Workaround the Touch Bar word suggestion issue

This commit is contained in:
1024jp 2017-10-11 10:02:02 +09:00
parent adb57c2331
commit 56afe3fa6f
2 changed files with 7 additions and 1 deletions

View File

@ -14,6 +14,7 @@ develop
### Fixes
- Fix an issue where UNIX scripts could fail getting the content of the document.
- Workaround an issue where word suggestion in the Touch Bar cannot insert a word starts with a symbol correctly.
- Address an issue where the application could crash on document saving or text replacement.

View File

@ -99,7 +99,12 @@ extension EditorTextViewController {
func textView(_ textView: NSTextView, candidatesForSelectedRange selectedRange: NSRange) -> [Any]? {
var index = 0
guard let candidates = textView.completions(forPartialWordRange: textView.rangeForUserCompletion, indexOfSelectedItem: &index), !candidates.isEmpty else { return nil }
guard
let candidates = textView.completions(forPartialWordRange: textView.rangeForUserCompletion, indexOfSelectedItem: &index)?
.filter({ $0.range(of: "^(\\W|_)", options: .regularExpression) == nil }),
!candidates.isEmpty
else { return nil }
// -> remove words start with non-alphabet to workaround a bug: e.g. "__init__" in Python (2017-10 macOS 10.13)
return candidates
}