mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-01 01:32:04 +03:00
Merge branch 'develop' into cglayer
Conflicts: SwiftNeoVim/CocoaExtensions.swift SwiftNeoVim/NeoVimView+Draw.swift SwiftNeoVim/NeoVimView+Mouse.swift SwiftNeoVim/NeoVimView+UiBridge.swift SwiftNeoVim/NeoVimView.swift
This commit is contained in:
commit
c1d919d740
@ -52,6 +52,7 @@ typedef NS_ENUM(NSUInteger, NeoVimAgentMsgId) {
|
||||
NeoVimAgentMsgIdDelete,
|
||||
NeoVimAgentMsgIdResize,
|
||||
NeoVimAgentMsgIdSelectWindow,
|
||||
NeoVimAgentMsgIdScroll,
|
||||
NeoVimAgentMsgIdCursorGoto,
|
||||
NeoVimAgentMsgIdQuit,
|
||||
|
||||
|
@ -72,6 +72,8 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
|
||||
|
||||
case NeoVimAgentMsgIdSelectWindow: return data_sync(data, outputCondition, neovim_select_window);
|
||||
|
||||
case NeoVimAgentMsgIdScroll: return data_sync(data, outputCondition, neovim_scroll);
|
||||
|
||||
case NeoVimAgentMsgIdGetTabs: return data_sync(data, outputCondition, neovim_tabs);
|
||||
|
||||
case NeoVimAgentMsgIdGetBuffers: return data_sync(data, outputCondition, neovim_buffers);
|
||||
|
@ -15,6 +15,7 @@ extern void start_neovim();
|
||||
extern void quit_neovim();
|
||||
|
||||
extern void neovim_select_window(void **argv);
|
||||
extern void neovim_scroll(void **argv);
|
||||
extern void neovim_tabs(void **argv);
|
||||
extern void neovim_buffers(void **argv);
|
||||
extern void neovim_vim_command_output(void **argv);
|
||||
|
@ -26,6 +26,8 @@
|
||||
#import <nvim/ex_getln.h>
|
||||
#import <nvim/fileio.h>
|
||||
#import <nvim/undo.h>
|
||||
#import <nvim/mouse.h>
|
||||
#import <nvim/edit.h>
|
||||
#import <nvim/api/window.h>
|
||||
|
||||
|
||||
@ -613,6 +615,34 @@ static NeoVimBuffer *buffer_for(buf_T *buf) {
|
||||
return [buffer autorelease];
|
||||
}
|
||||
|
||||
void neovim_scroll(void **argv) {
|
||||
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
|
||||
NSInteger *values = (NSInteger *) data.bytes;
|
||||
NSInteger horiz = values[0];
|
||||
NSInteger vert = values[1];
|
||||
|
||||
if (horiz == 0 && vert == 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// value > 0 => down or right
|
||||
int horizDir;
|
||||
int vertDir;
|
||||
if (horiz != 0) {
|
||||
horizDir = horiz > 0 ? MSCR_RIGHT: MSCR_LEFT;
|
||||
custom_ui_scroll(horizDir, (int) ABS(horiz));
|
||||
}
|
||||
if (vert != 0) {
|
||||
vertDir = vert > 0 ? MSCR_DOWN: MSCR_UP;
|
||||
custom_ui_scroll(vertDir, (int) ABS(vert));
|
||||
}
|
||||
|
||||
ui_refresh();
|
||||
|
||||
return nil;
|
||||
});
|
||||
}
|
||||
|
||||
void neovim_select_window(void **argv) {
|
||||
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
|
||||
int handle = ((int *) data.bytes)[0];
|
||||
|
@ -43,6 +43,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (NSArray<NSString *> *)escapedFileNames:(NSArray<NSString *> *)fileNames;
|
||||
- (NSArray<NeoVimBuffer *> *)buffers;
|
||||
- (NSArray<NeoVimTab*> *)tabs;
|
||||
|
||||
- (void)scrollHorizontal:(NSInteger)horiz vertical:(NSInteger)vert;
|
||||
- (void)selectWindow:(NeoVimWindow *)window;
|
||||
|
||||
// WAITS
|
||||
|
@ -305,6 +305,12 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
|
||||
[self sendMessageWithId:NeoVimAgentMsgIdSetBoolOption data:data expectsReply:YES];
|
||||
}
|
||||
|
||||
- (void)scrollHorizontal:(NSInteger)horiz vertical:(NSInteger)vert {
|
||||
NSInteger values[] = { horiz, vert };
|
||||
NSData *data = [[NSData alloc] initWithBytes:values length:2 * sizeof(NSInteger)];
|
||||
[self sendMessageWithId:NeoVimAgentMsgIdScroll data:data expectsReply:NO];
|
||||
}
|
||||
|
||||
- (void)selectWindow:(NeoVimWindow *)window {
|
||||
int values[] = { (int) window.handle };
|
||||
NSData *data = [[NSData alloc] initWithBytes:values length:sizeof(int)];
|
||||
|
@ -43,22 +43,10 @@ extension NeoVimView {
|
||||
return
|
||||
}
|
||||
|
||||
let (absDeltaX, absDeltaY) = (abs(deltaX), abs(deltaY))
|
||||
|
||||
// The absolute delta values can get very very big when you use two finger scrolling
|
||||
// on the trackpad: Cap them using heuristic values...
|
||||
let numX = deltaX != 0 ? max(1, min(Int(absDeltaX / scrollLimiterX), maxScrollDeltaX)) : 0
|
||||
let numY = deltaY != 0 ? max(1, min(Int(absDeltaY / scrollLimiterY), maxScrollDeltaY)) : 0
|
||||
|
||||
for i in 0..<max(numX, numY) {
|
||||
if i < numX {
|
||||
self.throttleScrollX(absDelta: absDeltaX, vimInput: vimInputX)
|
||||
}
|
||||
|
||||
if i < numY {
|
||||
self.throttleScrollY(absDelta: absDeltaY, vimInput: vimInputY)
|
||||
}
|
||||
}
|
||||
let (absDeltaX, absDeltaY) = (min(Int(abs(deltaX)), maxScrollDeltaX),
|
||||
min(Int(abs(deltaY)), maxScrollDeltaY))
|
||||
let (horizSign, vertSign) = (deltaX > 0 ? 1 : -1, deltaY > 0 ? 1 : -1)
|
||||
self.agent.scrollHorizontal(horizSign * absDeltaX, vertical: vertSign * absDeltaY)
|
||||
}
|
||||
|
||||
override public func magnify(with event: NSEvent) {
|
||||
@ -188,38 +176,6 @@ extension NeoVimView {
|
||||
|
||||
return (resultX, resultY)
|
||||
}
|
||||
|
||||
fileprivate func throttleScrollX(absDelta absDeltaX: CGFloat, vimInput: String) {
|
||||
if absDeltaX == 0 {
|
||||
self.scrollGuardCounterX = scrollGuardYield - 1
|
||||
} else if absDeltaX <= 2 {
|
||||
// Poor man's throttle for scroll value = 1 or 2
|
||||
if self.scrollGuardCounterX % scrollGuardYield == 0 {
|
||||
self.agent.vimInput(vimInput)
|
||||
self.scrollGuardCounterX = 1
|
||||
} else {
|
||||
self.scrollGuardCounterX += 1
|
||||
}
|
||||
} else {
|
||||
self.agent.vimInput(vimInput)
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func throttleScrollY(absDelta absDeltaY: CGFloat, vimInput: String) {
|
||||
if absDeltaY == 0 {
|
||||
self.scrollGuardCounterY = scrollGuardYield - 1
|
||||
} else if absDeltaY <= 2 {
|
||||
// Poor man's throttle for scroll value = 1 or 2
|
||||
if self.scrollGuardCounterY % scrollGuardYield == 0 {
|
||||
self.agent.vimInput(vimInput)
|
||||
self.scrollGuardCounterY = 1
|
||||
} else {
|
||||
self.scrollGuardCounterY += 1
|
||||
}
|
||||
} else {
|
||||
self.agent.vimInput(vimInput)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate let maxScrollDeltaX = 30
|
||||
|
@ -55,7 +55,7 @@ extension NeoVimView {
|
||||
// we don't get the puts, thus we have to redraw the put position.
|
||||
if self.usesLigatures {
|
||||
self.markForRender(region: self.grid.regionOfWord(at: self.grid.putPosition))
|
||||
|
||||
self.markForRender(region: self.grid.regionOfWord(at: curScreenCursor))
|
||||
self.markForRender(region: self.grid.regionOfWord(at: position))
|
||||
self.markForRender(region: self.grid.regionOfWord(at: screenCursor))
|
||||
} else {
|
||||
@ -90,7 +90,9 @@ extension NeoVimView {
|
||||
public func setScrollRegionToTop(_ top: Int, bottom: Int, left: Int, right: Int) {
|
||||
gui.async {
|
||||
self.bridgeLogger.debug("\(top):\(bottom):\(left):\(right)")
|
||||
self.grid.setScrollRegion(Region(top: top, bottom: bottom, left: left, right: right))
|
||||
|
||||
let region = Region(top: top, bottom: bottom, left: left, right: right)
|
||||
self.grid.setScrollRegion(region)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,8 @@ public class NeoVimView: NSView,
|
||||
|
||||
let logger = FileLogger(as: NeoVimView.self, with: URL(fileURLWithPath: "/tmp/nvv.log"))
|
||||
let bridgeLogger = FileLogger(as: NeoVimView.self,
|
||||
with: URL(fileURLWithPath: "/tmp/nvv-bridge.log"))
|
||||
with: URL(fileURLWithPath: "/tmp/nvv-bridge.log"),
|
||||
shouldLogDebug: false)
|
||||
let agent: NeoVimAgent
|
||||
let grid = Grid()
|
||||
|
||||
|
2
neovim
2
neovim
@ -1 +1 @@
|
||||
Subproject commit 1ff979cee6bfca5137ae8754484948628d9ef119
|
||||
Subproject commit 4b246213526564c477c96f485d4ce435628c6568
|
Loading…
Reference in New Issue
Block a user