1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-25 23:02:35 +03:00

GH-339 Try set cursor method

This commit is contained in:
Tae Won Ha 2017-01-07 13:55:53 +01:00
parent 2e7a52c3cc
commit 5098c13781
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
7 changed files with 58 additions and 7 deletions

View File

@ -99,6 +99,8 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
case NeoVimAgentMsgIdDelete: return null_data_async(data, neovim_delete);
case NeoVimAgentDebug1: return null_data_async(data, neovim_cursor_goto);
default: return NULL;
}

View File

@ -27,3 +27,5 @@ extern void neovim_vim_command(void **argv);
extern void neovim_vim_input(void **argv);
extern void neovim_vim_input_marked_text(void **argv);
extern void neovim_delete(void **argv);
extern void neovim_cursor_goto(void **argv);

View File

@ -30,6 +30,8 @@
#import <nvim/fileio.h>
#import <nvim/undo.h>
#import <nvim/eval.h>
#import <nvim/api/window.h>
#import <nvim/screen.h>
#define pun_type(t, x) (*((t *) (&(x))))
@ -757,7 +759,9 @@ void neovim_vim_command(void **argv) {
Error err = ERROR_INIT;
nvim_command(vim_string_from(input), &err);
// FIXME: handle err.set == true
if (err.set) {
WLOG("ERROR while executing command %s: %s", input.cstr, err.msg);
}
[input release];
@ -851,3 +855,31 @@ void neovim_delete(void **argv) {
return nil;
});
}
void neovim_cursor_goto(void **argv) {
work_async(argv, ^NSData *(NSData *data) {
Array position = ARRAY_DICT_INIT;
position.size = 2;
position.items = xmalloc(sizeof(Object) * 2);
Object row = OBJECT_INIT;
row.type = kObjectTypeInteger;
row.data.integer = 10;
Object col = OBJECT_INIT;
col.type = kObjectTypeInteger;
col.data.integer = 5;
position.items[0] = row;
position.items[1] = col;
Error err = ERROR_INIT;
nvim_win_set_cursor(nvim_get_current_win(), position, &err);
// nvim_input((String){.data="<ESC>", .size=5});
xfree(position.items);
return nil;
});
}

View File

@ -21,6 +21,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, weak) id <NeoVimUiBridgeProtocol> bridge;
- (instancetype)initWithUuid:(NSString *)uuid;
- (void)debug;
- (void)quit;
- (bool)runLocalServerAndNeoVim;

View File

@ -84,7 +84,7 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
NSCondition *_neoVimReadyCondition;
bool _isInitErrorPresent;
uint32_t _neoVimIsQuitting;
volatile uint32_t _neoVimIsQuitting;
}
- (instancetype)initWithUuid:(NSString *)uuid {
@ -108,6 +108,10 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
return _neoVimIsQuitting == 1;
}
- (void)debug {
[self sendMessageWithId:NeoVimAgentDebug1 data:nil expectsReply:NO];
}
// We cannot use -dealloc for this since -dealloc is not called until the run loop in the thread stops.
- (void)quit {
OSAtomicOr32Barrier(1, &_neoVimIsQuitting);
@ -236,7 +240,7 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
NSData *response = [self sendMessageWithId:NeoVimAgentMsgIdGetDirtyDocs data:nil expectsReply:YES];
if (response == nil) {
log4Warn("The response for the msg %lu was nil.", NeoVimAgentMsgIdGetDirtyDocs);
return YES;
return NO;
}
NSNumber *value = [NSKeyedUnarchiver unarchiveObjectWithData:response];

View File

@ -208,8 +208,14 @@ public class NeoVimView: NSView, NeoVimUiBridgeProtocol, NSUserInterfaceValidati
@IBAction public func debug1(_ sender: AnyObject?) {
NSLog("DEBUG 1 - Start")
self.vimExCommand("norm 10G5|")
self.vimInput("<ESC>")
// self.vimExCommand("norm 10G5|")
// self.vimExCommand("redraw")
// self.vimExCommand("cal cursor(10,5)")
// self.exec(command: "cal cursor(10,5)")
// self.vimOutput(of: "cal nvim_win_set_cursor(1000, [10, 5])")
// self.vimExCommand("redraw")
// self.vimInput("<ESC>")
self.agent.debug()
NSLog("DEBUG 1 - End")
}

View File

@ -309,9 +309,11 @@ class MainWindowComponent: WindowComponent,
self.neoVimView.select(buffer: buffer)
case let PreviewComponent.Action.reverseSearch(to: position):
self.neoVimView.vimExCommand("norm \(position.row)G\(position.column)|")
let command = "norm \(position.row)G\(position.column)|"
self.neoVimView.exec(command: "call nvim_win_set_cursor(1000, 10, 5)")
// self.neoVimView.vimExCommand(command)
// The above command does not refresh the cursor...
self.neoVimView.vimInput("<ESC>")
// self.neoVimView.vimInput("<ESC>")
return