InputHandler // Use applyingTransformFW2HW().
This commit is contained in:
parent
f103335d5c
commit
2cdc64b1ff
|
@ -134,6 +134,19 @@ public extension NSApplication {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - String.applyingTransform
|
||||||
|
|
||||||
|
public extension String {
|
||||||
|
func applyingTransformFW2HW(reverse: Bool) -> String {
|
||||||
|
if #available(macOS 10.11, *) {
|
||||||
|
return applyingTransform(.fullwidthToHalfwidth, reverse: reverse) ?? self
|
||||||
|
}
|
||||||
|
let theString = NSMutableString(string: self)
|
||||||
|
CFStringTransform(theString, nil, kCFStringTransformFullwidthHalfwidth, reverse)
|
||||||
|
return theString as String
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Check whether current date is the given date.
|
// MARK: - Check whether current date is the given date.
|
||||||
|
|
||||||
public extension Date {
|
public extension Date {
|
||||||
|
|
|
@ -235,8 +235,7 @@ extension InputHandler {
|
||||||
if state.type == .ofEmpty {
|
if state.type == .ofEmpty {
|
||||||
if input.isMainAreaNumKey, input.modifierFlags == [.shift, .option] {
|
if input.isMainAreaNumKey, input.modifierFlags == [.shift, .option] {
|
||||||
guard let strRAW = input.mainAreaNumKeyChar else { return false }
|
guard let strRAW = input.mainAreaNumKeyChar else { return false }
|
||||||
let newString =
|
let newString = strRAW.applyingTransformFW2HW(reverse: !prefs.halfWidthPunctuationEnabled)
|
||||||
strRAW.applyingTransform(.fullwidthToHalfwidth, reverse: !prefs.halfWidthPunctuationEnabled) ?? strRAW
|
|
||||||
delegate.switchState(IMEState.ofCommitting(textToCommit: newString))
|
delegate.switchState(IMEState.ofCommitting(textToCommit: newString))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ public extension SessionCtl {
|
||||||
|
|
||||||
// Apple 數字小鍵盤處理
|
// Apple 數字小鍵盤處理
|
||||||
if eventToDeal.isNumericPadKey,
|
if eventToDeal.isNumericPadKey,
|
||||||
let eventCharConverted = eventToDeal.characters?.applyingTransform(.fullwidthToHalfwidth, reverse: false)
|
let eventCharConverted = eventToDeal.characters?.applyingTransformFW2HW(reverse: false)
|
||||||
{
|
{
|
||||||
eventToDeal = eventToDeal.reinitiate(characters: eventCharConverted) ?? eventToDeal
|
eventToDeal = eventToDeal.reinitiate(characters: eventCharConverted) ?? eventToDeal
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue