Skip to content

Commit 83a4466

Browse files
authored
Do not adjust y offset when the mouse is below the last line (microsoft#164750)
Fixes microsoft#164131: Do not adjust y offset when the mouse is below the last line
1 parent 9e0b95f commit 83a4466

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/vs/editor/browser/controller/mouseTarget.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -851,22 +851,31 @@ export class MouseTargetFactory {
851851
// In Chrome, especially on Linux it is possible to click between lines,
852852
// so try to adjust the `hity` below so that it lands in the center of a line
853853
const lineNumber = ctx.getLineNumberAtVerticalOffset(request.mouseVerticalOffset);
854-
const lineVerticalOffset = ctx.getVerticalOffsetForLineNumber(lineNumber);
855-
const lineCenteredVerticalOffset = lineVerticalOffset + Math.floor(ctx.lineHeight / 2);
856-
let adjustedPageY = request.pos.y + (lineCenteredVerticalOffset - request.mouseVerticalOffset);
854+
const lineStartVerticalOffset = ctx.getVerticalOffsetForLineNumber(lineNumber);
855+
const lineEndVerticalOffset = lineStartVerticalOffset + ctx.lineHeight;
857856

858-
if (adjustedPageY <= request.editorPos.y) {
859-
adjustedPageY = request.editorPos.y + 1;
860-
}
861-
if (adjustedPageY >= request.editorPos.y + request.editorPos.height) {
862-
adjustedPageY = request.editorPos.y + request.editorPos.height - 1;
863-
}
857+
const isBelowLastLine = (
858+
lineNumber === ctx.viewModel.getLineCount()
859+
&& request.mouseVerticalOffset > lineEndVerticalOffset
860+
);
864861

865-
const adjustedPage = new PageCoordinates(request.pos.x, adjustedPageY);
862+
if (!isBelowLastLine) {
863+
const lineCenteredVerticalOffset = Math.floor((lineStartVerticalOffset + lineEndVerticalOffset) / 2);
864+
let adjustedPageY = request.pos.y + (lineCenteredVerticalOffset - request.mouseVerticalOffset);
866865

867-
const r = this._actualDoHitTestWithCaretRangeFromPoint(ctx, adjustedPage.toClientCoordinates());
868-
if (r.type === HitTestResultType.Content) {
869-
return r;
866+
if (adjustedPageY <= request.editorPos.y) {
867+
adjustedPageY = request.editorPos.y + 1;
868+
}
869+
if (adjustedPageY >= request.editorPos.y + request.editorPos.height) {
870+
adjustedPageY = request.editorPos.y + request.editorPos.height - 1;
871+
}
872+
873+
const adjustedPage = new PageCoordinates(request.pos.x, adjustedPageY);
874+
875+
const r = this._actualDoHitTestWithCaretRangeFromPoint(ctx, adjustedPage.toClientCoordinates());
876+
if (r.type === HitTestResultType.Content) {
877+
return r;
878+
}
870879
}
871880

872881
// Also try to hit test without the adjustment (for the edge cases that we are near the top or bottom)

0 commit comments

Comments
 (0)