Skip to content

Commit

Permalink
Bring back ctrl-space mapping. Refs blinksh#782, blinksh#942, blinksh…
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jun 2, 2020
1 parent a36d946 commit cb8524a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions KB/Native/Views/KBWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class KBWebView: KBWebViewBase {
private var _loaded = false
private(set) var webViewReady = false
private(set) var blinkKeyCommands: [BlinkCommand] = []
private var _grabsCtrlSpace = false

func configure(_ cfg: KBConfig) {
_buildCommands(cfg)
Expand All @@ -66,6 +67,8 @@ class KBWebView: KBWebViewBase {
cmd.bindingAction = shortcut.action
return cmd
}

_grabsCtrlSpace = matchCommand(input: " ", flags: [UIKeyModifierFlags.control]) != nil
}

func matchCommand(input: String, flags: UIKeyModifierFlags) -> (UIKeyCommand, UIResponder)? {
Expand All @@ -87,6 +90,22 @@ class KBWebView: KBWebViewBase {
return result
}

override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
guard
_grabsCtrlSpace,
let key = presses.first?.key,
key.keyCode == .keyboardSpacebar,
key.modifierFlags.contains(.control),
let (cmd, responder) = matchCommand(input: " ", flags: key.modifierFlags),
let action = cmd.action
else {
super.pressesBegan(presses, with: event)
return
}

responder.perform(action, with: cmd)
}

func contentView() -> UIView? {
scrollView.subviews.first
}
Expand All @@ -102,11 +121,6 @@ class KBWebView: KBWebViewBase {
NotificationCenter.default.removeObserver(v)
}






override func ready() {
webViewReady = true
super.ready()
Expand Down

0 comments on commit cb8524a

Please sign in to comment.