InputHandler // Accommodating Megrez 2.5.1 update.
- Utilizing [Node].smashedPairs, etc. - Refactoring rotateCandidate().
This commit is contained in:
parent
b75ab569b7
commit
f9abcd4f09
|
@ -217,7 +217,7 @@ public class InputHandler: InputHandlerProtocol {
|
||||||
|
|
||||||
var position = rearBoundary // 臨時統計用
|
var position = rearBoundary // 臨時統計用
|
||||||
while position < frontBoundary {
|
while position < frontBoundary {
|
||||||
guard let regionIndex = compositor.cursorRegionMap[position] else {
|
guard let regionIndex = compositor.walkedNodes.cursorRegionMap[position] else {
|
||||||
position += 1
|
position += 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,32 +342,26 @@ extension InputHandler {
|
||||||
|
|
||||||
var composed = ""
|
var composed = ""
|
||||||
|
|
||||||
for node in compositor.walkedNodes {
|
compositor.walkedNodes.smashedPairs.forEach { key, value in
|
||||||
var key = node.keyArray.joined(separator: " ")
|
var key = key
|
||||||
if !prefs.cassetteEnabled {
|
if !prefs.cassetteEnabled {
|
||||||
var keyArray = node.keyArray
|
key =
|
||||||
for (i, neta) in keyArray.enumerated() {
|
|
||||||
keyArray[i] =
|
|
||||||
prefs.inlineDumpPinyinInLieuOfZhuyin
|
prefs.inlineDumpPinyinInLieuOfZhuyin
|
||||||
? Tekkon.restoreToneOneInPhona(target: neta) // 恢復陰平標記
|
? Tekkon.restoreToneOneInPhona(target: key) // 恢復陰平標記
|
||||||
: Tekkon.cnvPhonaToTextbookReading(target: neta) // 恢復陰平標記
|
: Tekkon.cnvPhonaToTextbookReading(target: key) // 恢復陰平標記
|
||||||
}
|
|
||||||
|
|
||||||
key = keyArray.joined(separator: "\t")
|
|
||||||
|
|
||||||
if prefs.inlineDumpPinyinInLieuOfZhuyin {
|
if prefs.inlineDumpPinyinInLieuOfZhuyin {
|
||||||
key = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: key) // 注音轉拼音
|
key = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: key) // 注音轉拼音
|
||||||
key = Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: key) // 轉教科書式標調
|
key = Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: key) // 轉教科書式標調
|
||||||
}
|
}
|
||||||
key = key.replacingOccurrences(of: "\t", with: " ")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = node.value
|
key = key.replacingOccurrences(of: "\t", with: " ")
|
||||||
|
|
||||||
if isShiftPressed {
|
if isShiftPressed {
|
||||||
if !composed.isEmpty { composed += " " }
|
if !composed.isEmpty { composed += " " }
|
||||||
composed += key
|
composed += key.contains("_") ? "??" : key
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 不要給標點符號等特殊元素加注音
|
// 不要給標點符號等特殊元素加注音
|
||||||
|
@ -710,50 +704,32 @@ extension InputHandler {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
var length = 0
|
guard let region = compositor.walkedNodes.cursorRegionMap[cursorForCandidate],
|
||||||
var currentNode: Megrez.Compositor.Node?
|
compositor.walkedNodes.count > region
|
||||||
let cursorIndex = cursorForCandidate
|
else {
|
||||||
for node in compositor.walkedNodes {
|
delegate.callError("1CE6FFBD")
|
||||||
length += node.spanLength
|
|
||||||
if length > cursorIndex {
|
|
||||||
currentNode = node
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let currentNode = currentNode else {
|
|
||||||
delegate.callError("F58DEA95")
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let currentNode = compositor.walkedNodes[region]
|
||||||
|
|
||||||
let currentPaired = (currentNode.keyArray, currentNode.value)
|
let currentPaired = (currentNode.keyArray, currentNode.value)
|
||||||
|
|
||||||
var currentIndex = 0
|
var currentIndex: Int {
|
||||||
if !currentNode.isOverridden {
|
var result = 0
|
||||||
/// 如果是沒有被使用者手動選字過的(節錨下的)節點,
|
|
||||||
/// 就從第一個候選字詞開始,這樣使用者在敲字時就會優先匹配
|
|
||||||
/// 那些字詞長度不小於 2 的單元圖。換言之,如果使用者敲了兩個
|
|
||||||
/// 注音讀音、卻發現這兩個注音讀音各自的單字權重遠高於由這兩個
|
|
||||||
/// 讀音組成的雙字詞的權重、導致這個雙字詞並未在爬軌時被自動
|
|
||||||
/// 選中的話,則使用者可以直接摁下本函式對應的按鍵來輪替候選字即可。
|
|
||||||
/// (預設情況下是 (Shift+)Tab 來做正 (反) 向切換,但也可以用
|
|
||||||
/// Shift(+Command)+Space 或 Alt+↑/↓ 來切換(縱排輸入時則是 Alt+←/→)、
|
|
||||||
/// 以應對臉書綁架 Tab 鍵的情況。
|
|
||||||
if candidates[0] == currentPaired {
|
|
||||||
/// 如果第一個候選字詞是當前節點的候選字詞的值的話,
|
|
||||||
/// 那就切到下一個(或上一個,也就是最後一個)候選字詞。
|
|
||||||
currentIndex = reverseOrder ? candidates.count - 1 : 1
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for candidate in candidates {
|
for candidate in candidates {
|
||||||
currentIndex =
|
if !currentNode.isOverridden {
|
||||||
|
if candidates[0] == currentPaired { result = reverseOrder ? candidates.count - 1 : 1 }
|
||||||
|
break
|
||||||
|
}
|
||||||
|
result =
|
||||||
(candidate == currentPaired && reverseOrder)
|
(candidate == currentPaired && reverseOrder)
|
||||||
? ((currentIndex == 0) ? candidates.count - 1 : currentIndex - 1) : currentIndex + 1
|
? ((result == 0) ? candidates.count - 1 : result - 1) : result + 1
|
||||||
if candidate == currentPaired { break }
|
if candidate == currentPaired { break }
|
||||||
}
|
}
|
||||||
|
return (0..<candidates.count).contains(result) ? result : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentIndex >= candidates.count { currentIndex = 0 }
|
|
||||||
consolidateNode(
|
consolidateNode(
|
||||||
candidate: candidates[currentIndex], respectCursorPushing: false,
|
candidate: candidates[currentIndex], respectCursorPushing: false,
|
||||||
preConsolidate: false, skipObservation: true
|
preConsolidate: false, skipObservation: true
|
||||||
|
|
Loading…
Reference in New Issue