1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-25 14:52:19 +03:00

GH-339 Push the current line and col to the UI

This commit is contained in:
Tae Won Ha 2017-01-07 15:53:32 +01:00
parent fbe1d4a917
commit 491eaa73d4
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
5 changed files with 35 additions and 23 deletions

View File

@ -190,9 +190,15 @@ static void server_ui_cursor_goto(UI *ui __unused, int row, int col) {
_put_row = row;
_put_column = col;
int values[] = {row, col, screen_cursor_row(), screen_cursor_column()};
DLOG("%d:%d - %d:%d", values[0], values[1], values[2], values[3]);
NSData *data = [[NSData alloc] initWithBytes:values length:(4 * sizeof(int))];
int values[] = {
row, col,
screen_cursor_row(), screen_cursor_column(),
(int) curwin->w_cursor.lnum, curwin->w_cursor.col + 1
};
DLOG("%d:%d - %d:%d - %d:%d", values[0], values[1], values[2], values[3], values[4], values[5]);
NSData *data = [[NSData alloc] initWithBytes:values length:(6 * sizeof(int))];
[_neovim_server sendMessageWithId:NeoVimServerMsgIdSetPosition data:data];
[data release];
}
@ -639,15 +645,17 @@ void neovim_vim_command_output(void **argv) {
// We don't know why nvim_command_output does not work when the optimization level is set to -Os.
// If set to -O0, nvim_command_output works fine... -_-
// String commandOutput = nvim_command_output((String) {
// .data = (char *) input.cstr,
// .size = [input lengthOfBytesUsingEncoding:NSUTF8StringEncoding]
// }, &err);
do_cmdline_cmd("redir => v:command_output");
nvim_command(vim_string_from(input), &err);
do_cmdline_cmd("redir END");
String commandOutput = nvim_command_output((String) {
.data = (char *) input.cstr,
.size = [input lengthOfBytesUsingEncoding:NSUTF8StringEncoding]
}, &err);
// do_cmdline_cmd("redir => v:command_output");
// nvim_command(vim_string_from(input), &err);
// do_cmdline_cmd("redir END");
//
// char_u *output = get_vim_var_str(VV_COMMAND_OUTPUT);
char_u *output = get_vim_var_str(VV_COMMAND_OUTPUT);
char_u *output = (char_u *) commandOutput.data;
// FIXME: handle err.set == true
NSString *result = nil;

View File

@ -355,6 +355,9 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
}
- (NSData *)sendMessageWithId:(NeoVimAgentMsgId)msgid data:(NSData *)data expectsReply:(bool)expectsReply {
if (!NSThread.isMainThread) {
NSLog(@"THREAD: %@\t msgid: %d\t data: %@", NSThread.currentThread, msgid, data);
}
if (_neoVimIsQuitting == 1 && msgid != NeoVimAgentMsgIdQuit) {
// This happens often, e.g. when exiting full screen by closing all buffers. We try to resize the window after
// the message port has been closed. This is a quick-and-dirty fix.
@ -450,9 +453,10 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
return;
case NeoVimServerMsgIdSetPosition: {
int *values = data_to_int_array(data, 4);
int *values = data_to_int_array(data, 6);
[_bridge gotoPosition:(Position) { .row = values[0], .column = values[1] }
screenCursor:(Position) { .row = values[2], .column = values[3] }];
screenCursor:(Position) { .row = values[2], .column = values[3] }
currentPosition:(Position) { .row = values[4], .column = values[5] }];
return;
}

View File

@ -69,7 +69,7 @@ NS_ASSUME_NONNULL_BEGIN
* 2. NeoVim wants to put the cursor at (row, column).
* In case of 1. NeoVim will put in subsequent call. In case of 2. NeoVim seems to flush twice in a row.
*/
- (void)gotoPosition:(Position)position screenCursor:(Position)screenCursor;
- (void)gotoPosition:(Position)position screenCursor:(Position)screenCursor currentPosition:(Position)currentPosition;
- (void)updateMenu;
- (void)busyStart;

View File

@ -107,6 +107,8 @@ public class NeoVimView: NSView, NeoVimUiBridgeProtocol, NSUserInterfaceValidati
return true
}
public fileprivate(set) var currentPosition = Position(row: 1, column: 1)
fileprivate static let emojis: [UInt32] = [
0x1F600...0x1F64F,
0x1F910...0x1F918,
@ -1252,8 +1254,9 @@ extension NeoVimView {
}
}
public func gotoPosition(_ position: Position, screenCursor: Position) {
public func gotoPosition(_ position: Position, screenCursor: Position, currentPosition: Position) {
DispatchUtils.gui {
self.currentPosition = currentPosition
// NSLog("\(#function): \(position), \(screenCursor)")
let curScreenCursor = self.grid.screenCursor
@ -1316,12 +1319,11 @@ extension NeoVimView {
DispatchUtils.gui {
self.grid.scroll(Int(count))
self.setNeedsDisplay(region: self.grid.region)
DispatchUtils.gui {
// We do this in the next tick since we could (and do) call the agent again in the delegate method.
// Do not send msgs to agent -> neovim in the delegate method. It causes spinning when you're opening a file with
// existing swap file.
self.delegate?.scroll()
}
}
}
public func highlightSet(_ attrs: CellAttributes) {
DispatchUtils.gui {

View File

@ -15,13 +15,11 @@ protocol NeoVimInfoProvider: class {
extension NeoVimView: NeoVimInfoProvider {
func currentLine() -> Int {
let output = self.vimOutput(of: "echo line('.')")
return Int(output) ?? 0
return self.currentPosition.row
}
func currentColumn() -> Int {
let output = self.vimOutput(of: "echo virtcol('.')")
return Int(output) ?? 0
return self.currentPosition.column
}
}