From 56afe3fa6fb58a0d4685b7869d457d59085dd681 Mon Sep 17 00:00:00 2001 From: 1024jp <1024jp@wolfrosch.com> Date: Wed, 11 Oct 2017 10:02:02 +0900 Subject: [PATCH] Workaround the Touch Bar word suggestion issue --- CHANGELOG.md | 1 + CotEditor/Sources/EditorTextView+TouchBar.swift | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 264683d2a..4a41b6c8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/CotEditor/Sources/EditorTextView+TouchBar.swift b/CotEditor/Sources/EditorTextView+TouchBar.swift index e90dacc66..4da66ff47 100644 --- a/CotEditor/Sources/EditorTextView+TouchBar.swift +++ b/CotEditor/Sources/EditorTextView+TouchBar.swift @@ -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 }