Skip to content

Commit

Permalink
Working IME
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 27, 2019
1 parent 2e628b8 commit a507592
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
34 changes: 34 additions & 0 deletions Blink/SmarterKeys/SmarterTermInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,40 @@ class SmarterTermInput: KBWebView {
// }
}

override func onIME(_ event: String, data: String) {
if event == "compositionstart" && data.isEmpty {
} else if event == "compositionend" {
device?.view?.setIme("", completionHandler: nil)
} else {
device?.view?.setIme(data) { (data, error) in
guard
error == nil,
let resp = data as? [String: Any],
let markedRect = resp["markedRect"] as? String
else {
return
}
var rect = NSCoder.cgRect(for: markedRect)
let suggestionsHeight: CGFloat = 44
let maxY = rect.maxY
let minY = rect.minY
if maxY - suggestionsHeight < 0 {
rect.origin.y = maxY
} else {
rect.origin.y = minY
}

debugPrint(rect)
rect.size.height = 0
rect.size.width = 0

if let r = self.device?.view?.convert(rect, to: self.superview) {
self.frame = r
}
}
}
}

override func resignFirstResponder() -> Bool {
let res = super.resignFirstResponder()
if res {
Expand Down
3 changes: 2 additions & 1 deletion Blink/TermJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ NSString *term_modifySelection(NSString *direction, NSString *granularity)

NSString *term_setIme(NSString *imeText)
{
return [NSString stringWithFormat:@"term_setIme(%@[0]);", _encodeString(imeText)];
NSString *str = _encodeString(imeText);
return [NSString stringWithFormat:@"term_setIme(%@[0]);", str];
}

NSString *term_modifySideSelection()
Expand Down
2 changes: 1 addition & 1 deletion KB/Native/Model/KeyConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class KeyConfig: ObservableObject, Codable {
}

static var capsLock: KeyConfig {
KeyConfig(code: .capsLock, up: .none, down: .escape, mod: .none)
KeyConfig(code: .capsLock, up: .none, down: .none, mod: .none)
}

// - MARK: Codable
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 @@ -39,6 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)report:(NSString *)cmd arg:(NSObject *)arg;
- (void)ready;
- (void)onOut:(NSString *)data;
- (void)onIME:(NSString *)event data:(NSString *)data;

@end

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 @@ -168,7 +168,7 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
return _keyCommands;
}

- (void)_onIME:(NSString *)event data:(NSString *)data {
- (void)onIME:(NSString *)event data:(NSString *)data {

}

Expand Down Expand Up @@ -226,9 +226,9 @@ - (void)userContentController:(WKUserContentController *)userContentController
}
[self _rebuildKeyCommands];
} else if ([@"ime" isEqual:op]) {
NSString *event = body[@"event"];
NSString *event = body[@"type"];
NSString *data = body[@"data"];
[self _onIME:event data: data];
[self onIME:event data: data];
} else if ([@"guard-ime-on" isEqual:op]) {
if (_activeIMEGuardCommands == nil) {
_activeIMEGuardCommands = _imeGuardCommands;
Expand Down

0 comments on commit a507592

Please sign in to comment.