SessionCtl // Improve the handling of isVerticalTyping().

This commit is contained in:
ShikiSuen 2022-11-29 10:06:04 +08:00
parent 0e98eb0d2c
commit 326b22b35a
1 changed files with 20 additions and 10 deletions

View File

@ -95,15 +95,25 @@ public class SessionCtl: IMKInputController {
///
public static var isVerticalTyping: Bool = false
public var isVerticalTyping: Bool {
guard let client = client() else { return false }
public var isVerticalTyping: Bool = false {
didSet {
Self.isVerticalTyping = isVerticalTyping
}
}
public func updateVerticalTypingStatus() {
guard let client = client() else {
isVerticalTyping = false
return
}
DispatchQueue.main.async {
var textFrame = NSRect.seniorTheBeast
let attributes: [AnyHashable: Any]? = client.attributes(
forCharacterIndex: 0, lineHeightRectangle: &textFrame
)
let result = (attributes?["IMKTextOrientation"] as? NSNumber)?.intValue == 0 || false
Self.isVerticalTyping = result
return result
self.isVerticalTyping = result
}
}
/// InputMode
@ -203,6 +213,7 @@ extension SessionCtl {
public override func activateServer(_ sender: Any!) {
_ = sender //
DispatchQueue.main.async { [self] in
defer { updateVerticalTypingStatus() }
if let senderBundleID: String = (sender as? IMKTextInput)?.bundleIdentifier() {
vCLog("activateServer(\(senderBundleID))")
isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID
@ -219,7 +230,6 @@ extension SessionCtl {
syncBaseLMPrefs()
Self.theShiftKeyDetector.alsoToggleWithLShift = PrefMgr.shared.togglingAlphanumericalModeWithLShift
Self.isVerticalTyping = isVerticalTyping
if #available(macOS 10.15, *) {
if isASCIIMode, PrefMgr.shared.disableShiftTogglingAlphanumericalMode { isASCIIMode = false }