ctlIME & InputState // Fix an issue of not committing converted buffer.

This commit is contained in:
ShikiSuen 2022-06-22 13:16:35 +08:00
parent f4e685ad15
commit 2f68cf373c
2 changed files with 12 additions and 11 deletions

View File

@ -137,7 +137,7 @@ class InputState {
class NotEmpty: InputState { class NotEmpty: InputState {
private(set) var composingBuffer: String private(set) var composingBuffer: String
private(set) var cursorIndex: Int = 0 { didSet { cursorIndex = max(cursorIndex, 0) } } private(set) var cursorIndex: Int = 0 { didSet { cursorIndex = max(cursorIndex, 0) } }
var composingBufferConverted: String { public var composingBufferConverted: String {
let converted = IME.kanjiConversionIfRequired(composingBuffer) let converted = IME.kanjiConversionIfRequired(composingBuffer)
if converted.utf16.count != composingBuffer.utf16.count if converted.utf16.count != composingBuffer.utf16.count
|| converted.count != composingBuffer.count || converted.count != composingBuffer.count
@ -153,10 +153,10 @@ class InputState {
defer { self.cursorIndex = cursorIndex } defer { self.cursorIndex = cursorIndex }
} }
var attributedString: NSAttributedString { var attributedString: NSMutableAttributedString {
/// ///
/// JIS /// JIS
let attributedString = NSAttributedString( let attributedString = NSMutableAttributedString(
string: composingBufferConverted, string: composingBufferConverted,
attributes: [ attributes: [
.underlineStyle: NSUnderlineStyle.single.rawValue, .underlineStyle: NSUnderlineStyle.single.rawValue,
@ -270,7 +270,7 @@ class InputState {
defer { self.markerIndex = markerIndex } defer { self.markerIndex = markerIndex }
} }
override var attributedString: NSAttributedString { override var attributedString: NSMutableAttributedString {
/// ///
/// JIS /// JIS
let attributedString = NSMutableAttributedString(string: composingBufferConverted) let attributedString = NSMutableAttributedString(string: composingBufferConverted)
@ -392,8 +392,8 @@ class InputState {
// //
// //
// Crediting Qwertyyb: https://github.com/qwertyyb/Fire/issues/55#issuecomment-1133497700 // Crediting Qwertyyb: https://github.com/qwertyyb/Fire/issues/55#issuecomment-1133497700
override var attributedString: NSAttributedString { override var attributedString: NSMutableAttributedString {
let attributedString = NSAttributedString( let attributedString = NSMutableAttributedString(
string: " ", string: " ",
attributes: [ attributes: [
.underlineStyle: NSUnderlineStyle.single.rawValue, .underlineStyle: NSUnderlineStyle.single.rawValue,

View File

@ -63,8 +63,12 @@ class ctlInputMethod: IMKInputController {
client().overrideKeyboard(withKeyboardNamed: mgrPrefs.basicKeyboardLayout) client().overrideKeyboard(withKeyboardNamed: mgrPrefs.basicKeyboardLayout)
} }
/// 調 /// 調
func resetKeyHandler() { func resetKeyHandler() {
if let state = state as? InputState.NotEmpty {
/// 調
handle(state: InputState.Committing(textToCommit: state.composingBufferConverted))
}
keyHandler.clear() keyHandler.clear()
handle(state: InputState.Empty()) handle(state: InputState.Empty())
} }
@ -229,10 +233,6 @@ class ctlInputMethod: IMKInputController {
/// - Parameter sender: 使 /// - Parameter sender: 使
override func commitComposition(_ sender: Any!) { override func commitComposition(_ sender: Any!) {
_ = sender // _ = sender //
if let state = state as? InputState.NotEmpty {
/// 調
handle(state: InputState.Committing(textToCommit: state.composingBuffer))
}
resetKeyHandler() resetKeyHandler()
} }
} }
@ -297,6 +297,7 @@ extension ctlInputMethod {
} }
/// ///
/// IMK commitComposition
private func commit(text: String) { private func commit(text: String) {
let buffer = IME.kanjiConversionIfRequired(text) let buffer = IME.kanjiConversionIfRequired(text)
if buffer.isEmpty { if buffer.isEmpty {