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
This commit is contained in:
Domagoj Kriskovic
2024-12-06 12:43:48 +01:00
committed by Copybot
parent 527f56599f
commit 174d62e4cc
@@ -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,
}
}