Raise an alert by performing find with “in selection” but without selection

This commit is contained in:
1024jp 2019-11-01 11:27:00 +09:00
parent a3fc08731c
commit 07115627a6
9 changed files with 31 additions and 3 deletions

View File

@ -7,6 +7,7 @@ Change Log
### Improvements
- Raise an alert when performing find (or replacement) with “in selection” option while no text is selected.
- Accept importing custom syntax styles with “.yml” extension.
- Avoid re-parsing syntax highlight when the appearance is switched.
- Supprt Dark Mode in the help.

View File

@ -54,6 +54,7 @@ final class TextFind {
case regularExpression(reason: String)
case emptyFindString
case emptyInSelectionSearch
var errorDescription: String? {
@ -63,6 +64,8 @@ final class TextFind {
return "Invalid regular expression".localized
case .emptyFindString:
return "Empty find string".localized
case .emptyInSelectionSearch:
return "The option “in selection” is enabled, although nothing is selected.".localized
}
}
@ -74,6 +77,8 @@ final class TextFind {
return reason
case .emptyFindString:
return "Input text to find.".localized
case .emptyInSelectionSearch:
return "Select the search scope in document or disable “in selection” option.".localized
}
}
@ -119,6 +124,10 @@ final class TextFind {
throw TextFind.Error.emptyFindString
}
guard !inSelection || selectedRanges.contains(where: { !$0.isEmpty }) else {
throw TextFind.Error.emptyInSelectionSearch
}
switch mode {
case .textual(let options, _):
assert(!options.contains(.backwards))
@ -221,6 +230,8 @@ final class TextFind {
/// - wrapped: Whether the search was wrapped to find the result.
func findInSelection(forward: Bool) -> (range: NSRange?, count: Int, wrapped: Bool) {
assert(self.inSelection)
var matches = [NSRange]()
self.enumerateMatchs(in: self.selectedRanges, using: { (matchedRange, _, _) in
matches.append(matchedRange)

View File

@ -413,15 +413,19 @@ final class TextFinder: NSResponder, NSMenuItemValidation {
let textFind: TextFind
do {
textFind = try TextFind(for: string, findString: self.sanitizedFindString, mode: mode, inSelection: inSelection, selectedRanges: textView.selectedRanges as! [NSRange])
} catch {
} catch let error as TextFind.Error {
switch error {
case TextFind.Error.regularExpression:
case .regularExpression, .emptyInSelectionSearch:
self.findPanelController.showWindow(self)
self.presentError(error, modalFor: self.findPanelController.window!, delegate: nil, didPresent: nil, contextInfo: nil)
default: break
case .emptyFindString:
break
}
NSSound.beep()
return nil
} catch {
assertionFailure()
return nil
}
return (textView, textFind)

View File

@ -83,7 +83,9 @@
"%@ strings replaced." = "%@ Zeichenketten ersetzt.";
"Invalid regular expression" = "Ungültiger regulärer Ausdruck";
"Empty find string" = "Leerer Suchbegriff";
"The option “in selection” is enabled, although nothing is selected." = "Die Option „In Auswahl“ ist aktiviert, obwohl nichts ausgewählt ist.";
"Input text to find." = "Gib den zu findenden Text ein.";
"Select the search scope in document or disable “in selection” option." = "Wähle den Suchbereich im Dokument oder deaktiviere die Option „In Auswahl“.";
// accessibility announcement
"Search wrapped." = "Die Suche hat umgebrochen."; // announced when the search restarted from the beginning.

View File

@ -83,7 +83,9 @@
"%@ strings replaced." = "%@ éléments remplacés.";
"Invalid regular expression" = "Expression régulière invalide";
"Empty find string" = "Châine de recherche vide";
"The option “in selection” is enabled, although nothing is selected." = "The option “in selection” is enabled, although nothing is selected."; // FIXME: added
"Input text to find." = "Texte à rechercher";
"Select the search scope in document or disable “in selection” option." = "Select the search scope in document or disable “in selection” option."; // FIXME: added
// accessibility announcement
"Search wrapped." = "Retour au début."; // announced when the search restarted from the beginning.

View File

@ -84,7 +84,9 @@
"%@ strings replaced." = "%@ stringhe sostituite.";
"Invalid regular expression" = "Espressione regolare non valida";
"Empty find string" = "Stringa di ricerca vuota";
"The option “in selection” is enabled, although nothing is selected." = "The option “in selection” is enabled, although nothing is selected."; // FIXME: added
"Input text to find." = "Inserire il testo da cercare.";
"Select the search scope in document or disable “in selection” option." = "Select the search scope in document or disable “in selection” option."; // FIXME: added
// accessibility announcement
"Search wrapped." = "Ricerca dall'inizio"; // announced when the search restarted from the beginning.

View File

@ -84,7 +84,9 @@
"%@ strings replaced." = "%@件置換しました。";
"Invalid regular expression" = "無効な正規表現です。";
"Empty find string" = "検索文字列が空です。";
"The option “in selection” is enabled, although nothing is selected." = "「選択範囲のみ」オプションが有効になっていますが、何も選択されていません。";
"Input text to find." = "検索するテキストを入力してください。";
"Select the search scope in document or disable “in selection” option." = "検索範囲を選択するか「選択範囲のみ」オプションを無効にしてください。";
// accessibility announcement
"Search wrapped." = "検索が折り返されました。"; // announced when the search restarted from the beginning.

View File

@ -84,7 +84,9 @@
"%@ strings replaced." = "%@ strings substituídas.";
"Invalid regular expression" = "Expressão regular inválida";
"Empty find string" = "String de busca vazia";
"The option “in selection” is enabled, although nothing is selected." = "The option “in selection” is enabled, although nothing is selected."; // FIXME: added
"Input text to find." = "Digite o texto a buscar.";
"Select the search scope in document or disable “in selection” option." = "Select the search scope in document or disable “in selection” option."; // FIXME: added
// accessibility announcement
"Search wrapped." = "A busca voltou ao início."; // announced when the search restarted from the beginning.

View File

@ -84,7 +84,9 @@
"%@ strings replaced." = "已替换 %@ 个匹配";
"Invalid regular expression" = "无效的正则表达式";
"Empty find string" = "空的搜索字符串";
"The option “in selection” is enabled, although nothing is selected." = "The option “in selection” is enabled, although nothing is selected."; // FIXME: added
"Input text to find." = "输入文本以查找。";
"Select the search scope in document or disable “in selection” option." = "Select the search scope in document or disable “in selection” option."; // FIXME: added
// accessibility announcement
"Search wrapped." = "已从头搜索"; // announced when the search restarted from the beginning.