ソースを参照

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
Domagoj Kriskovic 1 年間 前
親
コミット
174d62e4cc

+ 14 - 2
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,
   }
 }