ctlIME // Move kanji conversion to IME module.
This commit is contained in:
parent
ad1141a7fd
commit
8076b083fe
|
@ -146,7 +146,7 @@ class InputState {
|
||||||
|
|
||||||
var attributedString: NSAttributedString {
|
var attributedString: NSAttributedString {
|
||||||
let attributedString = NSAttributedString(
|
let attributedString = NSAttributedString(
|
||||||
string: composingBuffer,
|
string: IME.kanjiConversionIfRequired(composingBuffer),
|
||||||
attributes: [
|
attributes: [
|
||||||
.underlineStyle: NSUnderlineStyle.single.rawValue,
|
.underlineStyle: NSUnderlineStyle.single.rawValue,
|
||||||
.markedClauseSegment: 0,
|
.markedClauseSegment: 0,
|
||||||
|
@ -260,7 +260,7 @@ class InputState {
|
||||||
}
|
}
|
||||||
|
|
||||||
override var attributedString: NSAttributedString {
|
override var attributedString: NSAttributedString {
|
||||||
let attributedString = NSMutableAttributedString(string: composingBuffer)
|
let attributedString = NSMutableAttributedString(string: IME.kanjiConversionIfRequired(composingBuffer))
|
||||||
let end = markedRange.upperBound
|
let end = markedRange.upperBound
|
||||||
|
|
||||||
attributedString.setAttributes(
|
attributedString.setAttributes(
|
||||||
|
|
|
@ -446,4 +446,19 @@ class KeyHandler {
|
||||||
func deleteCompositorReadingToTheFrontOfCursor() {
|
func deleteCompositorReadingToTheFrontOfCursor() {
|
||||||
compositor.deleteReadingToTheFrontOfCursor()
|
compositor.deleteReadingToTheFrontOfCursor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - 其他工具函式
|
||||||
|
|
||||||
|
func kanjiConversionIfRequired(_ text: String) -> String {
|
||||||
|
if inputMode == InputMode.imeModeCHT {
|
||||||
|
switch (mgrPrefs.chineseConversionEnabled, mgrPrefs.shiftJISShinjitaiOutputEnabled) {
|
||||||
|
case (false, true): return vChewingKanjiConverter.cnvTradToJIS(text)
|
||||||
|
case (true, false): return vChewingKanjiConverter.cnvTradToKangXi(text)
|
||||||
|
// 本來這兩個開關不該同時開啟的,但萬一被開啟了的話就這樣處理:
|
||||||
|
case (true, true): return vChewingKanjiConverter.cnvTradToJIS(text)
|
||||||
|
case (false, false): return text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return text
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,20 +298,7 @@ extension ctlInputMethod {
|
||||||
|
|
||||||
/// 遞交組字區內容。
|
/// 遞交組字區內容。
|
||||||
private func commit(text: String) {
|
private func commit(text: String) {
|
||||||
func kanjiConversionIfRequired(_ text: String) -> String {
|
let buffer = keyHandler.kanjiConversionIfRequired(text)
|
||||||
if keyHandler.inputMode == InputMode.imeModeCHT {
|
|
||||||
switch (mgrPrefs.chineseConversionEnabled, mgrPrefs.shiftJISShinjitaiOutputEnabled) {
|
|
||||||
case (false, true): return vChewingKanjiConverter.cnvTradToJIS(text)
|
|
||||||
case (true, false): return vChewingKanjiConverter.cnvTradToKangXi(text)
|
|
||||||
// 本來這兩個開關不該同時開啟的,但萬一被開啟了的話就這樣處理:
|
|
||||||
case (true, true): return vChewingKanjiConverter.cnvTradToJIS(text)
|
|
||||||
case (false, false): return text
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return text
|
|
||||||
}
|
|
||||||
|
|
||||||
let buffer = kanjiConversionIfRequired(text)
|
|
||||||
if buffer.isEmpty {
|
if buffer.isEmpty {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue