From 174d62e4cc23a427b355d5b173418ca3f6ab65dc Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Fri, 6 Dec 2024 12:43:48 +0100 Subject: [PATCH] Improve positioning of "Add comment" tooltip when selecting entire line(s) (#22277) * Avoid obscuring text with "Add comment" tooltip when selecting entire line * tooltip position change on direction of selection GitOrigin-RevId: d8cd301091104dae2422e34e14f90afd4c0927c4 --- .../source-editor/extensions/review-tooltip.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/extensions/review-tooltip.ts b/services/web/frontend/js/features/source-editor/extensions/review-tooltip.ts index 61d1681ae8..1dca2689c4 100644 --- a/services/web/frontend/js/features/source-editor/extensions/review-tooltip.ts +++ b/services/web/frontend/js/features/source-editor/extensions/review-tooltip.ts @@ -126,9 +126,21 @@ function buildTooltip(state: EditorState): Tooltip | null { return null } + const lineAtFrom = state.doc.lineAt(state.selection.main.from) + const lineAtTo = state.doc.lineAt(state.selection.main.to) + const multiLineSelection = lineAtFrom.number !== lineAtTo.number + const column = state.selection.main.head - lineAtTo.from + + // If the selection is a multi-line selection and the cursor is at the beginning of the next line + // we want to show the tooltip at the end of the previous line + const pos = + multiLineSelection && column === 0 + ? state.selection.main.head - 1 + : state.selection.main.head + return { - pos: state.selection.main.head, - above: true, + pos, + above: state.selection.main.head !== state.selection.main.to, create: createReviewTooltipView, } }