Skip to content

Commit

Permalink
Add <> custom presses. Refs blinksh#903
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jan 6, 2020
1 parent ff6c8ca commit 36e62a9
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Blink/SpaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ extension SpaceController {

SmarterTermInput.shared.reportStateReset()
switch cmd.bindingAction {
case .hex(let hex, comment: _):
SmarterTermInput.shared.reportHex(hex)
break;
case .press(let keyCode, mods: let mods):
SmarterTermInput.shared.reportPress(UIKeyModifierFlags(rawValue: mods), keyId: keyCode.id)
break;
Expand Down
2 changes: 1 addition & 1 deletion KB/JS/dist/kb.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions KB/JS/src/Keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ export default class Keyboard implements IKeyboard {
case 'capture':
this._toggleCaptureMode(arg);
break;
case 'hex':
this._output(hex_to_ascii(arg));
break;
case 'config':
this._config(arg);
break;
Expand Down
14 changes: 10 additions & 4 deletions KB/Native/Model/KeyBindingAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ enum Command: String, Codable, CaseIterable {
}

enum KeyBindingAction: Codable, Identifiable {
case hex(String)
case hex(String, comment: String?)
case press(KeyCode, mods: Int)
case command(Command)
case none
Expand Down Expand Up @@ -148,6 +148,8 @@ enum KeyBindingAction: Codable, Identifiable {
.press(.f10, []),
.press(.f11, []),
.press(.f12, []),
.hex("3C", comment: "Press <"),
.hex("3E", comment: "Press >")
]
}

Expand All @@ -157,7 +159,8 @@ enum KeyBindingAction: Codable, Identifiable {

var title: String {
switch self {
case .hex(let str): return "Hex: (\(str))"
case .hex(let str, comment: let comment):
return comment ?? "Hex: (\(str))"
case .press(let keyCode, let mods):
var sym = UIKeyModifierFlags(rawValue: mods).toSymbols()
sym += keyCode.symbol
Expand All @@ -177,15 +180,17 @@ enum KeyBindingAction: Codable, Identifiable {
case press
case mods
case command
case comment
case none
}

func encode(to encoder: Encoder) throws {
var c = encoder.container(keyedBy: Keys.self)
switch self {
case .hex(let str):
case .hex(let str, comment: let comment):
try c.encode(Keys.hex.stringValue, forKey: .type)
try c.encode(str, forKey: .value)
try c.encodeIfPresent(comment, forKey: .comment)
case .press(let keyCode, let mods):
try c.encode(Keys.press.stringValue, forKey: .type)
try c.encode(keyCode, forKey: .key)
Expand All @@ -206,7 +211,8 @@ enum KeyBindingAction: Codable, Identifiable {
switch k {
case .hex:
let hex = try c.decode(String.self, forKey: .value)
self = .hex(hex)
let comment = try c.decodeIfPresent(String.self, forKey: .comment)
self = .hex(hex, comment: comment)
case .press:
let keyCode = try c.decode(KeyCode.self, forKey: .key)
let mods = try c.decode(Int.self, forKey: .mods)
Expand Down
1 change: 1 addition & 0 deletions KB/Native/Views/KBWebViewBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ NS_ASSUME_NONNULL_BEGIN

- (void)reportStateReset:(BOOL)hasSelection;
- (void)reportLang:(NSString *) lang;
- (void)reportHex:(NSString *) hex;
- (void)reportPress:(UIKeyModifierFlags)mods keyId:(NSString *)keyId;
- (void)reportToolbarPress:(UIKeyModifierFlags)mods keyId:(NSString *)keyId;
- (void)reportToolbarModifierFlags:(UIKeyModifierFlags)flags;
Expand Down
8 changes: 3 additions & 5 deletions KB/Native/Views/KBWebViewBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
#import "KBWebViewBase.h"

NSString *_encodeString(NSString *str);
//{
// NSData *jsonData = [NSJSONSerialization dataWithJSONObject:str options:NSJSONWritingFragmentsAllowed error:nil];
// return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
//}


@interface KeyCommand: UIKeyCommand
@end
Expand Down Expand Up @@ -179,6 +174,9 @@ - (void)reportPress:(UIKeyModifierFlags)mods keyId:(NSString *)keyId {
[self report:@"press" arg:_encodeString(kid)];
}

- (void)reportHex:(NSString *)hex {
[self report:@"hex" arg:_encodeString(hex)];
}

// Not sure we need up
- (void)_imeGuardUp:(KeyCommand *)cmd {
Expand Down
2 changes: 1 addition & 1 deletion KB/Native/Views/KeyCaptureView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CaptureController: UIViewController {
private func _generateCommands() -> Array<UIKeyCommand> {
var result:Array<UIKeyCommand> = []
let chars = "`1234567890-=\u{8}\tqwertyuiop[]\\asdfghjkl;'\rzxcvbnm,./ "
+ "§±^°"
+ "§±^°‹›"
let inputs = chars.map({String($0)}) + [
UIKeyCommand.inputUpArrow,
UIKeyCommand.inputDownArrow,
Expand Down

0 comments on commit 36e62a9

Please sign in to comment.