Skip to content

Commit 01765cd

Browse files
authored
Merge pull request #381 from macvim-dev/fix/scroll
Fix scroll on 10.12
2 parents 9172041 + 39c4be7 commit 01765cd

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/MacVim/MMTextViewHelper.h

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
NSMutableDictionary *signImages;
3636
BOOL useMouseTime;
3737
NSDate *mouseDownTime;
38+
CGFloat scrollingDeltaX;
39+
CGFloat scrollingDeltaY;
3840

3941
// Input Manager
4042
NSRange imRange;

src/MacVim/MMTextViewHelper.m

+32-5
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,38 @@ - (void)doCommandBySelector:(SEL)sel
280280

281281
- (void)scrollWheel:(NSEvent *)event
282282
{
283+
float dx = 0;
284+
float dy = 0;
285+
286+
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
287+
if ([event hasPreciseScrollingDeltas]) {
288+
NSSize cellSize = [textView cellSize];
289+
float thresholdX = cellSize.width;
290+
float thresholdY = cellSize.height;
291+
scrollingDeltaX += [event scrollingDeltaX];
292+
if (fabs(scrollingDeltaX) > thresholdX) {
293+
dx = roundf(scrollingDeltaX / thresholdX);
294+
scrollingDeltaX -= thresholdX * dx;
295+
}
296+
scrollingDeltaY += [event scrollingDeltaY];
297+
if (fabs(scrollingDeltaY) > thresholdY) {
298+
dy = roundf(scrollingDeltaY / thresholdY);
299+
scrollingDeltaY -= thresholdY * dy;
300+
}
301+
} else {
302+
scrollingDeltaX = 0;
303+
scrollingDeltaY = 0;
304+
dx = [event scrollingDeltaX];
305+
dy = [event scrollingDeltaY];
306+
}
307+
#else
308+
dx = [event deltaX];
309+
dy = [event deltaY];
310+
#endif
311+
312+
if (dx == 0 && dy == 0)
313+
return;
314+
283315
if ([self hasMarkedText]) {
284316
// We must clear the marked text since the cursor may move if the
285317
// marked text moves outside the view as a result of scrolling.
@@ -288,11 +320,6 @@ - (void)scrollWheel:(NSEvent *)event
288320
[[NSTextInputContext currentInputContext] discardMarkedText];
289321
}
290322

291-
float dx = [event deltaX];
292-
float dy = [event deltaY];
293-
if (dx == 0 && dy == 0)
294-
return;
295-
296323
int row, col;
297324
NSPoint pt = [textView convertPoint:[event locationInWindow] fromView:nil];
298325
if ([textView convertPoint:pt toRow:&row column:&col]) {

0 commit comments

Comments
 (0)