diff --git a/NvimView/NvimServer/NvimServer.m b/NvimView/NvimServer/NvimServer.m index f2c3531e..bfa85ecc 100644 --- a/NvimView/NvimServer/NvimServer.m +++ b/NvimView/NvimServer/NvimServer.m @@ -63,9 +63,6 @@ static CFDataRef local_server_callback( case NvimBridgeMsgIdResize: return data_async(data, neovim_resize); - case NvimBridgeMsgIdInput: - return data_async(data, neovim_vim_input); - case NvimBridgeMsgIdDeleteInput: return data_async(data, neovim_delete_and_input); diff --git a/NvimView/NvimServer/SharedTypes.h b/NvimView/NvimServer/SharedTypes.h index 3beae944..effb56de 100644 --- a/NvimView/NvimServer/SharedTypes.h +++ b/NvimView/NvimServer/SharedTypes.h @@ -49,7 +49,6 @@ typedef NS_ENUM(NSInteger, NvimServerMsgId) { typedef NS_ENUM(NSInteger, NvimBridgeMsgId) { NvimBridgeMsgIdAgentReady = 0, NvimBridgeMsgIdReadyForRpcEvents, - NvimBridgeMsgIdInput, NvimBridgeMsgIdDeleteInput, NvimBridgeMsgIdResize, NvimBridgeMsgIdScroll, diff --git a/NvimView/NvimServer/server_ui.h b/NvimView/NvimServer/server_ui.h index fb3f7bcc..c4a2dc66 100644 --- a/NvimView/NvimServer/server_ui.h +++ b/NvimView/NvimServer/server_ui.h @@ -15,7 +15,6 @@ extern void start_neovim(NSInteger width, NSInteger height, NSArray extern void neovim_scroll(void **argv); extern void neovim_resize(void **argv); -extern void neovim_vim_input(void **argv); extern void neovim_delete_and_input(void **argv); extern void neovim_focus_gained(void **argv); diff --git a/NvimView/NvimServer/server_ui.m b/NvimView/NvimServer/server_ui.m index 04961fd7..f6795224 100644 --- a/NvimView/NvimServer/server_ui.m +++ b/NvimView/NvimServer/server_ui.m @@ -686,16 +686,6 @@ void neovim_resize(void **argv) { }); } -void neovim_vim_input(void **argv) { - work_async(argv, ^(NSData *data) { - NSString *input = [[NSString alloc] initWithData:data - encoding:NSUTF8StringEncoding]; - - nvim_input(vim_string_from(input)); - [input release]; - }); -} - void neovim_delete_and_input(void **argv) { work_async(argv, ^(NSData *data) { const NSInteger *const values = data.bytes; diff --git a/NvimView/NvimView/NvimView+Key.swift b/NvimView/NvimView/NvimView+Key.swift index 54683bb7..feae67d5 100644 --- a/NvimView/NvimView/NvimView+Key.swift +++ b/NvimView/NvimView/NvimView+Key.swift @@ -16,7 +16,7 @@ extension NvimView { let modifierFlags = event.modifierFlags let isMeta = (self.isLeftOptionMeta && modifierFlags.contains(.leftOption)) - || (self.isRightOptionMeta && modifierFlags.contains(.rightOption)) + || (self.isRightOptionMeta && modifierFlags.contains(.rightOption)) if !isMeta { let cocoaHandledEvent @@ -41,9 +41,7 @@ extension NvimView { let finalInput = isWrapNeeded ? self.wrapNamedKeys(flags + namedChars) : self.vimPlainString(chars) - try? self.bridge - .vimInput(finalInput) - .wait() + _ = self.api.input(keys: finalInput, checkBlocked: false).syncValue() self.keyDownDone = true } @@ -131,8 +129,8 @@ extension NvimView { // Control code \0 causes rpc parsing problems. // So we escape as early as possible if chars == "\0" { - self.bridge - .vimInput(self.wrapNamedKeys("Nul")) + self.api + .input(keys: self.wrapNamedKeys("Nul"), checkBlocked: false) .subscribe() .disposed(by: self.disposeBag) return true @@ -142,8 +140,8 @@ extension NvimView { // See special cases in vim/os_win32.c from vim sources // Also mentioned in MacVim's KeyBindings.plist if .control == flags && chars == "6" { - self.bridge - .vimInput("\u{1e}") // AKA ^^ + self.api + .input(keys: "\u{1e}", checkBlocked: false) // AKA ^^ .subscribe() .disposed(by: self.disposeBag) return true @@ -151,8 +149,8 @@ extension NvimView { if .control == flags && chars == "2" { // should generate \0, escaping as above - self.bridge - .vimInput(self.wrapNamedKeys("Nul")) + self.api + .input(keys: self.wrapNamedKeys("Nul"), checkBlocked: false) .subscribe() .disposed(by: self.disposeBag) return true @@ -300,7 +298,7 @@ extension NvimView { .map { row in row.filter { cell in return aRange.location <= cell.flatCharIndex - && cell.flatCharIndex <= aRange.inclusiveEndIndex + && cell.flatCharIndex <= aRange.inclusiveEndIndex } } .flatMap { $0 } diff --git a/NvimView/NvimView/NvimView+MenuItems.swift b/NvimView/NvimView/NvimView+MenuItems.swift index a4e26858..f1bb6f76 100644 --- a/NvimView/NvimView/NvimView+MenuItems.swift +++ b/NvimView/NvimView/NvimView+MenuItems.swift @@ -50,15 +50,15 @@ extension NvimView { @IBAction func undo(_ sender: AnyObject?) { switch self.mode { case .insert, .replace: - self.bridge - .vimInput("ui") + self.api + .input(keys: "ui", checkBlocked: false) .subscribe(onError: { error in self.eventsSubject.onNext(.apiError(msg: "Could not undo", cause: error)) }) .disposed(by: self.disposeBag) case .normal, .visual: - self.bridge - .vimInput("u") + self.api + .input(keys: "u", checkBlocked: false) .subscribe(onError: { error in self.eventsSubject.onNext(.apiError(msg: "Could not undo", cause: error)) }) @@ -71,15 +71,15 @@ extension NvimView { @IBAction func redo(_ sender: AnyObject?) { switch self.mode { case .insert, .replace: - self.bridge - .vimInput("i") + self.api + .input(keys: "i", checkBlocked: false) .subscribe(onError: { error in self.eventsSubject.onNext(.apiError(msg: "Could not redo", cause: error)) }) .disposed(by: self.disposeBag) case .normal, .visual: - self.bridge - .vimInput("") + self.api + .input(keys: "", checkBlocked: false) .subscribe(onError: { error in self.eventsSubject.onNext(.apiError(msg: "Could not redo", cause: error)) }) @@ -92,8 +92,8 @@ extension NvimView { @IBAction func cut(_ sender: AnyObject?) { switch self.mode { case .visual, .normal: - self.bridge - .vimInput("\"+d") + self.api + .input(keys: "\"+d", checkBlocked: false) .subscribe(onError: { error in self.eventsSubject.onNext(.apiError(msg: "Could not cut", cause: error)) }) @@ -106,8 +106,8 @@ extension NvimView { @IBAction func copy(_ sender: AnyObject?) { switch self.mode { case .visual, .normal: - self.bridge - .vimInput("\"+y") + self.api + .input(keys: "\"+y", checkBlocked: false) .subscribe(onError: { error in self.eventsSubject.onNext(.apiError(msg: "Could not copy", cause: error)) }) @@ -125,8 +125,8 @@ extension NvimView { if self.mode == .cmdline || self.mode == .cmdlineInsert || self.mode == .cmdlineReplace || self.mode == .replace || self.mode == .termFocus { - self.bridge - .vimInput(self.vimPlainString(content)) + self.api + .input(keys: self.vimPlainString(content), checkBlocked: false) .subscribe(onError: { error in self.eventsSubject.onNext(.apiError(msg: "Could not paste \(content)", cause: error)) }) @@ -156,13 +156,13 @@ extension NvimView { case .insert: let cmd = element.column == 0 ? "\"+Pa" : "\"+pa" - return self.bridge - .vimInput(cmd) + return self.api + .input(keys: cmd, checkBlocked: false).asCompletable() .andThen(Single.just(element.pasteModeSet)) case .normal, .visual: - return self.bridge - .vimInput("\"+p") + return self.api + .input(keys: "\"+p", checkBlocked: false).asCompletable() .andThen(Single.just(element.pasteModeSet)) default: @@ -186,8 +186,8 @@ extension NvimView { @IBAction func delete(_ sender: AnyObject?) { switch self.mode { case .normal, .visual: - self.bridge - .vimInput("x") + self.api + .input(keys: "x", checkBlocked: false) .subscribe(onError: { error in self.eventsSubject.onNext(.apiError(msg: "Could not delete", cause: error)) }) @@ -200,15 +200,15 @@ extension NvimView { @IBAction public override func selectAll(_ sender: Any?) { switch self.mode { case .insert, .visual: - self.bridge - .vimInput("ggVG") + self.api + .input(keys: "ggVG", checkBlocked: false) .subscribe(onError: { error in self.eventsSubject.onNext(.apiError(msg: "Could not select all", cause: error)) }) .disposed(by: self.disposeBag) default: - self.bridge - .vimInput("ggVG") + self.api + .input(keys: "ggVG", checkBlocked: false) .subscribe(onError: { error in self.eventsSubject.onNext(.apiError(msg: "Could not select all", cause: error)) }) diff --git a/NvimView/NvimView/NvimView+Mouse.swift b/NvimView/NvimView/NvimView+Mouse.swift index 2cbb600b..47a35d69 100644 --- a/NvimView/NvimView/NvimView+Mouse.swift +++ b/NvimView/NvimView/NvimView+Mouse.swift @@ -33,9 +33,11 @@ extension NvimView { let (vimInputX, vimInputY) = self.vimScrollInputFor(deltaX: deltaX, deltaY: deltaY, modifierFlags: event.modifierFlags, cellPosition: cellPosition) - self.bridge - .vimInput(vimInputX) - .andThen(self.bridge.vimInput(vimInputY)) + self.api + .input(keys: vimInputX, checkBlocked: false).asCompletable() + .andThen( + self.api.input(keys: vimInputY, checkBlocked: false).asCompletable() + ) .subscribe() .disposed(by: self.disposeBag) @@ -85,7 +87,7 @@ extension NvimView { func position(at location: CGPoint) -> Position { let row = Int( (self.bounds.size.height - location.y - self.offset.y) - / self.cellSize.height + / self.cellSize.height ) let column = Int((location.x - self.offset.x) / self.cellSize.width) @@ -117,8 +119,8 @@ extension NvimView { result = self.wrapNamedKeys("\(vimClickCount)\(vimName)") + vimMouseLocation } - self.bridge - .vimInput(result) + self.api + .input(keys: result, checkBlocked: false) .subscribe() .disposed(by: self.disposeBag) } @@ -126,8 +128,8 @@ extension NvimView { private func shouldFireVimInputFor(event: NSEvent, newCellPosition: Position) -> Bool { let type = event.type guard type == .leftMouseDragged - || type == .rightMouseDragged - || type == .otherMouseDragged else { + || type == .rightMouseDragged + || type == .otherMouseDragged else { self.lastClickedCellPosition = newCellPosition return true diff --git a/NvimView/NvimView/SharedTypes.h b/NvimView/NvimView/SharedTypes.h index 3beae944..effb56de 100644 --- a/NvimView/NvimView/SharedTypes.h +++ b/NvimView/NvimView/SharedTypes.h @@ -49,7 +49,6 @@ typedef NS_ENUM(NSInteger, NvimServerMsgId) { typedef NS_ENUM(NSInteger, NvimBridgeMsgId) { NvimBridgeMsgIdAgentReady = 0, NvimBridgeMsgIdReadyForRpcEvents, - NvimBridgeMsgIdInput, NvimBridgeMsgIdDeleteInput, NvimBridgeMsgIdResize, NvimBridgeMsgIdScroll, diff --git a/NvimView/NvimView/UiBridge.swift b/NvimView/NvimView/UiBridge.swift index 917b8262..700b6689 100644 --- a/NvimView/NvimView/UiBridge.swift +++ b/NvimView/NvimView/UiBridge.swift @@ -104,10 +104,6 @@ class UiBridge { .timeout(timeout, scheduler: self.scheduler) } - func vimInput(_ str: String) -> Completable { - return self.sendMessage(msgId: .input, data: str.data(using: .utf8)) - } - func deleteCharacters(_ count: Int, andInputEscapedString string: String) -> Completable {