Skip to content

Commit

Permalink
Merge pull request #168 from macvim-dev/feature/mousetime
Browse files Browse the repository at this point in the history
Add MMUseMouseTime, Revise #77
  • Loading branch information
splhack committed Dec 10, 2015
2 parents 11bd9b9 + cbd8ff0 commit e387a4c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/MacVim/MMBackend.m
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,7 @@ - (void)insertVimStateMessage
[NSNumber numberWithBool:mmta], @"p_mmta",
[NSNumber numberWithInt:numTabs], @"numTabs",
[NSNumber numberWithInt:fuoptions_flags], @"fullScreenOptions",
[NSNumber numberWithLong:p_mouset], @"p_mouset",
nil];

// Put the state before all other messages.
Expand Down Expand Up @@ -1932,12 +1933,12 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data
int col = *((int*)bytes); bytes += sizeof(int);
int button = *((int*)bytes); bytes += sizeof(int);
int flags = *((int*)bytes); bytes += sizeof(int);
int count = *((int*)bytes); bytes += sizeof(int);
int repeat = *((int*)bytes); bytes += sizeof(int);

button = eventButtonNumberToVimMouseButton(button);
if (button >= 0) {
flags = eventModifierFlagsToVimMouseModMask(flags);
gui_send_mouse_event(button, col, row, count>1, flags);
gui_send_mouse_event(button, col, row, repeat, flags);
}
} else if (MouseUpMsgID == msgid) {
if (!data) return;
Expand Down
2 changes: 2 additions & 0 deletions src/MacVim/MMTextViewHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
BOOL interpretKeyEventsSwallowedKey;
NSEvent *currentEvent;
NSMutableDictionary *signImages;
BOOL useMouseTime;
NSDate *mouseDownTime;

// Input Manager
NSRange imRange;
Expand Down
24 changes: 22 additions & 2 deletions src/MacVim/MMTextViewHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ - (id)init

signImages = [[NSMutableDictionary alloc] init];

useMouseTime =
[[NSUserDefaults standardUserDefaults] boolForKey:MMUseMouseTimeKey];
if (useMouseTime)
mouseDownTime = [[NSDate date] retain];

return self;
}

Expand All @@ -91,6 +96,7 @@ - (void)dealloc
[markedText release]; markedText = nil;
[markedTextAttributes release]; markedTextAttributes = nil;
[signImages release]; signImages = nil;
[mouseDownTime release]; mouseDownTime = nil;

#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
if (asciiImSource) {
Expand Down Expand Up @@ -380,7 +386,21 @@ - (void)mouseDown:(NSEvent *)event

int button = [event buttonNumber];
int flags = [event modifierFlags];
int count = [event clickCount];
int repeat = 0;

if (useMouseTime) {
// Use Vim mouseTime option to handle multiple mouse down events
NSDate *now = [[NSDate date] retain];
id mouset = [[[self vimController] vimState] objectForKey:@"p_mouset"];
NSTimeInterval interval =
[now timeIntervalSinceDate:mouseDownTime] * 1000.0;
if (interval < (NSTimeInterval)[mouset longValue])
repeat = 1;
mouseDownTime = now;
} else {
repeat = [event clickCount] > 1;
}

NSMutableData *data = [NSMutableData data];

// If desired, intepret Ctrl-Click as a right mouse click.
Expand All @@ -398,7 +418,7 @@ - (void)mouseDown:(NSEvent *)event
[data appendBytes:&col length:sizeof(int)];
[data appendBytes:&button length:sizeof(int)];
[data appendBytes:&flags length:sizeof(int)];
[data appendBytes:&count length:sizeof(int)];
[data appendBytes:&repeat length:sizeof(int)];

[[self vimController] sendMessage:MouseDownMsgID data:data];
}
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/Miscellaneous.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern NSString *MMUseInlineImKey;
#endif // INCLUDE_OLD_IM_CODE
extern NSString *MMSuppressTerminationAlertKey;
extern NSString *MMNativeFullScreenKey;
extern NSString *MMUseMouseTimeKey;


// Enum for MMUntitledWindowKey
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/Miscellaneous.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#endif // INCLUDE_OLD_IM_CODE
NSString *MMSuppressTerminationAlertKey = @"MMSuppressTerminationAlert";
NSString *MMNativeFullScreenKey = @"MMNativeFullScreen";
NSString *MMUseMouseTimeKey = @"MMUseMouseTime";



Expand Down

0 comments on commit e387a4c

Please sign in to comment.