Skip to content

Commit

Permalink
Respect shift on software arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Dec 13, 2019
1 parent 25cd367 commit 796fd36
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
12 changes: 10 additions & 2 deletions Blink/SmarterKeys/KBView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,23 @@ extension KBView: KBKeyViewDelegate {

defer { turnOffUntracked() }

guard let keyInput = keyInput
else {
return
}

let keyCode = value.keyCode
var keyId = keyCode.id
keyId += ":\(value.text)"

var flags = traits.modifierFlags
if keyInput.trackingModifierFlags.contains(.shift) {
flags.insert(.shift)
}

if let input = value.input,
flags.rawValue > 0,
let (cmd, responder) = keyInput?.matchCommand(input: input, flags: flags),
let (cmd, responder) = keyInput.matchCommand(input: input, flags: flags),
let action = cmd.action {
responder.perform(action, with: cmd)
return
Expand All @@ -390,7 +398,7 @@ extension KBView: KBKeyViewDelegate {
flags.remove(.command)
}

keyInput?.reportToolbarPress(flags, keyId: keyId)
keyInput.reportToolbarPress(flags, keyId: keyId)
}

func keyViewCancelled(keyView: KBKeyView) {
Expand Down
2 changes: 2 additions & 0 deletions KB/Native/Views/KBWebViewBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN

@interface KBWebViewBase : WKWebView

@property (readonly) UIKeyModifierFlags trackingModifierFlags;

- (void)reportStateReset;
- (void)reportLang:(NSString *) lang;
- (void)reportPress:(UIKeyModifierFlags)mods keyId:(NSString *)keyId;
Expand Down
6 changes: 3 additions & 3 deletions KB/Native/Views/KBWebViewBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ - (void)userContentController:(WKUserContentController *)userContentController
});
} else if ([@"mods" isEqual:op]) {
NSNumber *mods = body[@"mods"];
UIKeyModifierFlags flags = (UIKeyModifierFlags)mods.integerValue;
if (flags == 0) {
_trackingModifierFlags = (UIKeyModifierFlags)mods.integerValue;
if (_trackingModifierFlags == 0) {
_activeModsCommand = nil;
} else {
_activeModsCommand = [self _modifiersCommand:flags];
_activeModsCommand = [self _modifiersCommand:_trackingModifierFlags];
}
[self _rebuildKeyCommands];
[self onMods];
Expand Down

0 comments on commit 796fd36

Please sign in to comment.