New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scroll wheel sends escape sequences in alternate screen mode #282
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1546,7 +1546,7 @@ - (void)rightMouseDragged:(NSEvent *)event | |
[super rightMouseDragged:event]; | ||
} | ||
|
||
- (BOOL)scrollWheelShouldSendArrowForEvent:(NSEvent *)event at:(NSPoint)point { | ||
- (BOOL)scrollWheelShouldSendAuxForEvent:(NSEvent *)event at:(NSPoint)point upData:(NSData**)upData downData:(NSData**)downData { | ||
NSRect liveRect = [self liveRect]; | ||
if (!NSPointInRect(point, liveRect)) { | ||
return NO; | ||
|
@@ -1560,40 +1560,52 @@ - (BOOL)scrollWheelShouldSendArrowForEvent:(NSEvent *)event at:(NSPoint)point { | |
return NO; | ||
} | ||
BOOL alternateMouseScroll = [iTermAdvancedSettingsModel alternateMouseScroll]; | ||
NSString* alternateMouseScrollEscapeUp = [iTermAdvancedSettingsModel alternateMouseScrollEscapeUp]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (style nitpick) Put the space before the |
||
NSString* alternateMouseScrollEscapeDown = [iTermAdvancedSettingsModel alternateMouseScrollEscapeDown]; | ||
BOOL showingAlternateScreen = [self.dataSource showingAlternateScreen]; | ||
if (!alternateMouseScroll && showingAlternateScreen) { | ||
[_altScreenMouseScrollInferer scrollWheel:event]; | ||
} | ||
if (!alternateMouseScroll) { | ||
if (!showingAlternateScreen) { | ||
return NO; | ||
} | ||
if (!showingAlternateScreen) { | ||
|
||
if (alternateMouseScroll) { | ||
*upData = [_dataSource.terminal.output keyArrowUp:event.modifierFlags]; | ||
*downData = [_dataSource.terminal.output keyArrowDown:event.modifierFlags]; | ||
return YES; | ||
} else if (alternateMouseScrollEscapeUp.length && alternateMouseScrollEscapeDown.length) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this could cause confusion if a user intentionally sets only one to experiment with it. |
||
|
||
NSString* e_ups = [NSString stringWithFormat:@"\e%@", alternateMouseScrollEscapeUp ]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably send multiple repeats of the code when you scroll fast. Also, don't prepend |
||
NSString* e_dps = [NSString stringWithFormat:@"\e%@", alternateMouseScrollEscapeDown ]; | ||
|
||
*upData = [ e_ups dataUsingEncoding:_dataSource.terminal.encoding ]; | ||
*downData = [ e_dps dataUsingEncoding:_dataSource.terminal.encoding ]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
return YES; | ||
} else { | ||
[_altScreenMouseScrollInferer scrollWheel:event]; | ||
return NO; | ||
} | ||
return YES; | ||
} | ||
|
||
|
||
- (void)scrollWheel:(NSEvent *)event { | ||
DLog(@"scrollWheel:%@", event); | ||
|
||
NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; | ||
|
||
if ([self scrollWheelShouldSendArrowForEvent:event at:point]) { | ||
NSData* upData = nil; | ||
NSData* downData = nil; | ||
if ([self scrollWheelShouldSendAuxForEvent:event at:point upData:&upData downData:&downData]) { | ||
DLog(@"Scroll wheel sending arrow key"); | ||
|
||
PTYScrollView *scrollView = (PTYScrollView *)self.enclosingScrollView; | ||
CGFloat deltaY = [scrollView accumulateVerticalScrollFromEvent:event]; | ||
|
||
NSData *arrowKeyData = nil; | ||
NSData* payload = nil; | ||
if (deltaY > 0) { | ||
arrowKeyData = [_dataSource.terminal.output keyArrowUp:event.modifierFlags]; | ||
payload = upData; | ||
} else if (deltaY < 0) { | ||
arrowKeyData = [_dataSource.terminal.output keyArrowDown:event.modifierFlags]; | ||
payload = downData; | ||
} | ||
if (arrowKeyData) { | ||
if (payload) { | ||
for (int i = 0; i < ceil(fabs(deltaY)); i++) { | ||
[_delegate writeTask:arrowKeyData]; | ||
[_delegate writeTask:payload]; | ||
} | ||
} | ||
} else if (![self reportMouseEvent:event]) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,8 @@ + (NSString *)name { \ | |
DEFINE_BOOL(allowDragOfTabIntoNewWindow, YES, @"Tabs: Allow a tab to be dragged and dropped outside any existing tab bar to create a new window."); | ||
|
||
#pragma mark Mouse | ||
DEFINE_STRING(alternateMouseScrollEscapeUp, @"", @"Mouse: Scroll wheel sends the specified escape sequence in alternate screen mode (up)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a newline and explain that the string should use vim syntax, such as |
||
DEFINE_STRING(alternateMouseScrollEscapeDown, @"", @"Mouse: Scroll wheel sends the specified escape sequence in alternate screen mode (down)"); | ||
DEFINE_BOOL(alternateMouseScroll, NO, @"Mouse: Scroll wheel sends arrow keys when in alternate screen mode."); | ||
DEFINE_BOOL(pinchToChangeFontSizeDisabled, NO, @"Mouse: Disable changing font size in response to a pinch gesture."); | ||
DEFINE_BOOL(useSystemCursorWhenPossible, NO, @"Mouse: Use system cursor icons when possible."); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's separate computing the data to send from determining if data should be sent. That means two methods:
(by not taking a
point
we're doing a touch of cleanup here since the point can be computed from theevent
and the caller doesn't need it for anything but passing to this method)and
which calls
enclosingScrollView
andaccumulateVerticalScrollFromEvent
, and then returns the appropriate data.