InputHandler // Accommodating Tekkon 1.3.1 update.
- Also add Shift+Ctrl+Command+Option+Enter support for committing non-HTML textbook readings only.
This commit is contained in:
parent
d9e7033f90
commit
c13d223bb2
|
@ -181,25 +181,27 @@ extension IMEStateData {
|
|||
public var readingThreadForDisplay: String {
|
||||
var arrOutput = [String]()
|
||||
for neta in markedReadings {
|
||||
var neta = neta
|
||||
if neta.isEmpty { continue }
|
||||
if neta.contains("_") {
|
||||
arrOutput.append("??")
|
||||
continue
|
||||
}
|
||||
if !PrefMgr.shared.cassetteEnabled {
|
||||
if PrefMgr.shared.showHanyuPinyinInCompositionBuffer,
|
||||
PrefMgr.shared.alwaysShowTooltipTextsHorizontally || !isVerticalTyping
|
||||
{
|
||||
// 恢復陰平標記->注音轉拼音->轉教科書式標調
|
||||
neta = Tekkon.restoreToneOneInZhuyinKey(targetJoined: neta)
|
||||
neta = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: neta)
|
||||
neta = Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: neta)
|
||||
} else {
|
||||
neta = Tekkon.cnvZhuyinChainToTextbookReading(targetJoined: neta)
|
||||
neta.components(separatedBy: "-").forEach { subNeta in
|
||||
var subNeta = subNeta
|
||||
if !PrefMgr.shared.cassetteEnabled {
|
||||
if PrefMgr.shared.showHanyuPinyinInCompositionBuffer,
|
||||
PrefMgr.shared.alwaysShowTooltipTextsHorizontally || !isVerticalTyping
|
||||
{
|
||||
// 恢復陰平標記->注音轉拼音->轉教科書式標調
|
||||
subNeta = Tekkon.restoreToneOneInPhona(target: subNeta)
|
||||
subNeta = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: subNeta)
|
||||
subNeta = Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: subNeta)
|
||||
} else {
|
||||
subNeta = Tekkon.cnvPhonaToTextbookReading(target: subNeta)
|
||||
}
|
||||
}
|
||||
arrOutput.append(subNeta)
|
||||
}
|
||||
arrOutput.append(neta)
|
||||
}
|
||||
return arrOutput.joined(separator: "\u{A0}")
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ extension InputHandler {
|
|||
case .kCarriageReturn, .kLineFeed: // Enter
|
||||
return (input.isCommandHold && input.isControlHold)
|
||||
? (input.isOptionHold
|
||||
? handleCtrlOptionCommandEnter()
|
||||
? handleCtrlOptionCommandEnter(isShiftPressed: input.isShiftHold)
|
||||
: handleCtrlCommandEnter(isShiftPressed: input.isShiftHold))
|
||||
: handleEnter()
|
||||
case .kSpace: // 倘若沒有在偏好設定內將 Space 空格鍵設為選字窗呼叫用鍵的話………
|
||||
|
|
|
@ -295,6 +295,7 @@ extension InputHandler {
|
|||
// MARK: - Command+Enter 鍵的處理(注音文)
|
||||
|
||||
/// Command+Enter 鍵的處理(注音文)。
|
||||
/// - Parameter isShiftPressed: 有沒有同時摁著 Shift 鍵。
|
||||
/// - Returns: 將按鍵行為「是否有處理掉」藉由 SessionCtl 回報給 IMK。
|
||||
func handleCtrlCommandEnter(isShiftPressed: Bool = false) -> Bool {
|
||||
guard let delegate = delegate else { return false }
|
||||
|
@ -308,7 +309,11 @@ extension InputHandler {
|
|||
if !prefs.cassetteEnabled {
|
||||
if prefs.inlineDumpPinyinInLieuOfZhuyin {
|
||||
if !compositor.isEmpty {
|
||||
displayedText = Tekkon.restoreToneOneInZhuyinKey(targetJoined: displayedText) // 恢復陰平標記
|
||||
var arrDisplayedTextElements = [String]()
|
||||
compositor.keys.forEach { key in
|
||||
arrDisplayedTextElements.append(Tekkon.restoreToneOneInPhona(target: key)) // 恢復陰平標記
|
||||
}
|
||||
displayedText = arrDisplayedTextElements.joined(separator: "\t")
|
||||
}
|
||||
displayedText = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: displayedText) // 注音轉拼音
|
||||
}
|
||||
|
@ -328,8 +333,9 @@ extension InputHandler {
|
|||
// MARK: - Command+Option+Enter 鍵的處理(網頁 Ruby 注音文標記)
|
||||
|
||||
/// Command+Option+Enter 鍵的處理(網頁 Ruby 注音文標記)。
|
||||
/// - Parameter isShiftPressed: 有沒有同時摁著 Shift 鍵。摁了的話則只遞交讀音字串。
|
||||
/// - Returns: 將按鍵行為「是否有處理掉」藉由 SessionCtl 回報給 IMK。
|
||||
func handleCtrlOptionCommandEnter() -> Bool {
|
||||
func handleCtrlOptionCommandEnter(isShiftPressed: Bool = false) -> Bool {
|
||||
guard let delegate = delegate else { return false }
|
||||
let state = delegate.state
|
||||
guard state.type == .ofInputting else { return false }
|
||||
|
@ -337,19 +343,33 @@ extension InputHandler {
|
|||
var composed = ""
|
||||
|
||||
for node in compositor.walkedNodes {
|
||||
var key = node.keyArray.joined(separator: "\t")
|
||||
var key = node.keyArray.joined(separator: " ")
|
||||
if !prefs.cassetteEnabled {
|
||||
var keyArray = node.keyArray
|
||||
for (i, neta) in keyArray.enumerated() {
|
||||
keyArray[i] =
|
||||
prefs.inlineDumpPinyinInLieuOfZhuyin
|
||||
? Tekkon.restoreToneOneInPhona(target: neta) // 恢復陰平標記
|
||||
: Tekkon.cnvPhonaToTextbookReading(target: neta) // 恢復陰平標記
|
||||
}
|
||||
|
||||
key = keyArray.joined(separator: "\t")
|
||||
|
||||
if prefs.inlineDumpPinyinInLieuOfZhuyin {
|
||||
key = Tekkon.restoreToneOneInZhuyinKey(targetJoined: key) // 恢復陰平標記
|
||||
key = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: key) // 注音轉拼音
|
||||
key = Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: key) // 轉教科書式標調
|
||||
key = key.replacingOccurrences(of: "\t", with: " ")
|
||||
} else {
|
||||
key = Tekkon.cnvZhuyinChainToTextbookReading(targetJoined: key, newSeparator: " ")
|
||||
}
|
||||
key = key.replacingOccurrences(of: "\t", with: " ")
|
||||
}
|
||||
|
||||
let value = node.value
|
||||
|
||||
if isShiftPressed {
|
||||
if !composed.isEmpty { composed += " " }
|
||||
composed += key
|
||||
continue
|
||||
}
|
||||
|
||||
// 不要給標點符號等特殊元素加注音
|
||||
composed += key.contains("_") ? value : "<ruby>\(value)<rp>(</rp><rt>\(key)</rt><rp>)</rp></ruby>"
|
||||
}
|
||||
|
|
|
@ -32,8 +32,14 @@ extension SessionCtl {
|
|||
? theCandidate.0.joined(separator: separator)
|
||||
: (PrefMgr.shared.showHanyuPinyinInCompositionBuffer
|
||||
? Tekkon.cnvPhonaToHanyuPinyin(
|
||||
targetJoined: Tekkon.restoreToneOneInZhuyinKey(
|
||||
targetJoined: theCandidate.0.joined(separator: separator)))
|
||||
targetJoined: {
|
||||
var arr = [String]()
|
||||
theCandidate.0.forEach { key in
|
||||
arr.append(Tekkon.restoreToneOneInPhona(target: key))
|
||||
}
|
||||
return arr.joined(separator: "-")
|
||||
}()
|
||||
)
|
||||
: theCandidate.0.joined(separator: separator))
|
||||
result = "\(result)\u{17}(\(reading))"
|
||||
}
|
||||
|
@ -95,7 +101,14 @@ extension SessionCtl {
|
|||
? neta.0.joined(separator: separator)
|
||||
: (PrefMgr.shared.showHanyuPinyinInCompositionBuffer
|
||||
? Tekkon.cnvPhonaToHanyuPinyin(
|
||||
targetJoined: Tekkon.restoreToneOneInZhuyinKey(targetJoined: neta.0.joined(separator: separator)))
|
||||
targetJoined: {
|
||||
var arr = [String]()
|
||||
neta.0.forEach { key in
|
||||
arr.append(Tekkon.restoreToneOneInPhona(target: key))
|
||||
}
|
||||
return arr.joined(separator: "-")
|
||||
}()
|
||||
)
|
||||
: neta.0.joined(separator: separator))
|
||||
let netaShownWithPronunciation = "\(netaShown)\u{17}(\(reading))"
|
||||
if candidateString == prefix + netaShownWithPronunciation {
|
||||
|
|
Loading…
Reference in New Issue