mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-25 23:02:35 +03:00
Use input from API
This commit is contained in:
parent
3c8c608003
commit
5a381dd1e2
@ -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);
|
||||
|
||||
|
@ -49,7 +49,6 @@ typedef NS_ENUM(NSInteger, NvimServerMsgId) {
|
||||
typedef NS_ENUM(NSInteger, NvimBridgeMsgId) {
|
||||
NvimBridgeMsgIdAgentReady = 0,
|
||||
NvimBridgeMsgIdReadyForRpcEvents,
|
||||
NvimBridgeMsgIdInput,
|
||||
NvimBridgeMsgIdDeleteInput,
|
||||
NvimBridgeMsgIdResize,
|
||||
NvimBridgeMsgIdScroll,
|
||||
|
@ -15,7 +15,6 @@ extern void start_neovim(NSInteger width, NSInteger height, NSArray<NSString *>
|
||||
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);
|
||||
|
@ -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;
|
||||
|
@ -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" {
|
||||
// <C-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 }
|
||||
|
@ -50,15 +50,15 @@ extension NvimView {
|
||||
@IBAction func undo(_ sender: AnyObject?) {
|
||||
switch self.mode {
|
||||
case .insert, .replace:
|
||||
self.bridge
|
||||
.vimInput("<Esc>ui")
|
||||
self.api
|
||||
.input(keys: "<Esc>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("<Esc><C-r>i")
|
||||
self.api
|
||||
.input(keys: "<Esc><C-r>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("<C-r>")
|
||||
self.api
|
||||
.input(keys: "<C-r>", 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 ? "<ESC>\"+Pa" : "<ESC>\"+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("<Esc>ggVG")
|
||||
self.api
|
||||
.input(keys: "<Esc>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))
|
||||
})
|
||||
|
@ -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
|
||||
|
@ -49,7 +49,6 @@ typedef NS_ENUM(NSInteger, NvimServerMsgId) {
|
||||
typedef NS_ENUM(NSInteger, NvimBridgeMsgId) {
|
||||
NvimBridgeMsgIdAgentReady = 0,
|
||||
NvimBridgeMsgIdReadyForRpcEvents,
|
||||
NvimBridgeMsgIdInput,
|
||||
NvimBridgeMsgIdDeleteInput,
|
||||
NvimBridgeMsgIdResize,
|
||||
NvimBridgeMsgIdScroll,
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user