ctlIME & InputState // Fix an issue of not committing converted buffer.
This commit is contained in:
parent
f4e685ad15
commit
2f68cf373c
|
@ -137,7 +137,7 @@ class InputState {
|
|||
class NotEmpty: InputState {
|
||||
private(set) var composingBuffer: String
|
||||
private(set) var cursorIndex: Int = 0 { didSet { cursorIndex = max(cursorIndex, 0) } }
|
||||
var composingBufferConverted: String {
|
||||
public var composingBufferConverted: String {
|
||||
let converted = IME.kanjiConversionIfRequired(composingBuffer)
|
||||
if converted.utf16.count != composingBuffer.utf16.count
|
||||
|| converted.count != composingBuffer.count
|
||||
|
@ -153,10 +153,10 @@ class InputState {
|
|||
defer { self.cursorIndex = cursorIndex }
|
||||
}
|
||||
|
||||
var attributedString: NSAttributedString {
|
||||
var attributedString: NSMutableAttributedString {
|
||||
/// 考慮到因為滑鼠點擊等其它行為導致的組字區內容遞交情況,
|
||||
/// 這裡對組字區內容也加上康熙字轉換或者 JIS 漢字轉換處理。
|
||||
let attributedString = NSAttributedString(
|
||||
let attributedString = NSMutableAttributedString(
|
||||
string: composingBufferConverted,
|
||||
attributes: [
|
||||
.underlineStyle: NSUnderlineStyle.single.rawValue,
|
||||
|
@ -270,7 +270,7 @@ class InputState {
|
|||
defer { self.markerIndex = markerIndex }
|
||||
}
|
||||
|
||||
override var attributedString: NSAttributedString {
|
||||
override var attributedString: NSMutableAttributedString {
|
||||
/// 考慮到因為滑鼠點擊等其它行為導致的組字區內容遞交情況,
|
||||
/// 這裡對組字區內容也加上康熙字轉換或者 JIS 漢字轉換處理。
|
||||
let attributedString = NSMutableAttributedString(string: composingBufferConverted)
|
||||
|
@ -392,8 +392,8 @@ class InputState {
|
|||
// 會出現符號選字窗無法響應方向鍵的問題。
|
||||
// 如有誰要修奇摩注音的一點通選單的話,修復原理也是一樣的。
|
||||
// Crediting Qwertyyb: https://github.com/qwertyyb/Fire/issues/55#issuecomment-1133497700
|
||||
override var attributedString: NSAttributedString {
|
||||
let attributedString = NSAttributedString(
|
||||
override var attributedString: NSMutableAttributedString {
|
||||
let attributedString = NSMutableAttributedString(
|
||||
string: " ",
|
||||
attributes: [
|
||||
.underlineStyle: NSUnderlineStyle.single.rawValue,
|
||||
|
|
|
@ -63,8 +63,12 @@ class ctlInputMethod: IMKInputController {
|
|||
client().overrideKeyboard(withKeyboardNamed: mgrPrefs.basicKeyboardLayout)
|
||||
}
|
||||
|
||||
/// 重設按鍵調度模組。
|
||||
/// 重設按鍵調度模組,會將當前尚未遞交的內容遞交出去。
|
||||
func resetKeyHandler() {
|
||||
if let state = state as? InputState.NotEmpty {
|
||||
/// 將傳回的新狀態交給調度函式。
|
||||
handle(state: InputState.Committing(textToCommit: state.composingBufferConverted))
|
||||
}
|
||||
keyHandler.clear()
|
||||
handle(state: InputState.Empty())
|
||||
}
|
||||
|
@ -229,10 +233,6 @@ class ctlInputMethod: IMKInputController {
|
|||
/// - Parameter sender: 呼叫了該函式的客體(無須使用)。
|
||||
override func commitComposition(_ sender: Any!) {
|
||||
_ = sender // 防止格式整理工具毀掉與此對應的參數。
|
||||
if let state = state as? InputState.NotEmpty {
|
||||
/// 將傳回的新狀態交給調度函式。
|
||||
handle(state: InputState.Committing(textToCommit: state.composingBuffer))
|
||||
}
|
||||
resetKeyHandler()
|
||||
}
|
||||
}
|
||||
|
@ -297,6 +297,7 @@ extension ctlInputMethod {
|
|||
}
|
||||
|
||||
/// 遞交組字區內容。
|
||||
/// 注意:必須在 IMK 的 commitComposition 函式當中也間接或者直接執行這個處理。
|
||||
private func commit(text: String) {
|
||||
let buffer = IME.kanjiConversionIfRequired(text)
|
||||
if buffer.isEmpty {
|
||||
|
|
Loading…
Reference in New Issue