fix(session-ui): select diff text and comment on it from a toolbar (#64410)

This commit is contained in:
Aarav Sareen
2026-11-17 16:32:12 +05:30
committed by GitHub
Unverified
parent 1e6bf4c34a
commit a9a35b4b4c
82 changed files with 1189 additions and 584 deletions
@@ -187,7 +187,8 @@ test("mobile changes summarize expanded diffs, stage comments, wrap by setting,
const note = "Use the existing value instead"
const commented = review.locator('[data-file="src/review.ts"]')
await commented.getByRole("button", { expanded: false }).click()
await commented.getByText("export const value = 'after'", { exact: true }).click()
await commented.getByText("export const value = 'after'", { exact: true }).hover()
await commented.getByRole("button", { name: "Comment", exact: true, includeHidden: true }).dispatchEvent("click")
await expect(commented.locator('[data-slot="line-comment-editor-label"]')).toHaveText("Commenting on line 2")
await commented.getByRole("textbox").fill(note)
await commented.locator('[data-slot="line-comment-action"][data-variant="primary"]').click()
+1
View File
@@ -499,6 +499,7 @@ export function SessionFileView(props: { session: MountedSession; screen: Sessio
annotations={commentsUi.annotations()}
renderAnnotation={commentsUi.renderAnnotation}
renderGutterUtility={commentsUi.renderGutterUtility}
onCommentSelection={commentsUi.commentSelection()}
onLineSelected={(range: LineRange | null) => {
commentsUi.onLineSelected(range)
}}
@@ -22,27 +22,17 @@ let first: Element | null = null
const ends: (SelectedLineRange | null)[] = []
const comments: SelectedLineRange[] = []
export const controls = {
setOverflow,
setSelected,
setCommented,
/** Every range `onLineSelectionEnd` reported, in order. */
ends: () => ends.map((range) => (range ? { start: range.start, end: range.end } : null)),
/** Every range the Add comment toolbar reported, in order. */
comments: () => comments.map((range) => ({ start: range.start, end: range.end })),
append: (line: string) => setContents((value) => value + line),
/** Dispatches mouse events on code lines in one task, so no animation frame runs between them. */
gesture: (steps: ["mousedown" | "mousemove" | "mouseup", number][]) => {
const root = document.querySelector("[data-testid='file-viewer-fixture'] diffs-container")?.shadowRoot
for (const [type, line] of steps) {
const target = root?.querySelector(`[data-line="${line}"]`)
if (!target) throw new Error(`line ${line} is not drawn`)
target.dispatchEvent(
new MouseEvent(type, { bubbles: true, composed: true, button: 0, buttons: type === "mouseup" ? 0 : 1 }),
)
}
},
// Keep the first Pierre host so a later check can tell an in-place update from a rebuild.
keepHost: () => (first = document.querySelector("[data-testid='file-viewer-fixture'] diffs-container")),
sameHost: () =>
@@ -76,6 +66,7 @@ export function mountTextViewer(lines: number) {
selectedLines={selected()}
commentedLines={commented()}
onLineSelectionEnd={(range) => ends.push(range)}
onCommentSelection={(range) => comments.push(range)}
/>
),
host(),
@@ -37,86 +37,73 @@ story("windows a medium text file and keeps selection and comment marks", async
await expect(root.locator('[data-line="400"]')).toBeInViewport()
})
story("selects lines by dragging over the code and over the line numbers", async ({ mount, page }) => {
story(
"selects text when dragging over the code and lines when dragging over the line numbers",
async ({ mount, page }) => {
await mount("components-markdown--compact-result")
await page.evaluate(async (fixture) => (await import(fixture)).mountTextViewer(40), fixture)
const root = page.getByTestId("file-viewer-fixture")
await expect(root.locator('[data-line="40"]')).toHaveCount(1)
const ends = () => page.evaluate(async (fixture) => (await import(fixture)).controls.ends(), fixture)
const from = await root.locator('[data-line="3"]').boundingBox()
const to = await root.locator('[data-line="6"]').boundingBox()
if (!from || !to) throw new Error("lines 3 and 6 have no layout")
await page.mouse.move(from.x + 8, from.y + from.height / 2)
await page.mouse.down()
await page.mouse.move(to.x + 40, to.y + to.height / 2, { steps: 6 })
await page.mouse.up()
await expect(page.getByRole("toolbar", { name: "Selection actions" })).toBeVisible()
const first = await root.locator('[data-column-number="8"]').boundingBox()
const last = await root.locator('[data-column-number="10"]').boundingBox()
if (!first || !last) throw new Error("line numbers 8 and 10 have no layout")
await page.mouse.move(first.x + first.width / 2, first.y + first.height / 2)
await page.mouse.down()
await page.mouse.move(last.x + last.width / 2, last.y + last.height / 2, { steps: 4 })
await page.mouse.up()
await expect(root.locator("[data-line][data-selected-line]")).toHaveCount(3)
// The text drag ended no line selection.
await expect.poll(ends).toEqual([{ start: 8, end: 10 }])
},
)
story("comments on the lines a selection covers, not the next one it ends at", async ({ mount, page }) => {
await mount("components-markdown--compact-result")
await page.evaluate(async (fixture) => (await import(fixture)).mountTextViewer(40), fixture)
const root = page.getByTestId("file-viewer-fixture")
const add = page.getByRole("toolbar", { name: "Selection actions" }).getByRole("button", { name: "Add comment" })
await expect(root.locator('[data-line="40"]')).toHaveCount(1)
const ends = () => page.evaluate(async (fixture) => (await import(fixture)).controls.ends(), fixture)
const from = await root.locator('[data-line="3"]').boundingBox()
const to = await root.locator('[data-line="6"]').boundingBox()
// A triple click selects line 3 up to the start of line 4.
await root.locator('[data-line="3"]').click({ clickCount: 3 })
await expect(add).toBeVisible()
const line = await root.locator('[data-line="3"]').boundingBox()
const toolbar = await page.getByRole("toolbar", { name: "Selection actions" }).boundingBox()
if (!from || !to) throw new Error("lines 3 and 6 have no layout")
await page.mouse.move(from.x + 8, from.y + from.height / 2)
if (!line || !toolbar) throw new Error("line 3 or the toolbar has no layout")
// A one-line selection gets the toolbar above it, not below the next line.
expect(toolbar.y + toolbar.height).toBeLessThanOrEqual(line.y)
await add.click()
// A drag that starts past the end of line 7 selects only its line break, so it comments from line 8.
const from = await root.locator('[data-line="7"]').boundingBox()
const to = await root.locator('[data-line="9"]').boundingBox()
if (!from || !to) throw new Error("lines 7 and 9 have no layout")
await page.mouse.move(from.x + from.width - 4, from.y + from.height / 2)
await page.mouse.down()
await page.mouse.move(to.x + 40, to.y + to.height / 2, { steps: 6 })
await page.mouse.up()
await expect(root.locator("[data-line][data-selected-line]")).toHaveCount(4)
await expect.poll(ends).toEqual([{ start: 3, end: 6 }])
const first = await root.locator('[data-column-number="8"]').boundingBox()
const last = await root.locator('[data-column-number="10"]').boundingBox()
if (!first || !last) throw new Error("line numbers 8 and 10 have no layout")
await page.mouse.move(first.x + first.width / 2, first.y + first.height / 2)
await page.mouse.down()
await page.mouse.move(last.x + last.width / 2, last.y + last.height / 2, { steps: 4 })
await page.mouse.up()
await expect(root.locator("[data-line][data-selected-line]")).toHaveCount(3)
await expect.poll(ends).toEqual([
{ start: 3, end: 6 },
{ start: 8, end: 10 },
])
})
story("commits a drag whose text selection stays collapsed", async ({ mount, page }) => {
await mount("components-markdown--compact-result")
await page.evaluate(async (fixture) => (await import(fixture)).mountTextViewer(40), fixture)
const root = page.getByTestId("file-viewer-fixture")
await expect(root.locator('[data-line="40"]')).toHaveCount(1)
// Script-dispatched mouse events leave no text selection, as a drag over trailing whitespace can.
await page.evaluate(
async (fixture) =>
(await import(fixture)).controls.gesture([
["mousedown", 3],
["mousemove", 6],
["mouseup", 6],
]),
fixture,
)
await expect(root.locator("[data-line][data-selected-line]")).toHaveCount(4)
await add.click()
await expect
.poll(() => page.evaluate(async (fixture) => (await import(fixture)).controls.ends(), fixture))
.toEqual([{ start: 3, end: 6 }])
})
story("does not end a drag that a fast second press replaced", async ({ mount, page }) => {
await mount("components-markdown--compact-result")
await page.evaluate(async (fixture) => (await import(fixture)).mountTextViewer(40), fixture)
const root = page.getByTestId("file-viewer-fixture")
await expect(root.locator('[data-line="40"]')).toHaveCount(1)
const ends = () => page.evaluate(async (fixture) => (await import(fixture)).controls.ends(), fixture)
// The second press lands before the first drag's finishing frame runs.
await page.evaluate(
async (fixture) =>
(await import(fixture)).controls.gesture([
["mousedown", 2],
["mousemove", 5],
["mouseup", 5],
["mousedown", 10],
["mousemove", 12],
]),
fixture,
)
await expect(root.locator("[data-line][data-selected-line]")).toHaveCount(3)
await page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))))
expect(await ends()).toEqual([])
await page.evaluate(async (fixture) => (await import(fixture)).controls.gesture([["mouseup", 12]]), fixture)
await expect.poll(ends).toEqual([{ start: 10, end: 12 }])
.poll(() => page.evaluate(async (fixture) => (await import(fixture)).controls.comments(), fixture))
.toEqual([
{ start: 3, end: 3 },
{ start: 8, end: 9 },
])
})
story("releases the pinned height when a diff becomes empty", async ({ mount, page }) => {
@@ -1,10 +1,26 @@
import { expect, story } from "../../stories/playwright/story"
// Moved from packages/app/e2e/regression/review-line-comment.spec.ts
story("opens the comment editor when code is clicked", async ({ mount }) => {
// Selecting text to copy it used to open the comment editor and move focus into it.
story("selected code offers Add comment instead of opening the editor", async ({ mount, page }) => {
const root = await mount("components-session-review--interactive-comments")
const review = root.locator('[data-component="session-review"]')
await review.locator('[data-line-type="change-addition"] [data-diff-span]').click()
const code = review.locator('[data-line-type="change-addition"] [data-diff-span]')
const add = page.getByRole("toolbar", { name: "Selection actions" }).getByRole("button", { name: "Add comment" })
await code.click()
const box = await code.boundingBox()
if (!box) throw new Error("the added line has no layout")
await page.mouse.move(box.x + 1, box.y + box.height / 2)
await page.mouse.down()
await page.mouse.move(box.x + box.width - 1, box.y + box.height / 2, { steps: 4 })
await page.mouse.up()
await expect(add).toBeVisible()
await expect(review.getByRole("textbox")).toHaveCount(0)
await expect(review.locator("[data-selected-line]")).toHaveCount(0)
await add.click()
await expect(add).toHaveCount(0)
await expect(review.getByRole("textbox")).toBeVisible()
await expect(review.locator('[data-slot="line-comment-editor-label"]')).toHaveText("Commenting on line 2")
})
@@ -49,13 +65,40 @@ story("shows a comment button when a diff line is hovered", async ({ mount }) =>
await expect(review.locator('[data-slot="line-comment-editor-label"]')).toHaveText("Commenting on line 1")
})
story("dragging the comment button down the gutter comments on every line it covers", async ({ mount, page }) => {
const root = await mount("components-session-review--interactive-comments")
const review = root.locator('[data-component="session-review"]')
const comment = review.getByRole("button", { name: "Comment", exact: true, includeHidden: true })
await review.getByText("export const first = 1", { exact: true }).hover()
await expect(comment).toBeVisible()
const from = await comment.boundingBox()
const to = await review.locator('[data-column-number="3"]').boundingBox()
if (!from || !to) throw new Error("the comment button or line 3 has no layout")
await page.mouse.move(from.x + from.width / 2, from.y + from.height / 2)
await page.mouse.down()
await page.mouse.move(to.x + to.width / 2, to.y + to.height / 2, { steps: 4 })
await page.mouse.up()
await expect(review.locator('[data-slot="line-comment-editor-label"]')).toHaveText("Commenting on lines 1-3")
// The button sits on the range's last line; a click on it used to start a new selection from that line alone.
await review.locator('[data-column-number="3"]').hover()
const button = await review.locator('button[aria-label="Comment"]').boundingBox()
if (!button) throw new Error("the comment button has no layout")
await page.mouse.click(button.x + button.width / 2, button.y + button.height / 2)
await page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))))
await expect(review.locator('[data-slot="line-comment-editor-label"]')).toHaveText("Commenting on lines 1-3")
})
story("keeps typed comment text while other lines and comments are used", async ({ mount, page }) => {
const root = await mount("components-session-review--interactive-comments")
const review = root.locator('[data-component="session-review"]')
const textbox = review.getByRole("textbox")
const firstLine = review.getByText("export const first = 1", { exact: true })
await review.locator('[data-line-type="change-addition"] [data-diff-span]').click()
await review.locator('[data-line-type="change-addition"][data-column-number="2"]').click()
await textbox.fill("first comment")
await textbox.press("Enter")
await expect(review.getByText("first comment", { exact: true })).toBeVisible()
@@ -66,7 +109,7 @@ story("keeps typed comment text while other lines and comments are used", async
await expect(textbox).toHaveValue("first comment")
await textbox.fill("edited comment")
// A click on another line keeps the edit, and the highlight returns to the edited line.
await firstLine.click()
await review.locator('[data-column-number="1"]').click()
await expect(textbox).toHaveValue("edited comment")
await expect(review.locator('[data-column-number="1"]')).not.toHaveAttribute("data-selected-line")
await firstLine.hover()
@@ -77,7 +120,7 @@ story("keeps typed comment text while other lines and comments are used", async
await expect(review.getByText("edited comment", { exact: true })).toBeVisible()
// Deleting a comment used to discard the draft on another line.
await firstLine.click()
await review.locator('[data-column-number="1"]').click()
await expect(review.locator('[data-slot="line-comment-editor-label"]')).toHaveText("Commenting on line 1")
await textbox.fill("draft text")
await review.getByRole("button", { name: "More options" }).click()
@@ -92,7 +135,7 @@ story("mentions in a diff comment pick a path, and Escape without a list cancels
const textbox = review.getByRole("textbox")
const items = review.locator('[data-slot="line-comment-mention-item"]')
await review.locator('[data-line-type="change-addition"] [data-diff-span]').click()
await review.locator('[data-line-type="change-addition"][data-column-number="2"]').click()
await textbox.pressSequentially("see @rev")
await expect(items).toHaveCount(2)
await textbox.press("ArrowDown")
@@ -0,0 +1,146 @@
import type { SelectedLineRange } from "@pierre/diffs"
import { createMemo, createSignal, onCleanup, Show, untrack } from "solid-js"
import { Portal } from "solid-js/web"
import { makeEventListener } from "@solid-primitives/event-listener"
import { createMediaQuery } from "@solid-primitives/media"
import { createResizeObserver } from "@solid-primitives/resize-observer"
import { Button } from "@opencode/ui/button"
import { useI18n } from "@opencode/ui/context/i18n"
import {
createCommentSelectionState,
selectCommentSelectionToolbar,
transitionCommentSelection,
type CommentSelectionEffect,
type CommentSelectionEvent,
type CommentSelectionSample,
} from "../pierre/comment-selection-machine"
const RELEASED: CommentSelectionEvent = Object.freeze({ type: "pointer.released" })
const CHANGED: CommentSelectionEvent = Object.freeze({ type: "selection.changed" })
const MOVED: CommentSelectionEvent = Object.freeze({ type: "layout.changed" })
/** Offers to comment on text selected in a file or diff viewer, like the timeline's Quote button. */
export function FileCommentSelection(props: {
wrapper: HTMLElement
sample: () => CommentSelectionSample | undefined
onComment: (range: SelectedLineRange) => void
}) {
const i18n = useI18n()
const [state, setState] = createSignal(createCommentSelectionState())
let element: HTMLElement | undefined
let settleTimer: ReturnType<typeof setTimeout> | undefined
let placeFrame: number | undefined
const run = (effect: CommentSelectionEffect) => {
if (effect.type === "schedule-settle") {
clearTimeout(settleTimer)
settleTimer = setTimeout(() => {
settleTimer = undefined
dispatch({ type: "settle.sampled", attempt: effect.attempt, sample: props.sample() })
}, effect.delayMs)
return
}
if (effect.type === "cancel-settle") {
clearTimeout(settleTimer)
settleTimer = undefined
return
}
if (effect.type === "schedule-place") {
if (placeFrame !== undefined) cancelAnimationFrame(placeFrame)
placeFrame = requestAnimationFrame(() => {
placeFrame = undefined
dispatch({ type: "place.sampled", attempt: effect.attempt, sample: props.sample() })
})
return
}
if (effect.type === "cancel-place") {
if (placeFrame !== undefined) cancelAnimationFrame(placeFrame)
placeFrame = undefined
return
}
if (effect.type === "clear-selection") return window.getSelection()?.removeAllRanges()
props.onComment(effect.range)
}
const dispatch = (event: CommentSelectionEvent) =>
untrack(() => {
const step = transitionCommentSelection(state(), event)
if (step.state !== state()) setState(step.state)
step.effects.forEach(run)
})
// Touch screens show their own menu over the selection.
const docked = createMediaQuery("(hover: none)")
const toolbar = createMemo(() => selectCommentSelectionToolbar(state(), docked()))
const inside = (target: EventTarget | null) => target instanceof Node && !!element?.contains(target)
makeEventListener(document, "pointerdown", (event) => {
if (inside(event.target)) return
dispatch({ type: "pointer.down", button: event.button, inside: event.composedPath().includes(props.wrapper) })
})
// A cancelled touch, a long-press or Ctrl+click menu, or leaving the window can end a press without `pointerup`.
makeEventListener(document, "pointerup", () => dispatch(RELEASED))
makeEventListener(document, "pointercancel", () => dispatch(RELEASED))
makeEventListener(document, "contextmenu", () => dispatch(RELEASED))
makeEventListener(window, "blur", () => dispatch(RELEASED))
makeEventListener(document, "selectionchange", () => dispatch(CHANGED))
makeEventListener(document, "keydown", (event) => {
if (event.key === "Escape" && !event.defaultPrevented) dispatch({ type: "escape" })
})
makeEventListener(document, "scroll", () => dispatch(MOVED), { capture: true, passive: true })
makeEventListener(window, "resize", () => dispatch(MOVED))
createResizeObserver(
() => props.wrapper,
() => dispatch(MOVED),
)
onCleanup(() => dispatch({ type: "disposed" }))
return (
<Show when={toolbar()}>
{(view) => (
<Portal>
<div
ref={(value) => {
element = value
createResizeObserver(value, () =>
dispatch({ type: "toolbar.measured", size: { width: value.offsetWidth, height: value.offsetHeight } }),
)
onCleanup(() => {
element = undefined
})
}}
data-component="file-comment-selection"
data-prevent-autofocus
role="toolbar"
aria-label={i18n.t("ui.lineComment.actions")}
class="fixed z-50 flex items-center gap-0.5 rounded-[8px] p-0.5 shadow-[var(--v2-elevation-raised)]"
style={{
top: `${view().place.top}px`,
left: `${view().place.left}px`,
visibility: view().measured ? undefined : "hidden",
}}
onMouseDown={(event) => event.preventDefault()}
>
<Button size="small" variant="ghost" icon="comment" onClick={() => dispatch({ type: "comment.added" })}>
{i18n.t("ui.lineComment.add")}
</Button>
</div>
</Portal>
)}
</Show>
)
}
@@ -44,3 +44,11 @@
}
}
}
[data-component="file-comment-selection"] {
background-color: var(--v2-background-bg-base);
}
[data-color-scheme="dark"] [data-component="file-comment-selection"] {
background-color: var(--v2-background-bg-layer-02);
}
+133 -105
View File
@@ -58,19 +58,18 @@ import {
type ViewerRenderRequest,
type ViewerTarget,
} from "../pierre/render-machine"
import { restoreShadowTextSelection } from "../pierre/selection-bridge"
import {
createFileSelectionState,
selectPointerTracking,
selectSelectedRange,
selectTextSelectionTracking,
transitionFileSelection,
type FileSelectionEffect,
type FileSelectionEvent,
type FileSelectionMode,
} from "../pierre/selection-machine"
import type { CommentSelectionSample } from "../pierre/comment-selection-machine"
import { acquireVirtualizer, virtualizeLineThreshold, virtualMetrics } from "../pierre/virtualizer"
import { getWorkerPool } from "../pierre/worker"
import { FileCommentSelection } from "./file-comment-selection"
import { FileMedia, type FileMediaOptions } from "./file-media"
import { FileSearchBar } from "./file-search"
@@ -85,6 +84,8 @@ type SharedProps<T> = {
selectedLines?: SelectedLineRange | null
commentedLines?: SelectedLineRange[]
onLineNumberSelectionEnd?: (selection: SelectedLineRange | null) => void
/** Offers an Add comment button on text selected in the code, and reports the lines it covers. */
onCommentSelection?: (range: SelectedLineRange) => void
onRendered?: () => void
class?: string
classList?: ComponentProps<"div">["classList"]
@@ -146,6 +147,7 @@ const sharedKeys = [
"onLineSelected",
"onLineSelectionEnd",
"onLineNumberSelectionEnd",
"onCommentSelection",
"onRendered",
"preloadedDiff",
] as const
@@ -171,7 +173,6 @@ type SelectionCallbacks = {
}
type ViewerConfig = {
mode: FileSelectionMode
enableLineSelection: () => boolean
selectedLines: () => SelectedLineRange | null | undefined
callbacks: SelectionCallbacks
@@ -191,25 +192,20 @@ type PointerMove = {
type: "pointer.move"
buttons: number
line: number | undefined
side: DiffSelectionSide | undefined
}
const POINTER_UP: FileSelectionEvent = Object.freeze({ type: "pointer.up" })
const SELECTION_CHANGED: FileSelectionEvent = Object.freeze({ type: "selection.changed" })
const POINTER_CANCELLED: FileSelectionEvent = Object.freeze({ type: "pointer.cancelled" })
function useFileViewer(config: ViewerConfig) {
let wrapper!: HTMLDivElement
let container!: HTMLDivElement
let overlay!: HTMLDivElement
let selection = createFileSelectionState(config.mode)
let dragFrame: number | undefined
let selectionFrame: number | undefined
let finishFrame: number | undefined
let shadowText: { root: ShadowRoot; text: Range } | undefined
let selection = createFileSelectionState()
// Pointer moves reuse one hit and one event so hovering and dragging allocate nothing per move.
const hit: MouseHit = { line: undefined, numberColumn: false, side: undefined }
const moveEvent: PointerMove = { type: "pointer.move", buttons: 0, line: undefined, side: undefined }
const moveEvent: PointerMove = { type: "pointer.move", buttons: 0, line: undefined }
const getRoot = () => getViewerRoot(container)
const getHost = () => getViewerHost(container)
@@ -222,79 +218,8 @@ function useFileViewer(config: ViewerConfig) {
// -- selection machine --
const readSelection = (preserveTextSelection: boolean) => {
const root = getRoot()
if (!root) return
const selected = readShadowLineSelection({
root,
lineForNode: config.lineForNode,
sideForNode: config.sideForNode,
preserveTextSelection,
})
if (!selected) return
return { root, range: selected.range, text: selected.text }
}
const cancelFrames = () => {
if (dragFrame !== undefined) cancelAnimationFrame(dragFrame)
if (selectionFrame !== undefined) cancelAnimationFrame(selectionFrame)
if (finishFrame !== undefined) cancelAnimationFrame(finishFrame)
dragFrame = undefined
selectionFrame = undefined
finishFrame = undefined
shadowText = undefined
}
const run = (effect: FileSelectionEffect) => {
if (effect.type === "cancel-frames") return cancelFrames()
if (effect.type === "schedule-drag") {
if (dragFrame !== undefined) return
dragFrame = requestAnimationFrame(() => {
dragFrame = undefined
dispatch({ type: "drag.frame", attempt: effect.attempt })
})
return
}
if (effect.type === "schedule-selection") {
if (selectionFrame !== undefined) return
selectionFrame = requestAnimationFrame(() => {
selectionFrame = undefined
const selected = readSelection(false)
if (selected) dispatch({ type: "selection.frame", attempt: effect.attempt, range: selected.range })
})
return
}
if (effect.type === "schedule-finish") {
finishFrame = requestAnimationFrame(() => {
finishFrame = undefined
const selected = readSelection(true)
shadowText = selected?.text ? { root: selected.root, text: selected.text } : undefined
dispatch({ type: "finish.frame", attempt: effect.attempt, range: selected?.range })
})
return
}
if (effect.type === "apply-selection") {
const text = effect.preserveText ? shadowText : undefined
shadowText = undefined
config.applySelection(effect.range)
restoreShadowTextSelection(text?.root, text?.text)
return
}
if (effect.type === "apply-selection") return config.applySelection(effect.range)
if (effect.type === "notify-line-selected") return config.callbacks.onLineSelected?.(effect.range)
@@ -319,9 +244,9 @@ function useFileViewer(config: ViewerConfig) {
return next === undefined ? range : next
}
// -- mouse handlers --
// -- pointer handlers --
const handleMouseDown = (event: MouseEvent) => {
const handlePointerDown = (event: PointerEvent) => {
if (event.button !== 0) return
fillMouseHit(hit, event, config.lineForElement, config.sideForElement)
dispatch({
@@ -330,35 +255,31 @@ function useFileViewer(config: ViewerConfig) {
column: hit.numberColumn ? "numbers" : "text",
line: hit.line,
side: hit.side,
touch: event.pointerType === "touch",
})
}
const handleMouseMove = (event: MouseEvent) => {
const handlePointerMove = (event: PointerEvent) => {
if (!selectPointerTracking(selection)) return
moveEvent.buttons = event.buttons
moveEvent.line = undefined
moveEvent.side = undefined
if ((event.buttons & 1) !== 0) {
fillMouseHit(hit, event, config.lineForElement, config.sideForElement)
fillMouseHit(hit, event, config.lineForElement)
moveEvent.line = hit.line
moveEvent.side = hit.side
}
dispatch(moveEvent)
}
const handleMouseUp = () => {
const handlePointerUp = () => {
if (!selectPointerTracking(selection)) return
dispatch(POINTER_UP)
}
const handleSelectionChange = () => {
if (!selectTextSelectionTracking(selection)) return
const current = window.getSelection()
if (!current || current.isCollapsed) return
dispatch(SELECTION_CHANGED)
const handlePointerCancel = () => {
if (!selectPointerTracking(selection)) return
dispatch(POINTER_CANCELLED)
}
// -- shared effects --
@@ -379,10 +300,10 @@ function useFileViewer(config: ViewerConfig) {
return
}
makeEventListener(container, "mousedown", handleMouseDown)
makeEventListener(container, "mousemove", handleMouseMove)
makeEventListener(window, "mouseup", handleMouseUp)
makeEventListener(document, "selectionchange", handleSelectionChange)
makeEventListener(container, "pointerdown", handlePointerDown)
makeEventListener(container, "pointermove", handlePointerMove)
makeEventListener(window, "pointerup", handlePointerUp)
makeEventListener(window, "pointercancel", handlePointerCancel)
})
onCleanup(() => dispatch({ type: "disposed" }))
@@ -409,6 +330,31 @@ function useFileViewer(config: ViewerConfig) {
getRoot,
getHost,
find,
/** The text selected in the code, as the lines it covers and where it sits on screen. */
sampleTextSelection: (): CommentSelectionSample | undefined => {
const root = getRoot()
if (!root || !wrapper) return
const selected = readShadowLineSelection({
root,
lineForNode: config.lineForNode,
sideForNode: config.sideForNode,
})
const range = selected && normalize(selected.range)
if (!selected || !range) return
const bounds = visibleBounds(wrapper)
const anchor = selectionAnchor(selected.text, selected.backward)
return {
range,
bounds,
anchor: anchor && anchor.bottom > bounds.top && anchor.top < bounds.bottom ? anchor : undefined,
}
},
/** Shows the current range again once Pierre has drawn fresh rows. */
reapplySelection: () => config.applySelection(selectSelectedRange(selection)),
/** Pierre's own line-number selection, passed in its options. */
@@ -854,6 +800,64 @@ function fillMouseHit(
}
}
/** The part of `el` left on screen by the window and every ancestor that clips it. */
function visibleBounds(el: HTMLElement) {
const box = el.getBoundingClientRect()
const bounds = {
top: Math.max(box.top, 0),
bottom: Math.min(box.bottom, window.innerHeight),
left: box.left,
right: box.right,
}
for (let parent = el.parentElement; parent; parent = parent.parentElement) {
if (getComputedStyle(parent).overflowY === "visible") continue
const clip = parent.getBoundingClientRect()
bounds.top = Math.max(bounds.top, clip.top)
bounds.bottom = Math.min(bounds.bottom, clip.bottom)
bounds.left = Math.max(bounds.left, clip.left)
bounds.right = Math.min(bounds.right, clip.right)
}
return bounds
}
/** The selected text's box, from its first and last glyphs rather than the line boxes the range also covers. */
function selectionAnchor(range: Range, backward: boolean) {
const first = edgeRect(range, false)
const last = edgeRect(range, true)
if (!first || !last) return
return {
top: first.top,
bottom: last.bottom,
start: first.left,
end: last.right,
single: last.top < first.bottom - first.height / 2,
backward,
}
}
function edgeRect(range: Range, end: boolean) {
const node = end ? range.endContainer : range.startContainer
const offset = end ? range.endOffset : range.startOffset
if (node instanceof Text) {
const glyph = new Range()
glyph.setStart(node, end ? Math.max(0, offset - 1) : offset)
glyph.setEnd(node, end ? offset : Math.min(node.length, offset + 1))
const rect = glyph.getBoundingClientRect()
if (rect.height > 0) return rect
}
const rects = [...range.getClientRects()].filter((rect) => rect.height > 0)
return end ? rects.at(-1) : rects[0]
}
function diffMouseSide(node: HTMLElement) {
const type = node.dataset.lineType
@@ -883,6 +887,7 @@ function ViewerShell(props: {
viewer: ReturnType<typeof useFileViewer>
class: string | undefined
classList: ComponentProps<"div">["classList"] | undefined
onCommentSelection: ((range: SelectedLineRange) => void) | undefined
}) {
return (
<div
@@ -916,6 +921,15 @@ function ViewerShell(props: {
</Show>
<div ref={(el) => (props.viewer.container = el)} />
<div ref={(el) => (props.viewer.overlay = el)} class="pointer-events-none absolute inset-0 z-0" />
<Show when={props.onCommentSelection}>
{(onComment) => (
<FileCommentSelection
wrapper={props.viewer.wrapper}
sample={props.viewer.sampleTextSelection}
onComment={(range) => onComment()(range)}
/>
)}
</Show>
</div>
)
}
@@ -981,7 +995,6 @@ function TextViewer<T>(props: TextFileProps<T>) {
}
viewer = useFileViewer({
mode: "text",
enableLineSelection: () => props.enableLineSelection === true,
selectedLines: () => local.selectedLines,
callbacks: local,
@@ -1054,7 +1067,15 @@ function TextViewer<T>(props: TextFileProps<T>) {
onRendered: () => local.onRendered?.(),
})
return <ViewerShell mode="text" viewer={viewer} class={local.class} classList={local.classList} />
return (
<ViewerShell
mode="text"
viewer={viewer}
class={local.class}
classList={local.classList}
onCommentSelection={local.onCommentSelection}
/>
)
}
// ---------------------------------------------------------------------------
@@ -1086,7 +1107,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
}
viewer = useFileViewer({
mode: "diff",
enableLineSelection: () => props.enableLineSelection === true,
selectedLines: () => local.selectedLines,
callbacks: local,
@@ -1254,7 +1274,15 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
),
)
return <ViewerShell mode="diff" viewer={viewer} class={local.class} classList={local.classList} />
return (
<ViewerShell
mode="diff"
viewer={viewer}
class={local.class}
classList={local.classList}
onCommentSelection={local.onCommentSelection}
/>
)
}
// ---------------------------------------------------------------------------
@@ -285,6 +285,7 @@ type LineCommentController<T extends SavedLineComment, A> = {
renderGutterUtility: ReturnType<typeof createLineCommentGutterRenderer>
onLineSelected: (range: SelectedLineRange | null) => void
onLineSelectionEnd: (range: SelectedLineRange | null) => void
commentSelection: Accessor<((range: SelectedLineRange) => void) | undefined>
}
export function createLineCommentController<T extends SavedLineComment>(
@@ -387,6 +388,11 @@ export function createLineCommentController<T extends SavedLineComment>(
}),
onLineSelected: (range: SelectedLineRange | null) => driver.send({ type: "line.selected", range }),
onLineSelectionEnd: (range: SelectedLineRange | null) => driver.send({ type: "line.selection-ended", range }),
/** Opens a draft on text selected in the code. Unset while a saved comment is edited, which keeps its range. */
commentSelection: () =>
driver.mode().status === "editing"
? undefined
: (range: SelectedLineRange) => driver.send({ type: "draft.opened", range }),
}
}
@@ -546,6 +552,7 @@ export function createLineCommentGutterRenderer(props: {
const comment = createHoverComment({
label: props.label,
getHoveredLine,
isSelected: (hovered) => lineInSelectedRange(props.getSelectedRange(), hovered.lineNumber, hovered.side),
onSelect: (hovered) => {
const current = props.getSelectedRange()
@@ -703,6 +703,7 @@ export const SessionReview = (props: SessionReviewProps) => {
renderGutterUtility={
props.onLineComment ? commentsUi.renderGutterUtility : undefined
}
onCommentSelection={props.onLineComment ? commentsUi.commentSelection() : undefined}
selectedLines={commentsUi.selected()}
commentedLines={commentedLines()}
media={{
@@ -22,6 +22,8 @@ export function createHoverComment(props: {
label: string
getHoveredLine: () => HoverCommentLine | undefined
onSelect: (line: HoverCommentLine) => void
/** Whether the line is in the selected range, which a click comments on as a whole rather than starting a new one. */
isSelected: (line: HoverCommentLine) => boolean
}): HoverComment | undefined {
if (typeof document === "undefined") return
@@ -48,16 +50,20 @@ export function createHoverComment(props: {
button.style.justifyContent = "center"
button.style.border = "none"
button.style.borderRadius = "var(--radius-md)"
button.style.background = "var(--icon-interactive-base)"
button.style.color = "var(--white)"
button.style.background = "var(--v2-background-bg-inverse)"
button.style.color = "var(--v2-icon-icon-inverse)"
button.style.boxShadow = "var(--shadow-xs)"
button.style.padding = "0"
button.style.cursor = "pointer"
button.style.position = "relative"
button.style.left = "30px"
// It overlaps the line number, which Pierre stacks at 1; Pierre's own gutter button uses 4.
button.style.zIndex = "4"
button.style.left = "-4px"
button.style.top = "calc((var(--diffs-line-height, 24px) - 20px) / 2)"
let state = INITIAL_HOVER_COMMENT_STATE
// Whether the last press went to Pierre, which then opens the draft itself.
let forwarded = false
// Reused for every pointer move and scroll so tracking allocates nothing.
const syncEvent: HoverCommentSync = { type: "hover.synced", lineNumber: undefined, side: undefined }
@@ -88,10 +94,19 @@ export function createHoverComment(props: {
document.addEventListener("scroll", sync, { passive: true, capture: true })
button.addEventListener("mouseenter", sync)
button.addEventListener("mousemove", sync)
// Pierre skips presses on a custom gutter button when it selects lines, so hand the press to the line number under
// the button: dragging from it then selects lines and ends in a draft for them. On a line that is already selected
// the press stays here, as Pierre would unselect or shrink the range, and the click comments on the whole range.
button.addEventListener("pointerdown", (event) => {
event.preventDefault()
event.stopPropagation()
sync()
const line = selectHoverLine(state)
forwarded = !line || !props.isSelected(line)
if (!forwarded) return
const slot = button.assignedSlot ?? button.parentElement?.assignedSlot
slot?.closest("[data-column-number]")?.dispatchEvent(new PointerEvent("pointerdown", event))
})
button.addEventListener("mousedown", (event) => {
event.preventDefault()
@@ -104,7 +119,8 @@ export function createHoverComment(props: {
sync()
const line = selectHoverLine(state)
if (line) props.onSelect(line)
// A keyboard press has no pointer, so it never went to Pierre.
if (line && (event.detail === 0 || !forwarded)) props.onSelect(line)
})
return {
@@ -0,0 +1,182 @@
import { describe, expect, test } from "bun:test"
import {
COMMENT_SELECTION_SETTLE_MS,
createCommentSelectionState,
selectCommentSelectionToolbar,
transitionCommentSelection,
type CommentSelectionEvent,
type CommentSelectionSample,
type CommentSelectionState,
type CommentSelectionTransition,
} from "./comment-selection-machine"
const BOUNDS = { top: 0, bottom: 400, left: 0, right: 600 }
const SAMPLE: CommentSelectionSample = {
range: { start: 3, end: 5 },
bounds: BOUNDS,
anchor: { top: 100, bottom: 160, start: 40, end: 300, single: false, backward: false },
}
const SIZE = { width: 120, height: 28 }
const replay = (
events: readonly CommentSelectionEvent[],
state: CommentSelectionState = createCommentSelectionState(),
) =>
events.reduce<CommentSelectionTransition>((last, event) => transitionCommentSelection(last.state, event), {
state,
effects: [],
})
const press = (inside = true, button = 0): CommentSelectionEvent => ({ type: "pointer.down", button, inside })
const released: CommentSelectionEvent = { type: "pointer.released" }
const changed: CommentSelectionEvent = { type: "selection.changed" }
const settled = (attempt: number, sample: CommentSelectionSample = SAMPLE): CommentSelectionEvent => ({
type: "settle.sampled",
attempt,
sample,
})
const nothing = (attempt: number): CommentSelectionEvent => ({ type: "settle.sampled", attempt, sample: undefined })
const measured: CommentSelectionEvent = { type: "toolbar.measured", size: SIZE }
describe("comment selection toolbar", () => {
test("a drag over the code offers the toolbar once the release settles", () => {
const dragging = replay([press(), changed, changed])
expect(dragging.state.status).toBe("pressing")
expect(dragging.effects).toEqual([])
const releasing = transitionCommentSelection(dragging.state, released)
expect(releasing.effects).toEqual([{ type: "schedule-settle", attempt: 1, delayMs: COMMENT_SELECTION_SETTLE_MS }])
expect(selectCommentSelectionToolbar(releasing.state)).toBeUndefined()
const shown = replay([settled(1), measured], releasing.state)
expect(selectCommentSelectionToolbar(shown.state)).toEqual({ place: { top: 168, left: 240 }, measured: true })
})
test("a click that leaves nothing selected offers nothing", () => {
const step = replay([press(), released, nothing(1)])
expect(step.state).toEqual({ status: "idle", issued: 1 })
expect(selectCommentSelectionToolbar(step.state)).toBeUndefined()
})
test("a selection made outside the viewer schedules no work", () => {
const step = replay([press(false), changed, released])
expect(step.state.status).toBe("idle")
expect(step.effects).toEqual([])
})
test("a new press drops the previous release's pending read", () => {
const pressed = replay([press(), released, press()])
expect(pressed.effects).toEqual([{ type: "cancel-settle" }])
const stale = transitionCommentSelection(pressed.state, settled(1))
expect(stale.state).toBe(pressed.state)
})
test("a press elsewhere closes the toolbar", () => {
const step = replay([press(), released, settled(1), press(false)])
expect(step.state.status).toBe("idle")
expect(selectCommentSelectionToolbar(step.state)).toBeUndefined()
})
test("a secondary press keeps the toolbar, so a context menu can copy the text", () => {
const shown = replay([press(), released, settled(1)])
expect(transitionCommentSelection(shown.state, press(true, 2)).state).toBe(shown.state)
})
test("Add comment opens a draft on the selected lines and clears the text selection", () => {
const step = replay([press(), released, settled(1), { type: "comment.added" }])
expect(step.state.status).toBe("idle")
expect(step.effects).toEqual([{ type: "clear-selection" }, { type: "open-draft", range: { start: 3, end: 5 } }])
})
test("Escape closes the toolbar and keeps the text selected", () => {
const step = replay([press(), released, settled(1), { type: "escape" }])
expect(step.state.status).toBe("idle")
expect(step.effects).toEqual([])
})
test("a changed selection hides the toolbar until it settles again", () => {
const changing = replay([press(), released, settled(1), changed])
expect(selectCommentSelectionToolbar(changing.state)).toBeUndefined()
expect(changing.effects).toEqual([{ type: "schedule-settle", attempt: 2, delayMs: COMMENT_SELECTION_SETTLE_MS }])
const cleared = transitionCommentSelection(changing.state, nothing(2))
expect(cleared.state.status).toBe("idle")
})
test("scrolling places the toolbar once per frame and hides it while the selection is out of view", () => {
const shown = replay([press(), released, settled(1), measured])
const scrolled = replay([{ type: "layout.changed" }, { type: "layout.changed" }], shown.state)
expect(transitionCommentSelection(shown.state, { type: "layout.changed" }).effects).toEqual([
{ type: "schedule-place", attempt: 2 },
])
expect(scrolled.effects).toEqual([])
const away = transitionCommentSelection(scrolled.state, {
type: "place.sampled",
attempt: 2,
sample: { ...SAMPLE, anchor: undefined },
})
expect(away.state.status).toBe("shown")
expect(selectCommentSelectionToolbar(away.state)).toBeUndefined()
const gone = replay(
[{ type: "layout.changed" }, { type: "place.sampled", attempt: 3, sample: undefined }],
away.state,
)
expect(gone.state.status).toBe("idle")
})
test("disposing cancels pending work and ignores later events", () => {
const disposed = replay([press(), released, { type: "disposed" }])
expect(disposed.effects).toEqual([{ type: "cancel-settle" }])
expect(transitionCommentSelection(disposed.state, settled(1)).state).toBe(disposed.state)
})
})
describe("comment selection toolbar position", () => {
const place = (anchor: Partial<NonNullable<CommentSelectionSample["anchor"]>>, bounds = BOUNDS) =>
selectCommentSelectionToolbar(
replay([press(), released, settled(1, { ...SAMPLE, bounds, anchor: { ...SAMPLE.anchor!, ...anchor } }), measured])
.state,
)?.place
test("sits centered above a one-line selection", () => {
expect(place({ single: true, top: 100, bottom: 120, start: 100, end: 200 })).toEqual({ top: 64, left: 90 })
})
test("sits above the start of a selection dragged upwards", () => {
expect(place({ backward: true })).toEqual({ top: 64, left: 8 })
})
test("flips to the other side when there is no room", () => {
expect(place({ top: 300, bottom: 380 })).toEqual({ top: 264, left: 240 })
expect(place({ single: true, top: 10, bottom: 30, start: 100, end: 200 })).toEqual({ top: 38, left: 90 })
})
test("docks centered at the viewer's bottom on touch screens, clear of their own selection menu", () => {
const shown = replay([press(), released, settled(1), measured]).state
expect(selectCommentSelectionToolbar(shown, true)?.place).toEqual({ top: 364, left: 240 })
})
test("pins to the viewer's bottom when neither side fits, and stays inside its edges", () => {
expect(place({ top: 20, bottom: 390, end: 590 })).toEqual({ top: 364, left: 472 })
expect(place({ end: 10 }, { ...BOUNDS, right: 100 })).toEqual({ top: 168, left: 8 })
})
})
@@ -0,0 +1,257 @@
import type { SelectedLineRange } from "@pierre/diffs"
/** How long a released selection waits unchanged before the toolbar reads it, as for the timeline's Quote. */
export const COMMENT_SELECTION_SETTLE_MS = 150
/** Space between the toolbar, the selection and the viewer's visible edges. */
export const COMMENT_SELECTION_GAP = 8
export type CommentSelectionRect = {
readonly top: number
readonly bottom: number
readonly left: number
readonly right: number
}
export type CommentSelectionSize = { readonly width: number; readonly height: number }
/** The selected text's box in viewport pixels. `start` is its first glyph's left edge, `end` its last glyph's right. */
export type CommentSelectionAnchor = {
readonly top: number
readonly bottom: number
readonly start: number
readonly end: number
readonly single: boolean
/** Dragged upwards, so the pointer rests at the start. */
readonly backward: boolean
}
/** The viewer's text selection, read in one frame. `anchor` is undefined while it is scrolled out of `bounds`. */
export type CommentSelectionSample = {
readonly range: SelectedLineRange
/** The part of the viewer that is on screen. */
readonly bounds: CommentSelectionRect
readonly anchor: CommentSelectionAnchor | undefined
}
/**
* The Add comment toolbar for text selected in a file or diff viewer. `pressing` is a primary press inside the viewer;
* its selection is read only after the release, once it has stayed unchanged for `COMMENT_SELECTION_SETTLE_MS` under
* `attempt`. `shown` offers a comment on `range`; `placeAttempt` names the queued placement frame.
*/
export type CommentSelectionState =
| { readonly status: "idle"; readonly issued: number }
| { readonly status: "pressing"; readonly issued: number }
| { readonly status: "settling"; readonly issued: number; readonly attempt: number }
| {
readonly status: "shown"
readonly issued: number
readonly range: SelectedLineRange
readonly bounds: CommentSelectionRect
readonly anchor: CommentSelectionAnchor | undefined
/** Zero until the toolbar is measured. */
readonly size: CommentSelectionSize
readonly placeAttempt: number | undefined
}
| { readonly status: "disposed" }
export type CommentSelectionEvent =
/** A press outside the toolbar; `inside` when it landed in this viewer. */
| { readonly type: "pointer.down"; readonly button: number; readonly inside: boolean }
/** `pointerup`, `pointercancel`, `contextmenu` or window `blur`: the press ended. */
| { readonly type: "pointer.released" }
| { readonly type: "selection.changed" }
/** `sample` is undefined when nothing in this viewer is selected. */
| { readonly type: "settle.sampled"; readonly attempt: number; readonly sample: CommentSelectionSample | undefined }
/** Something scrolled or resized. */
| { readonly type: "layout.changed" }
| { readonly type: "place.sampled"; readonly attempt: number; readonly sample: CommentSelectionSample | undefined }
| { readonly type: "toolbar.measured"; readonly size: CommentSelectionSize }
| { readonly type: "escape" }
| { readonly type: "comment.added" }
| { readonly type: "disposed" }
export type CommentSelectionEffect =
| { readonly type: "schedule-settle"; readonly attempt: number; readonly delayMs: number }
| { readonly type: "cancel-settle" }
| { readonly type: "schedule-place"; readonly attempt: number }
| { readonly type: "cancel-place" }
| { readonly type: "clear-selection" }
| { readonly type: "open-draft"; readonly range: SelectedLineRange }
export type CommentSelectionTransition = {
readonly state: CommentSelectionState
readonly effects: readonly CommentSelectionEffect[]
}
type Active = Exclude<CommentSelectionState, { status: "disposed" }>
const NONE: readonly never[] = []
const CANCEL_SETTLE: readonly CommentSelectionEffect[] = [{ type: "cancel-settle" }]
const CANCEL_PLACE: readonly CommentSelectionEffect[] = [{ type: "cancel-place" }]
const UNMEASURED: CommentSelectionSize = { width: 0, height: 0 }
export function createCommentSelectionState(): CommentSelectionState {
return { status: "idle", issued: 0 }
}
export function transitionCommentSelection(
state: CommentSelectionState,
event: CommentSelectionEvent,
): CommentSelectionTransition {
if (state.status === "disposed") return { state, effects: NONE }
if (event.type === "disposed") return { state: { status: "disposed" }, effects: cancel(state) }
if (event.type === "pointer.down") {
if (event.button !== 0) return { state, effects: NONE }
// A press elsewhere closes the toolbar; one in the viewer starts a selection that the release reads.
const status = event.inside ? "pressing" : "idle"
if (state.status === status) return { state, effects: NONE }
return { state: { status, issued: state.issued }, effects: cancel(state) }
}
if (event.type === "pointer.released") {
if (state.status !== "pressing") return { state, effects: NONE }
return settle(state, NONE)
}
if (event.type === "selection.changed") {
// A drag is read on release, and a selection made elsewhere is not this viewer's.
if (state.status !== "shown" && state.status !== "settling") return { state, effects: NONE }
return settle(state, cancel(state))
}
if (event.type === "settle.sampled") {
if (state.status !== "settling" || state.attempt !== event.attempt) return { state, effects: NONE }
if (!event.sample) return { state: { status: "idle", issued: state.issued }, effects: NONE }
return {
state: {
status: "shown",
issued: state.issued,
range: event.sample.range,
bounds: event.sample.bounds,
anchor: event.sample.anchor,
size: UNMEASURED,
placeAttempt: undefined,
},
effects: NONE,
}
}
if (event.type === "escape") {
if (state.status !== "shown" && state.status !== "settling") return { state, effects: NONE }
return { state: { status: "idle", issued: state.issued }, effects: cancel(state) }
}
if (state.status !== "shown") return { state, effects: NONE }
if (event.type === "layout.changed") {
// One frame places the toolbar for every scroll and resize before it.
if (state.placeAttempt !== undefined) return { state, effects: NONE }
const attempt = state.issued + 1
return {
state: { ...state, issued: attempt, placeAttempt: attempt },
effects: [{ type: "schedule-place", attempt }],
}
}
if (event.type === "place.sampled") {
if (state.placeAttempt !== event.attempt) return { state, effects: NONE }
// The selected rows left the viewer, such as when a virtualized diff dropped them.
if (!event.sample) return { state: { status: "idle", issued: state.issued }, effects: NONE }
return {
state: { ...state, bounds: event.sample.bounds, anchor: event.sample.anchor, placeAttempt: undefined },
effects: NONE,
}
}
if (event.type === "toolbar.measured") {
if (event.size.width === state.size.width && event.size.height === state.size.height)
return { state, effects: NONE }
return { state: { ...state, size: event.size }, effects: NONE }
}
return {
state: { status: "idle", issued: state.issued },
effects: [...cancel(state), { type: "clear-selection" }, { type: "open-draft", range: state.range }],
}
}
/**
* The toolbar's position, or undefined while it is closed or its selection is out of view. `docked` is for touch
* screens, which show their own menu over the selection.
*/
export function selectCommentSelectionToolbar(state: CommentSelectionState, docked = false) {
if (state.status !== "shown" || !state.anchor) return
return {
place: commentSelectionPosition(state.size, state.bounds, state.anchor, docked),
measured: state.size.height !== 0,
}
}
/**
* Like the terminal's Quote: a one-line selection gets the toolbar centered above it, a taller one gets it beside the
* end the pointer stopped at, below a downward drag and above an upward one.
*/
export function commentSelectionPosition(
size: CommentSelectionSize,
bounds: CommentSelectionRect,
anchor: CommentSelectionAnchor,
docked: boolean,
) {
const gap = COMMENT_SELECTION_GAP
const pinned = bounds.bottom - size.height - gap
if (docked) return { top: pinned, left: (bounds.left + bounds.right - size.width) / 2 }
const above = anchor.top - size.height - gap
const below = anchor.bottom + gap
const fitsAbove = above >= bounds.top + gap && anchor.top <= bounds.bottom
const fitsBelow = below + size.height <= bounds.bottom - gap && anchor.bottom >= bounds.top
const prefersAbove = anchor.single || anchor.backward
const sides = prefersAbove ? [fitsAbove && above, fitsBelow && below] : [fitsBelow && below, fitsAbove && above]
const top = sides.find((side) => side !== false)
const center = anchor.single
? (anchor.start + anchor.end - size.width) / 2
: (anchor.backward ? anchor.start : anchor.end) - size.width / 2
return {
top: top ?? pinned,
// A viewer narrower than the toolbar pins it to the left edge instead of past it.
left: Math.max(bounds.left + gap, Math.min(center, bounds.right - size.width - gap)),
}
}
function settle(state: Active, effects: readonly CommentSelectionEffect[]): CommentSelectionTransition {
const attempt = state.issued + 1
return {
state: { status: "settling", issued: attempt, attempt },
effects: [...effects, { type: "schedule-settle", attempt, delayMs: COMMENT_SELECTION_SETTLE_MS }],
}
}
function cancel(state: Active): readonly CommentSelectionEffect[] {
if (state.status === "settling") return CANCEL_SETTLE
if (state.status === "shown" && state.placeAttempt !== undefined) return CANCEL_PLACE
return NONE
}
@@ -57,31 +57,37 @@ export function findCodeSelectionSide(node: Node | null): SelectedLineRange["sid
return "additions"
}
type ComposedSelection = {
getComposedRanges?: (options?: { shadowRoots?: ShadowRoot[] }) => StaticRange[]
direction?: string
}
/** The lines under the browser's text selection in a viewer's shadow root, with the selected text's DOM range. */
export function readShadowLineSelection(opts: {
root: ShadowRoot
lineForNode: (node: Node | null) => number | undefined
sideForNode?: (node: Node | null) => SelectedLineRange["side"]
preserveTextSelection?: boolean
}) {
const selection =
(opts.root as unknown as { getSelection?: () => Selection | null }).getSelection?.() ?? window.getSelection()
// Chromium exposes `getSelection` on shadow roots and `getComposedRanges` on selections; the DOM types do not list them.
const root: ShadowRoot & { getSelection?: () => Selection | null } = opts.root
const selection: (Selection & ComposedSelection) | null = root.getSelection?.() ?? window.getSelection()
if (!selection || selection.isCollapsed) return
const domRange =
(
selection as unknown as {
getComposedRanges?: (options?: { shadowRoots?: ShadowRoot[] }) => StaticRange[]
}
).getComposedRanges?.({ shadowRoots: [opts.root] })?.[0] ??
selection.getComposedRanges?.({ shadowRoots: [opts.root] })?.[0] ??
(selection.rangeCount > 0 ? selection.getRangeAt(0) : undefined)
const startNode = domRange?.startContainer ?? selection.anchorNode
const endNode = domRange?.endContainer ?? selection.focusNode
if (!domRange) return
if (!startNode || !endNode) return
if (!opts.root.contains(domRange.startContainer) || !opts.root.contains(domRange.endContainer)) return
if (!opts.root.contains(startNode) || !opts.root.contains(endNode)) return
// A triple click, or a drag that stops at the start of the next line, ends on a line with nothing selected in it.
const startLine = selectedLine(domRange.startContainer, domRange.startOffset, false)
const endLine = selectedLine(domRange.endContainer, domRange.endOffset, true)
const span = startLine?.row !== endLine?.row
const startNode = (span && startLine?.empty) || domRange.startContainer
const endNode = (span && endLine?.empty) || domRange.endContainer
const start = opts.lineForNode(startNode)
const end = opts.lineForNode(endNode)
@@ -100,6 +106,35 @@ export function readShadowLineSelection(opts: {
return {
range,
text: opts.preserveTextSelection && domRange ? toRange(domRange).cloneRange() : undefined,
text: toRange(domRange),
backward: selection.direction === "backward",
}
}
/**
* The line row holding one end of a selection. `empty` is the neighbouring row to read instead when no character of
* this row is selected: the previous row for the end, the next one for the start.
*/
function selectedLine(node: Node, offset: number, end: boolean) {
const row = findElement(node)?.closest("[data-line], [data-alt-line]")
if (!row) return
const part = new Range()
if (end) {
part.setStart(row, 0)
part.setEnd(node, offset)
} else {
part.setStart(node, offset)
part.setEnd(row, row.childNodes.length)
}
if (part.toString() !== "") return { row }
let next = end ? row.previousElementSibling : row.nextElementSibling
while (next && !next.matches("[data-line], [data-alt-line]"))
next = end ? next.previousElementSibling : next.nextElementSibling
return { row, empty: next ?? undefined }
}
@@ -80,20 +80,3 @@ export function toRange(source: Range | StaticRange): Range {
return range
}
export function restoreShadowTextSelection(root: ShadowRoot | undefined, range: Range | undefined) {
if (!root || !range) return
requestAnimationFrame(() => {
// Chromium exposes `getSelection` on shadow roots; the DOM types do not list it.
const shadow: ShadowRoot & { getSelection?: () => Selection | null } = root
const selection = shadow.getSelection?.() ?? window.getSelection()
if (!selection) return
try {
selection.removeAllRanges()
selection.addRange(range)
} catch {}
})
}
@@ -6,83 +6,68 @@ import {
selectPointerTracking,
transitionFileSelection,
type FileSelectionEvent,
type FileSelectionState,
type FileSelectionTransition,
} from "./selection-machine"
const down = (line: number | undefined, column: "text" | "numbers" = "text", side?: "additions" | "deletions") =>
({ type: "pointer.down", button: 0, column, line, side }) as const
const down = (line: number | undefined, column: "text" | "numbers" = "numbers") =>
({ type: "pointer.down", button: 0, column, line, side: undefined, touch: false }) as const
const move = (line: number | undefined, side?: "additions" | "deletions", buttons = 1) =>
({ type: "pointer.move", buttons, line, side }) as const
const tap = (line: number, side?: "additions" | "deletions") =>
({ type: "pointer.down", button: 0, column: "text", line, side, touch: true }) as const
const move = (line: number | undefined, buttons = 1) => ({ type: "pointer.move", buttons, line }) as const
const up = { type: "pointer.up" } as const
function run(events: FileSelectionEvent[], state = createFileSelectionState("text")): FileSelectionTransition {
function run(events: FileSelectionEvent[], state = createFileSelectionState()): FileSelectionTransition {
return events.reduce((result, event) => transitionFileSelection(result.state, event), {
state,
effects: NO_SELECTION_EFFECTS,
})
}
function effects(events: FileSelectionEvent[], state: FileSelectionState) {
return events.map((event) => {
const step = transitionFileSelection(state, event)
state = step.state
return step.effects
})
}
describe("file line selection", () => {
test("disabling selection mid-drag ends the gesture and drops its frames", () => {
const dragging = run([down(5), move(7)])
expect(dragging.state).toMatchObject({ status: "dragging", column: "text", attempt: 1 })
test("pressing and dragging over the code leaves the lines to the text selection", () => {
const selected = run([{ type: "selection.controlled", range: { start: 2, end: 2 } }])
const dragged = run([down(5, "text"), move(7), up], selected.state)
const disabled = transitionFileSelection(dragging.state, { type: "selection.disabled" })
expect(disabled.state).toEqual({ status: "idle", mode: "text", selected: null, attempt: 2 })
expect(disabled.effects).toEqual([{ type: "cancel-frames" }])
for (const event of [{ type: "selection.changed" }, { type: "drag.frame", attempt: 1 }, move(9)] as const) {
const step = transitionFileSelection(disabled.state, event)
expect(step.state).toBe(disabled.state)
expect(step.effects).toBe(NO_SELECTION_EFFECTS)
}
expect(dragged.state).toBe(selected.state)
expect(dragged.effects).toBe(NO_SELECTION_EFFECTS)
expect(selectPointerTracking(dragged.state)).toBe(false)
})
test("a second press before the finishing frame drops the first drag's frame", () => {
const finishing = run([down(2), move(5), up])
expect(finishing.state).toMatchObject({ status: "finishing", attempt: 2, range: { start: 2, end: 5 } })
expect(finishing.effects).toEqual([{ type: "cancel-frames" }, { type: "schedule-finish", attempt: 2 }])
const pressed = transitionFileSelection(finishing.state, down(10))
expect(pressed.state).toMatchObject({ status: "pressing", attempt: 3, origin: { line: 10 } })
expect(pressed.effects).toEqual([{ type: "cancel-frames" }])
const stale = transitionFileSelection(pressed.state, {
type: "finish.frame",
attempt: 2,
range: { start: 10, end: 10 },
})
expect(stale.state).toBe(pressed.state)
expect(stale.effects).toBe(NO_SELECTION_EFFECTS)
})
test("a drag over whitespace commits its end points when the text selection is collapsed", () => {
const finishing = run([down(5), move(8), up])
const done = transitionFileSelection(finishing.state, { type: "finish.frame", attempt: 2, range: undefined })
expect(done.state).toEqual({ status: "idle", mode: "text", selected: { start: 5, end: 8 }, attempt: 2 })
expect(done.effects).toEqual([
{ type: "apply-selection", range: { start: 5, end: 8 }, preserveText: false },
{ type: "notify-selection-end", range: { start: 5, end: 8 }, fromNumberDrag: false },
test("a tap on the code toggles that line on touch screens, where line numbers can be hidden", () => {
const selected = run([tap(5, "additions"), up])
expect(selected.state).toMatchObject({ status: "idle", selected: { start: 5, end: 5, side: "additions" } })
expect(selected.effects).toEqual([
{ type: "apply-selection", range: { start: 5, end: 5, side: "additions" } },
{ type: "notify-selection-end", range: { start: 5, end: 5, side: "additions" }, fromNumberDrag: false },
])
const cleared = run([tap(5, "additions"), up], selected.state)
expect(cleared.effects).toEqual([
{ type: "apply-selection", range: null },
{ type: "notify-selection-end", range: null, fromNumberDrag: false },
])
})
test("a touch that scrolls, long-presses or moves to another line selects nothing", () => {
expect(run([tap(5), { type: "pointer.cancelled" }, up]).effects).toBe(NO_SELECTION_EFFECTS)
expect(run([tap(5), move(6), up]).effects).toBe(NO_SELECTION_EFFECTS)
})
test("disabling selection mid-press ends the gesture", () => {
const pressing = run([down(5), move(7)])
expect(pressing.state).toMatchObject({ status: "dragging", attempt: 1 })
const disabled = transitionFileSelection(pressing.state, { type: "selection.disabled" })
expect(disabled.state).toEqual({ status: "idle", selected: null, attempt: 2 })
expect(disabled.effects).toBe(NO_SELECTION_EFFECTS)
})
test("a line-number drag reports itself once and leaves nothing pending", () => {
// Pierre ends the gesture on its document pointerup, before our window mouseup.
const ended = run([down(1, "numbers"), move(4), { type: "pierre.selection-ended", range: { start: 1, end: 4 } }])
const ended = run([down(1), move(4), { type: "pierre.selection-ended", range: { start: 1, end: 4 } }])
expect(ended.effects).toEqual([{ type: "notify-selection-end", range: { start: 1, end: 4 }, fromNumberDrag: true }])
expect(ended.state).toMatchObject({ status: "idle" })
@@ -100,8 +85,8 @@ describe("file line selection", () => {
})
test("a line-number press that ends without Pierre's callback leaves nothing pending", () => {
for (const end of [move(4, undefined, 0), up]) {
const ended = run([down(1, "numbers"), move(4), end])
for (const end of [move(4, 0), up]) {
const ended = run([down(1), move(4), end])
expect(ended.state).toMatchObject({ status: "idle", attempt: 2 })
const next = transitionFileSelection(ended.state, { type: "pierre.selection-ended", range: { start: 3, end: 6 } })
@@ -112,72 +97,15 @@ describe("file line selection", () => {
})
test("a single-line number click is not a number drag", () => {
const ended = run([down(3, "numbers"), move(3), { type: "pierre.selection-ended", range: { start: 3, end: 3 } }])
const ended = run([down(3), move(3), { type: "pierre.selection-ended", range: { start: 3, end: 3 } }])
expect(ended.effects).toEqual([
{ type: "notify-selection-end", range: { start: 3, end: 3 }, fromNumberDrag: false },
])
})
test("a click toggles one line, even when the pointer jitters on that line", () => {
const selected = run([down(5), move(5), up])
expect(selected.state).toMatchObject({ status: "idle", selected: { start: 5, end: 5 } })
expect(selected.effects).toEqual([
{ type: "apply-selection", range: { start: 5, end: 5 }, preserveText: false },
{ type: "notify-selection-end", range: { start: 5, end: 5 }, fromNumberDrag: false },
])
const cleared = run([down(5), up], selected.state)
expect(cleared.state).toMatchObject({ status: "idle", selected: null })
expect(cleared.effects).toEqual([
{ type: "apply-selection", range: null, preserveText: false },
{ type: "notify-selection-end", range: null, fromNumberDrag: false },
])
})
test("selecting characters on one line keeps the text selection", () => {
const finishing = run([down(5), { type: "selection.changed" }, up])
expect(finishing.state).toMatchObject({ status: "finishing", range: { start: 5, end: 5 } })
const done = transitionFileSelection(finishing.state, {
type: "finish.frame",
attempt: 2,
range: { start: 5, end: 5, side: "additions" },
})
expect(done.effects).toEqual([
{ type: "apply-selection", range: { start: 5, end: 5, side: "additions" }, preserveText: true },
{ type: "notify-selection-end", range: { start: 5, end: 5, side: "additions" }, fromNumberDrag: false },
])
})
test("drag frames apply the latest end point and stale ones do nothing", () => {
const dragging = run([down(2), move(4), move(6)])
const frame = transitionFileSelection(dragging.state, { type: "drag.frame", attempt: 1 })
expect(frame.state).toMatchObject({ status: "dragging", selected: { start: 2, end: 6 } })
expect(frame.effects).toEqual([{ type: "apply-selection", range: { start: 2, end: 6 }, preserveText: false }])
expect(transitionFileSelection(dragging.state, { type: "drag.frame", attempt: 0 }).state).toBe(dragging.state)
})
test("a button released outside the window ends the drag", () => {
const step = run([down(2), move(4), move(undefined, undefined, 0)])
expect(step.state).toMatchObject({ status: "idle", attempt: 2 })
expect(step.effects).toEqual([{ type: "cancel-frames" }])
})
test("a diff drag keeps its direction and both sides", () => {
const finishing = run([down(20, "text", "deletions"), move(15, "additions"), up], createFileSelectionState("diff"))
expect(finishing.state).toMatchObject({
status: "finishing",
range: { start: 20, end: 15, side: "deletions", endSide: "additions" },
})
})
test("a controlled range applies unless it is the range already shown", () => {
const shown = run([down(5), up])
const shown = run([{ type: "selection.controlled", range: { start: 5, end: 5 } }])
const selected = shown.state.status === "idle" ? shown.state.selected : null
if (!selected) throw new Error("expected a selection")
@@ -188,7 +116,7 @@ describe("file line selection", () => {
// A restored draft hands back a copy of the range.
const copy = transitionFileSelection(shown.state, { type: "selection.controlled", range: { ...selected } })
expect(copy.effects).toEqual([{ type: "apply-selection", range: { start: 5, end: 5 }, preserveText: false }])
expect(copy.effects).toEqual([{ type: "apply-selection", range: { start: 5, end: 5 } }])
})
test("Pierre's committed range updates the shown range without ending a gesture", () => {
@@ -199,31 +127,24 @@ describe("file line selection", () => {
expect(step.effects).toEqual([{ type: "notify-line-selected", range: { start: 2, end: 4 } }])
})
test("hovering does no work and repeated moves on one line keep the same state", () => {
const idle = createFileSelectionState("text")
test("hovering does no work and repeated moves keep the same state", () => {
const idle = createFileSelectionState()
const dragging = run([down(2), move(4)])
const finishing = run([up], dragging.state)
expect(selectPointerTracking(idle)).toBe(false)
expect(selectPointerTracking(finishing.state)).toBe(false)
expect(selectPointerTracking(DISPOSED_FILE_SELECTION_STATE)).toBe(false)
expect(selectPointerTracking(dragging.state)).toBe(true)
const same = transitionFileSelection(dragging.state, move(4))
const same = transitionFileSelection(dragging.state, move(6))
expect(same.state).toBe(dragging.state)
expect(same.effects).toBe(NO_SELECTION_EFFECTS)
})
test("disposing drops pending frames and ignores later events", () => {
const disposed = run([down(2), move(4), { type: "disposed" }])
expect(disposed.state).toBe(DISPOSED_FILE_SELECTION_STATE)
expect(disposed.effects).toEqual([{ type: "cancel-frames" }])
test("disposing ignores later events", () => {
const state = run([down(2), move(4), { type: "disposed" }]).state
expect(state).toBe(DISPOSED_FILE_SELECTION_STATE)
expect(
effects(
[down(1), move(3), up, { type: "finish.frame", attempt: 2, range: undefined }],
DISPOSED_FILE_SELECTION_STATE,
),
).toEqual([NO_SELECTION_EFFECTS, NO_SELECTION_EFFECTS, NO_SELECTION_EFFECTS, NO_SELECTION_EFFECTS])
for (const event of [down(1), move(3), up] as const)
expect(transitionFileSelection(state, event).effects).toBe(NO_SELECTION_EFFECTS)
})
})
@@ -2,40 +2,24 @@ import type { SelectedLineRange } from "@pierre/diffs"
import type { DiffSelectionSide } from "./diff-selection"
import { isSingleLineSelection } from "./selection-bridge"
/** `text` orders a dragged range top to bottom; `diff` keeps its direction and the side of each end. */
export type FileSelectionMode = "text" | "diff"
export type SelectionPoint = {
readonly line: number
readonly side?: DiffSelectionSide
}
type Shared = {
readonly mode: FileSelectionMode
/** The range the viewer shows; the render driver reapplies it once fresh rows exist. */
readonly selected: SelectedLineRange | null
/** Gesture count. A frame scheduled for an earlier gesture is stale. */
/** Gesture count. */
readonly attempt: number
}
/**
* One line-selection gesture in a file or diff viewer. A press on the code (`text` column) selects lines from our own
* mouse handlers: a click toggles one line, a drag selects the lines between its ends, and `finishing` waits one frame
* for the browser's text selection before it commits. A press on the line numbers (`numbers` column) belongs to Pierre;
* the machine only tracks whether it moved, so a multi-line number drag can report itself.
* Line selection in a file or diff viewer. Line numbers select lines: Pierre runs that gesture, and the machine only
* tracks whether it moved, so a multi-line number drag can report itself. A mouse press on the code is left to the
* browser's text selection, which the viewer offers to comment on separately. A tap on the code toggles its line,
* because touch selects text with a long press instead, and narrow diffs hide their line numbers.
*/
export type FileSelectionState =
| (Shared & { readonly status: "idle" })
| (Shared & { readonly status: "pressing"; readonly column: "text"; readonly origin: SelectionPoint })
| (Shared & { readonly status: "pressing"; readonly column: "numbers"; readonly originLine: number | undefined })
| (Shared & {
readonly status: "dragging"
readonly column: "text"
readonly origin: SelectionPoint
readonly current: SelectionPoint
})
| (Shared & { readonly status: "dragging"; readonly column: "numbers" })
| (Shared & { readonly status: "finishing"; readonly range: SelectedLineRange })
| (Shared & { readonly status: "pressing"; readonly originLine: number | undefined })
| (Shared & { readonly status: "dragging" })
| (Shared & { readonly status: "tapping"; readonly line: number; readonly side: DiffSelectionSide | undefined })
| { readonly status: "disposed" }
export type FileSelectionEvent =
@@ -45,20 +29,12 @@ export type FileSelectionEvent =
readonly column: "text" | "numbers"
readonly line: number | undefined
readonly side: DiffSelectionSide | undefined
readonly touch: boolean
}
| {
readonly type: "pointer.move"
readonly buttons: number
readonly line: number | undefined
readonly side: DiffSelectionSide | undefined
}
| { readonly type: "pointer.move"; readonly buttons: number; readonly line: number | undefined }
| { readonly type: "pointer.up" }
/** The browser selection inside the viewer is no longer collapsed. */
| { readonly type: "selection.changed" }
| { readonly type: "drag.frame"; readonly attempt: number }
| { readonly type: "selection.frame"; readonly attempt: number; readonly range: SelectedLineRange }
/** `range` is the browser's text selection, or `undefined` when it is collapsed (a drag over whitespace). */
| { readonly type: "finish.frame"; readonly attempt: number; readonly range: SelectedLineRange | undefined }
/** The browser took the touch over, to scroll or to select text. */
| { readonly type: "pointer.cancelled" }
| { readonly type: "pierre.line-selected"; readonly range: SelectedLineRange | null }
| { readonly type: "pierre.selection-ended"; readonly range: SelectedLineRange | null }
| { readonly type: "selection.controlled"; readonly range: SelectedLineRange | null }
@@ -66,12 +42,7 @@ export type FileSelectionEvent =
| { readonly type: "disposed" }
export type FileSelectionEffect =
| { readonly type: "cancel-frames" }
| { readonly type: "schedule-drag"; readonly attempt: number }
| { readonly type: "schedule-selection"; readonly attempt: number }
| { readonly type: "schedule-finish"; readonly attempt: number }
/** `preserveText` restores the browser's text selection after Pierre redraws the selected rows. */
| { readonly type: "apply-selection"; readonly range: SelectedLineRange | null; readonly preserveText: boolean }
| { readonly type: "apply-selection"; readonly range: SelectedLineRange | null }
| { readonly type: "notify-line-selected"; readonly range: SelectedLineRange | null }
| {
readonly type: "notify-selection-end"
@@ -90,74 +61,102 @@ export const NO_SELECTION_EFFECTS: readonly FileSelectionEffect[] = Object.freez
export const DISPOSED_FILE_SELECTION_STATE: FileSelectionState = Object.freeze({ status: "disposed" })
const CANCEL_FRAMES: readonly FileSelectionEffect[] = Object.freeze([Object.freeze({ type: "cancel-frames" as const })])
export function createFileSelectionState(mode: FileSelectionMode): FileSelectionState {
return { status: "idle", mode, selected: null, attempt: 0 }
export function createFileSelectionState(): FileSelectionState {
return { status: "idle", selected: null, attempt: 0 }
}
export function transitionFileSelection(state: FileSelectionState, event: FileSelectionEvent): FileSelectionTransition {
if (state.status === "disposed") return { state, effects: NO_SELECTION_EFFECTS }
if (event.type === "disposed")
return { state: DISPOSED_FILE_SELECTION_STATE, effects: framed(state) ? CANCEL_FRAMES : NO_SELECTION_EFFECTS }
if (event.type === "disposed") return { state: DISPOSED_FILE_SELECTION_STATE, effects: NO_SELECTION_EFFECTS }
if (event.type === "selection.disabled") {
if (state.status === "idle") return { state, effects: NO_SELECTION_EFFECTS }
return { state: idle(state, state.selected, state.attempt + 1), effects: CANCEL_FRAMES }
return { state: idle(state, state.selected, state.attempt + 1), effects: NO_SELECTION_EFFECTS }
}
if (event.type === "pointer.down") return press(state, event)
if (event.type === "pointer.down") {
if (event.button !== 0) return { state, effects: NO_SELECTION_EFFECTS }
if (event.type === "pointer.move") return move(state, event)
if (event.column === "text") {
if (!event.touch || event.line === undefined) return { state, effects: NO_SELECTION_EFFECTS }
if (event.type === "pointer.up") return release(state)
if (event.type === "selection.changed") {
if (state.status === "pressing" && state.column === "text")
return {
state: { ...shared(state), status: "dragging", column: "text", origin: state.origin, current: state.origin },
effects: [{ type: "schedule-selection", attempt: state.attempt }],
state: {
status: "tapping",
selected: state.selected,
attempt: state.attempt + 1,
line: event.line,
side: event.side,
},
effects: NO_SELECTION_EFFECTS,
}
if (state.status === "dragging" && state.column === "text")
return { state, effects: [{ type: "schedule-selection", attempt: state.attempt }] }
return { state, effects: NO_SELECTION_EFFECTS }
}
if (event.type === "drag.frame") {
if (state.status !== "dragging" || state.column !== "text" || event.attempt !== state.attempt)
return { state, effects: NO_SELECTION_EFFECTS }
const range = buildSelectionRange(state.mode, state.origin, state.current)
return { state: { ...state, selected: range }, effects: [{ type: "apply-selection", range, preserveText: false }] }
}
if (event.type === "selection.frame") {
if (state.status !== "dragging" || state.column !== "text" || event.attempt !== state.attempt)
return { state, effects: NO_SELECTION_EFFECTS }
}
return {
state: { ...state, selected: event.range },
effects: [{ type: "apply-selection", range: event.range, preserveText: false }],
state: { status: "pressing", selected: state.selected, attempt: state.attempt + 1, originLine: event.line },
effects: NO_SELECTION_EFFECTS,
}
}
if (event.type === "finish.frame") {
if (state.status !== "finishing" || event.attempt !== state.attempt) return { state, effects: NO_SELECTION_EFFECTS }
const range = event.range ?? state.range
if (event.type === "pointer.cancelled") {
if (!selectPointerTracking(state)) return { state, effects: NO_SELECTION_EFFECTS }
return { state: idle(state, state.selected, state.attempt + 1), effects: NO_SELECTION_EFFECTS }
}
if (event.type === "pointer.move") {
if (state.status === "tapping") {
if (event.line === undefined || event.line === state.line) return { state, effects: NO_SELECTION_EFFECTS }
return { state: idle(state, state.selected, state.attempt + 1), effects: NO_SELECTION_EFFECTS }
}
if (state.status !== "pressing" && state.status !== "dragging") return { state, effects: NO_SELECTION_EFFECTS }
// The button came up outside the window, so no mouseup reached us.
if ((event.buttons & 1) === 0)
return { state: idle(state, state.selected, state.attempt + 1), effects: NO_SELECTION_EFFECTS }
if (
state.status === "dragging" ||
event.line === undefined ||
state.originLine === undefined ||
event.line === state.originLine
)
return { state, effects: NO_SELECTION_EFFECTS }
return {
state: { status: "dragging", selected: state.selected, attempt: state.attempt },
effects: NO_SELECTION_EFFECTS,
}
}
if (event.type === "pointer.up" && state.status === "tapping") {
const line: SelectedLineRange = { start: state.line, end: state.line }
if (state.side) line.side = state.side
const range =
state.selected && isSingleLineSelection(state.selected) && sameLine(state.selected, line) ? null : line
return {
state: idle(state, range, state.attempt),
effects: [
{ type: "apply-selection", range, preserveText: event.range !== undefined },
{ type: "apply-selection", range },
{ type: "notify-selection-end", range, fromNumberDrag: false },
],
}
}
// Pierre ends a line-number gesture on its own pointerup, which runs before this one.
if (event.type === "pointer.up") {
if (state.status !== "pressing" && state.status !== "dragging") return { state, effects: NO_SELECTION_EFFECTS }
return { state: idle(state, state.selected, state.attempt + 1), effects: NO_SELECTION_EFFECTS }
}
if (event.type === "pierre.line-selected")
return {
state: state.selected === event.range ? state : { ...state, selected: event.range },
@@ -165,15 +164,11 @@ export function transitionFileSelection(state: FileSelectionState, event: FileSe
}
if (event.type === "pierre.selection-ended") {
const fromNumberDrag =
state.status === "dragging" && state.column === "numbers" && !isSingleLineSelection(event.range)
const fromNumberDrag = state.status === "dragging" && !isSingleLineSelection(event.range)
return {
state: idle(state, event.range, state.attempt + 1),
effects: [
...(framed(state) ? CANCEL_FRAMES : NO_SELECTION_EFFECTS),
{ type: "notify-selection-end", range: event.range, fromNumberDrag },
],
effects: [{ type: "notify-selection-end", range: event.range, fromNumberDrag }],
}
}
@@ -181,119 +176,12 @@ export function transitionFileSelection(state: FileSelectionState, event: FileSe
return {
state: { ...state, selected: event.range },
effects: [{ type: "apply-selection", range: event.range, preserveText: false }],
effects: [{ type: "apply-selection", range: event.range }],
}
}
function press(state: Active, event: Extract<FileSelectionEvent, { type: "pointer.down" }>): FileSelectionTransition {
if (event.button !== 0) return { state, effects: NO_SELECTION_EFFECTS }
const effects = framed(state) ? CANCEL_FRAMES : NO_SELECTION_EFFECTS
if (event.column === "numbers")
return {
state: {
...shared(state),
attempt: state.attempt + 1,
status: "pressing",
column: "numbers",
originLine: event.line,
},
effects,
}
if (event.line === undefined) return { state, effects: NO_SELECTION_EFFECTS }
return {
state: {
...shared(state),
attempt: state.attempt + 1,
status: "pressing",
column: "text",
origin: { line: event.line, side: event.side },
},
effects,
}
}
function move(state: Active, event: Extract<FileSelectionEvent, { type: "pointer.move" }>): FileSelectionTransition {
if (state.status !== "pressing" && state.status !== "dragging") return { state, effects: NO_SELECTION_EFFECTS }
// The button came up outside the window, so no mouseup reached us.
if ((event.buttons & 1) === 0)
return {
state: idle(state, state.selected, state.attempt + 1),
effects: framed(state) ? CANCEL_FRAMES : NO_SELECTION_EFFECTS,
}
if (event.line === undefined) return { state, effects: NO_SELECTION_EFFECTS }
if (state.column === "numbers") {
if (state.status === "dragging" || state.originLine === undefined || event.line === state.originLine)
return { state, effects: NO_SELECTION_EFFECTS }
return { state: { ...shared(state), status: "dragging", column: "numbers" }, effects: NO_SELECTION_EFFECTS }
}
const last = state.status === "dragging" ? state.current : state.origin
if (event.line === last.line && event.side === last.side) return { state, effects: NO_SELECTION_EFFECTS }
return {
state: {
...shared(state),
status: "dragging",
column: "text",
origin: state.origin,
current: { line: event.line, side: event.side },
},
effects: [{ type: "schedule-drag", attempt: state.attempt }],
}
}
function release(state: Active): FileSelectionTransition {
if (state.status !== "pressing" && state.status !== "dragging") return { state, effects: NO_SELECTION_EFFECTS }
// Pierre ends a line-number gesture on its own pointerup, which runs before this mouseup.
if (state.column === "numbers")
return { state: idle(state, state.selected, state.attempt + 1), effects: NO_SELECTION_EFFECTS }
if (state.status === "dragging") {
const attempt = state.attempt + 1
return {
state: {
...shared(state),
attempt,
status: "finishing",
range: buildSelectionRange(state.mode, state.origin, state.current),
},
effects: [{ type: "cancel-frames" }, { type: "schedule-finish", attempt }],
}
}
const click = buildSelectionRange(state.mode, state.origin, state.origin)
const range = sameSelectedRange(state.selected, click) ? null : click
return {
state: idle(state, range, state.attempt + 1),
effects: [
{ type: "apply-selection", range, preserveText: false },
{ type: "notify-selection-end", range, fromNumberDrag: false },
],
}
}
function shared(state: Active) {
return { mode: state.mode, selected: state.selected, attempt: state.attempt }
}
function idle(state: Active, selected: SelectedLineRange | null, attempt: number): FileSelectionState {
return { status: "idle", mode: state.mode, selected, attempt }
}
/** Whether a drag, selection or finish frame may be queued. */
function framed(state: Active) {
return (state.status === "dragging" && state.column === "text") || state.status === "finishing"
return { status: "idle", selected, attempt }
}
export function selectSelectedRange(state: FileSelectionState) {
@@ -302,31 +190,9 @@ export function selectSelectedRange(state: FileSelectionState) {
/** Whether pointer moves can change the gesture; checked before any hit testing. */
export function selectPointerTracking(state: FileSelectionState) {
return state.status === "pressing" || state.status === "dragging"
return state.status === "pressing" || state.status === "dragging" || state.status === "tapping"
}
/** Whether a browser text selection can extend the gesture. */
export function selectTextSelectionTracking(state: FileSelectionState) {
return (state.status === "pressing" || state.status === "dragging") && state.column === "text"
}
export function buildSelectionRange(
mode: FileSelectionMode,
origin: SelectionPoint,
current: SelectionPoint,
): SelectedLineRange {
if (mode === "text") return { start: Math.min(origin.line, current.line), end: Math.max(origin.line, current.line) }
const range: SelectedLineRange = { start: origin.line, end: current.line }
if (origin.side) range.side = origin.side
if (origin.side && current.side && current.side !== origin.side) range.endSide = current.side
return range
}
export function sameSelectedRange(a: SelectedLineRange | null, b: SelectedLineRange | null) {
if (!a || !b) return a === b
return a.start === b.start && a.end === b.end && a.side === b.side && (a.endSide ?? a.side) === (b.endSide ?? b.side)
function sameLine(a: SelectedLineRange, b: SelectedLineRange) {
return a.start === b.start && a.side === b.side
}
@@ -179,5 +179,10 @@ export function createLineCommentControllerV2<T extends SavedLineComment>(props:
}),
onLineSelected: (range: SelectedLineRange | null) => driver.send({ type: "line.selected", range }),
onLineSelectionEnd: (range: SelectedLineRange | null) => driver.send({ type: "line.selection-ended", range }),
/** Opens a draft on text selected in the code. Unset while a saved comment is edited, which keeps its range. */
commentSelection: () =>
driver.mode().status === "editing"
? undefined
: (range: SelectedLineRange) => driver.send({ type: "draft.opened", range }),
}
}
@@ -204,6 +204,7 @@ export function SessionReviewFilePreviewV2(props: SessionReviewFilePreviewV2Prop
annotations={commentsUi.annotations()}
renderAnnotation={commentsUi.renderAnnotation}
renderGutterUtility={lineCommentsEnabled() ? commentsUi.renderGutterUtility : undefined}
onCommentSelection={lineCommentsEnabled() ? commentsUi.commentSelection() : undefined}
selectedLines={commentsUi.selected()}
commentedLines={commentedLines()}
media={{
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "በላይ አስተያየት መስጠት ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "አስተያየት ያክሉ",
"ui.lineComment.add": "አስተያየት ያክሉ",
"ui.lineComment.actions": "የምርጫ ድርጊቶች",
"ui.lineComment.contextPlaceholder": "ለዚህ ለውጥ አውድ ጨምር",
"ui.lineComment.submit": "አስተያየት",
"ui.lineComment.cancel": "ሰርዝ",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "جارٍ التعليق على ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "أضف تعليقًا",
"ui.lineComment.add": "أضف تعليقًا",
"ui.lineComment.actions": "إجراءات التحديد",
"ui.lineComment.contextPlaceholder": "أضف سياقًا لهذا التغيير",
"ui.lineComment.submit": "تعليق",
"ui.lineComment.cancel": "إلغاء",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Şərh yazılır: ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Şərh əlavə et",
"ui.lineComment.add": "Şərh əlavə et",
"ui.lineComment.actions": "Seçim əməliyyatları",
"ui.lineComment.contextPlaceholder": "Bu dəyişiklik üçün kontekst əlavə et",
"ui.lineComment.submit": "Şərh et",
"ui.lineComment.cancel": "Ləğv et",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Коментиране на",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Добавете коментар",
"ui.lineComment.add": "Добавете коментар",
"ui.lineComment.actions": "Действия за избраното",
"ui.lineComment.contextPlaceholder": "Добавете контекст за тази промяна",
"ui.lineComment.submit": "Коментирайте",
"ui.lineComment.cancel": "Отказ",
+2
View File
@@ -50,6 +50,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "মন্তব্য করছেন",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "মন্তব্য যোগ করুন",
"ui.lineComment.add": "মন্তব্য যোগ করুন",
"ui.lineComment.actions": "নির্বাচনের কার্যক্রম",
"ui.lineComment.contextPlaceholder": "এই পরিবর্তনের জন্য প্রসঙ্গ যোগ করুন",
"ui.lineComment.submit": "মন্তব্য করুন",
"ui.lineComment.cancel": "বাতিল করুন",
+2
View File
@@ -93,6 +93,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Comentando em ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Adicionar comentário",
"ui.lineComment.add": "Adicionar comentário",
"ui.lineComment.actions": "Ações da seleção",
"ui.lineComment.contextPlaceholder": "Adicionar contexto para esta alteração",
"ui.lineComment.submit": "Comentar",
"ui.lineComment.cancel": "Cancelar",
+2
View File
@@ -53,6 +53,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Komentarišeš ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Dodaj komentar",
"ui.lineComment.add": "Dodaj komentar",
"ui.lineComment.actions": "Radnje odabira",
"ui.lineComment.contextPlaceholder": "Dodaj kontekst za ovu izmjenu",
"ui.lineComment.submit": "Komentariši",
"ui.lineComment.cancel": "Otkaži",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Comentant ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Afegeix un comentari",
"ui.lineComment.add": "Afegeix un comentari",
"ui.lineComment.actions": "Accions de selecció",
"ui.lineComment.contextPlaceholder": "Afegeix context per a aquest canvi",
"ui.lineComment.submit": "Comenta",
"ui.lineComment.cancel": "Cancel·la",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Komentování ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Přidat komentář",
"ui.lineComment.add": "Přidat komentář",
"ui.lineComment.actions": "Akce výběru",
"ui.lineComment.contextPlaceholder": "Přidejte kontext pro tuto změnu",
"ui.lineComment.submit": "Komentář",
"ui.lineComment.cancel": "Zrušit",
+2
View File
@@ -86,6 +86,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Skriver en kommentar til ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Tilføj kommentar",
"ui.lineComment.add": "Tilføj kommentar",
"ui.lineComment.actions": "Markeringshandlinger",
"ui.lineComment.submit": "Kommenter",
"ui.lineComment.cancel": "Annuller",
"ui.sessionTurn.steps.show": "Vis trin",
+2
View File
@@ -93,6 +93,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Kommentiere ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Kommentar hinzufügen",
"ui.lineComment.add": "Kommentar hinzufügen",
"ui.lineComment.actions": "Auswahlaktionen",
"ui.lineComment.submit": "Kommentieren",
"ui.lineComment.cancel": "Abbrechen",
"ui.sessionTurn.steps.show": "Schritte anzeigen",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "ކޮމެންޓް ކުރަމުންނެވެ ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "ކޮމެންޓް އެޑް ކުރާށެވެ",
"ui.lineComment.add": "ކޮމެންޓް އެޑް ކުރާށެވެ",
"ui.lineComment.actions": "ސެލެކްޝަން އެކްޝަންތައް",
"ui.lineComment.contextPlaceholder": "މި ބަދަލަށް ކޮންޓެކްސްޓް އިތުރުކުރުން",
"ui.lineComment.submit": "ކޮމެންޓް",
"ui.lineComment.cancel": "ކެންސަލް",
+2
View File
@@ -50,6 +50,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "བསམ་འཆར་བཀོད་དོན།",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "བསམ་འཆར་ཁ་སྣོན་འབད།",
"ui.lineComment.add": "བསམ་འཆར་ཁ་སྣོན་འབད།",
"ui.lineComment.actions": "སེལ་འཐུའི་བྱ་སྤྱོད།",
"ui.lineComment.contextPlaceholder": "བསྒྱུར་བཅོས་འདི་གི་དོན་ལུ་ སྐབས་དོན་ཁ་སྐོང་བརྐྱབ།",
"ui.lineComment.submit": "བསམ༌འཆར",
"ui.lineComment.cancel": "ཆ་མེད་བཏང་པ་",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Σχολιασμός ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Προσθήκη σχολίου",
"ui.lineComment.add": "Προσθήκη σχολίου",
"ui.lineComment.actions": "Ενέργειες επιλογής",
"ui.lineComment.contextPlaceholder": "Προσθήκη περιβάλλοντος για αυτήν την αλλαγή",
"ui.lineComment.submit": "Σχόλιο",
"ui.lineComment.cancel": "Ακύρωση",
+2
View File
@@ -55,6 +55,8 @@ const source = {
"ui.lineComment.editorLabel.prefix": "Commenting on ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Add comment",
"ui.lineComment.add": "Add comment",
"ui.lineComment.actions": "Selection actions",
"ui.lineComment.contextPlaceholder": "Add context for this change",
"ui.lineComment.submit": "Comment",
"ui.lineComment.cancel": "Cancel",
+2
View File
@@ -92,6 +92,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Comentando en ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Añadir comentario",
"ui.lineComment.add": "Añadir comentario",
"ui.lineComment.actions": "Acciones de selección",
"ui.lineComment.contextPlaceholder": "Añadir contexto para este cambio",
"ui.lineComment.submit": "Comentar",
"ui.lineComment.cancel": "Cancelar",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Kommenteerides ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Lisa kommentaar",
"ui.lineComment.add": "Lisa kommentaar",
"ui.lineComment.actions": "Valiku toimingud",
"ui.lineComment.contextPlaceholder": "Lisage selle muudatuse kontekst",
"ui.lineComment.submit": "Kommenteeri",
"ui.lineComment.cancel": "Tühista",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "در حال اظهار نظر ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "نظر اضافه کنید",
"ui.lineComment.add": "نظر اضافه کنید",
"ui.lineComment.actions": "اقدامات انتخاب",
"ui.lineComment.contextPlaceholder": "برای این تغییر زمینه اضافه کنید",
"ui.lineComment.submit": "نظر دهید",
"ui.lineComment.cancel": "لغو کنید",
+2
View File
@@ -85,6 +85,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Kommentoit kohdetta ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Lisää kommentti",
"ui.lineComment.add": "Lisää kommentti",
"ui.lineComment.actions": "Valinnan toiminnot",
"ui.lineComment.submit": "Kommentoi",
"ui.lineComment.cancel": "Peruuta",
"ui.sessionTurn.steps.show": "Näytä vaiheet",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Viðmerkjandi ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Legg viðmerking til",
"ui.lineComment.add": "Legg viðmerking til",
"ui.lineComment.actions": "Gerðir fyri val",
"ui.lineComment.contextPlaceholder": "Legg samanhang til hesa broyting",
"ui.lineComment.submit": "Viðmerking",
"ui.lineComment.cancel": "Avlýs",
+2
View File
@@ -93,6 +93,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Commentaire concernant ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Ajouter un commentaire",
"ui.lineComment.add": "Ajouter un commentaire",
"ui.lineComment.actions": "Actions de sélection",
"ui.lineComment.contextPlaceholder": "Ajouter du contexte à cette modification",
"ui.lineComment.submit": "Commenter",
"ui.lineComment.cancel": "Annuler",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "תגובה על ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "הוסף תגובה",
"ui.lineComment.add": "הוסף תגובה",
"ui.lineComment.actions": "פעולות בחירה",
"ui.lineComment.contextPlaceholder": "הוסף הקשר לשינוי זה",
"ui.lineComment.submit": "שלח תגובה",
"ui.lineComment.cancel": "בטל",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "इस पर टिप्पणी की जा रही है: ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "टिप्पणी जोड़ें",
"ui.lineComment.add": "टिप्पणी जोड़ें",
"ui.lineComment.actions": "चयन कार्रवाइयाँ",
"ui.lineComment.contextPlaceholder": "इस परिवर्तन के लिए संदर्भ जोड़ें",
"ui.lineComment.submit": "टिप्पणी",
"ui.lineComment.cancel": "रद्द करें",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Komentiranje",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Dodajte komentar",
"ui.lineComment.add": "Dodajte komentar",
"ui.lineComment.actions": "Radnje odabira",
"ui.lineComment.contextPlaceholder": "Dodajte kontekst za ovu promjenu",
"ui.lineComment.submit": "Komentar",
"ui.lineComment.cancel": "Otkazati",
+2
View File
@@ -50,6 +50,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Hozzászólás",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Megjegyzés hozzáadása",
"ui.lineComment.add": "Megjegyzés hozzáadása",
"ui.lineComment.actions": "Kijelölési műveletek",
"ui.lineComment.contextPlaceholder": "Kontextus hozzáadása ehhez a módosításhoz",
"ui.lineComment.submit": "Megjegyzés",
"ui.lineComment.cancel": "Mégsem",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Մեկնաբանում ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Ավելացնել մեկնաբանություն",
"ui.lineComment.add": "Ավելացնել մեկնաբանություն",
"ui.lineComment.actions": "Ընտրության գործողություններ",
"ui.lineComment.contextPlaceholder": "Ավելացնել համատեքստ այս փոփոխության համար",
"ui.lineComment.submit": "Մեկնաբանություն",
"ui.lineComment.cancel": "Չեղարկել",
+2
View File
@@ -50,6 +50,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Mengomentari ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Tambah komentar",
"ui.lineComment.add": "Tambah komentar",
"ui.lineComment.actions": "Tindakan pilihan",
"ui.lineComment.contextPlaceholder": "Tambahkan konteks untuk perubahan ini",
"ui.lineComment.submit": "Komentar",
"ui.lineComment.cancel": "Batal",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Gerir athugasemdir við",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Bæta við athugasemd",
"ui.lineComment.add": "Bæta við athugasemd",
"ui.lineComment.actions": "Aðgerðir fyrir val",
"ui.lineComment.contextPlaceholder": "Bættu við samhengi fyrir þessa breytingu",
"ui.lineComment.submit": "Athugasemd",
"ui.lineComment.cancel": "Hætta við",
+2
View File
@@ -93,6 +93,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Commento su ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Aggiungi commento",
"ui.lineComment.add": "Aggiungi commento",
"ui.lineComment.actions": "Azioni di selezione",
"ui.lineComment.contextPlaceholder": "Aggiungi contesto per questa modifica",
"ui.lineComment.submit": "Commenta",
"ui.lineComment.cancel": "Annulla",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "",
"ui.lineComment.editorLabel.suffix": "へのコメントを作成中",
"ui.lineComment.placeholder": "コメントを追加",
"ui.lineComment.add": "コメントを追加",
"ui.lineComment.actions": "選択範囲の操作",
"ui.lineComment.contextPlaceholder": "この変更に関するコンテキストを追加",
"ui.lineComment.submit": "コメント",
"ui.lineComment.cancel": "キャンセル",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "კომენტირება ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "კომენტარის დამატება",
"ui.lineComment.add": "კომენტარის დამატება",
"ui.lineComment.actions": "მონიშნულის მოქმედებები",
"ui.lineComment.contextPlaceholder": "დაამატეთ კონტექსტი ამ ცვლილებისთვის",
"ui.lineComment.submit": "კომენტარი",
"ui.lineComment.cancel": "გაუქმება",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "អត្ថាធិប្បាយលើ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "បន្ថែមមតិ",
"ui.lineComment.add": "បន្ថែមមតិ",
"ui.lineComment.actions": "សកម្មភាពជ្រើសរើស",
"ui.lineComment.contextPlaceholder": "បន្ថែមបរិបទសម្រាប់ការផ្លាស់ប្តូរនេះ។",
"ui.lineComment.submit": "មតិយោបល់",
"ui.lineComment.cancel": "បោះបង់",
+2
View File
@@ -31,6 +31,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "",
"ui.lineComment.editorLabel.suffix": "에 댓글 작성 중",
"ui.lineComment.placeholder": "댓글 추가",
"ui.lineComment.add": "댓글 추가",
"ui.lineComment.actions": "선택 영역 작업",
"ui.lineComment.contextPlaceholder": "이 변경 사항에 대한 컨텍스트 추가",
"ui.lineComment.submit": "댓글 달기",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "ຄໍາເຫັນກ່ຽວກັບ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "ເພີ່ມຄຳເຫັນ",
"ui.lineComment.add": "ເພີ່ມຄຳເຫັນ",
"ui.lineComment.actions": "ການດຳເນີນການສຳລັບສ່ວນທີ່ເລືອກ",
"ui.lineComment.contextPlaceholder": "ເພີ່ມບໍລິບົດສໍາລັບການປ່ຽນແປງນີ້",
"ui.lineComment.submit": "ຄໍາເຫັນ",
"ui.lineComment.cancel": "ຍົກເລີກ",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Komentuodamas",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Pridėti komentarą",
"ui.lineComment.add": "Pridėti komentarą",
"ui.lineComment.actions": "Pažymėto teksto veiksmai",
"ui.lineComment.contextPlaceholder": "Pridėkite šio pakeitimo kontekstą",
"ui.lineComment.submit": "komentuoti",
"ui.lineComment.cancel": "Atšaukti",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Komentē",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Pievieno komentāru",
"ui.lineComment.add": "Pievieno komentāru",
"ui.lineComment.actions": "Atlases darbības",
"ui.lineComment.contextPlaceholder": "Pievieno kontekstu šai izmaiņai",
"ui.lineComment.submit": "Komentēt",
"ui.lineComment.cancel": "Atcelt",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Коментирајќи на",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Додадете коментар",
"ui.lineComment.add": "Додадете коментар",
"ui.lineComment.actions": "Дејства за изборот",
"ui.lineComment.contextPlaceholder": "Додадете контекст за оваа промена",
"ui.lineComment.submit": "Коментар",
"ui.lineComment.cancel": "Откажи",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Сэтгэгдэл бичиж байна",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Сэтгэгдэл нэмэх",
"ui.lineComment.add": "Сэтгэгдэл нэмэх",
"ui.lineComment.actions": "Сонголтын үйлдлүүд",
"ui.lineComment.contextPlaceholder": "Энэ өөрчлөлтийн контекст нэмнэ үү",
"ui.lineComment.submit": "Сэтгэгдэл",
"ui.lineComment.cancel": "Цуцлах",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Sedang mengulas pada",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Tambah komen",
"ui.lineComment.add": "Tambah komen",
"ui.lineComment.actions": "Tindakan pilihan",
"ui.lineComment.contextPlaceholder": "Tambah konteks untuk perubahan ini",
"ui.lineComment.submit": "Komen",
"ui.lineComment.cancel": "Batal",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "မှတ်ချက်ပေးခြင်း",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "မှတ်ချက်ထည့်ပါ။",
"ui.lineComment.add": "မှတ်ချက်ထည့်ပါ။",
"ui.lineComment.actions": "ရွေးချယ်မှု လုပ်ဆောင်ချက်များ",
"ui.lineComment.contextPlaceholder": "ဤပြောင်းလဲမှုအတွက် အကြောင်းအရာကို ထည့်ပါ။",
"ui.lineComment.submit": "မှတ်ချက်",
"ui.lineComment.cancel": "မလုပ်တော့",
+2
View File
@@ -50,6 +50,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "टिप्पणी गर्दै",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "टिप्पणी थप्नुहोस्",
"ui.lineComment.add": "टिप्पणी थप्नुहोस्",
"ui.lineComment.actions": "चयनका कार्यहरू",
"ui.lineComment.contextPlaceholder": "यो परिवर्तनको लागि सन्दर्भ थप्नुहोस्",
"ui.lineComment.submit": "टिप्पणी गर्नुहोस्",
"ui.lineComment.cancel": "रद्द गर्नुहोस्",
+2
View File
@@ -85,6 +85,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Opmerking bij ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Opmerking toevoegen",
"ui.lineComment.add": "Opmerking toevoegen",
"ui.lineComment.actions": "Selectieacties",
"ui.lineComment.contextPlaceholder": "Context voor deze wijziging toevoegen",
"ui.lineComment.submit": "Opmerking plaatsen",
"ui.lineComment.cancel": "Annuleren",
+2
View File
@@ -72,6 +72,8 @@ export const dict: Record<Keys, string> = {
"ui.lineComment.editorLabel.prefix": "Kommentar til ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Legg til kommentar",
"ui.lineComment.add": "Legg til kommentar",
"ui.lineComment.actions": "Markeringshandlinger",
"ui.lineComment.contextPlaceholder": "Legg til kontekst for denne endringen",
"ui.lineComment.submit": "Kommenter",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "ایتھے تبصرہ ہو رہیا اے: ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "تبصرہ شامل کرو",
"ui.lineComment.add": "تبصرہ شامل کرو",
"ui.lineComment.actions": "انتخاب دیاں کارروائیاں",
"ui.lineComment.contextPlaceholder": "اس تبدیلی لئی تناظر شامل کرو",
"ui.lineComment.submit": "تبصرہ کرو",
"ui.lineComment.cancel": "منسوخ کرو",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Komentowanie: ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Dodaj komentarz",
"ui.lineComment.add": "Dodaj komentarz",
"ui.lineComment.actions": "Akcje zaznaczenia",
"ui.lineComment.contextPlaceholder": "Dodaj kontekst tej zmiany",
"ui.lineComment.submit": "Skomentuj",
"ui.lineComment.cancel": "Anuluj",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Se comentează la",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Adaugă comentariu",
"ui.lineComment.add": "Adaugă comentariu",
"ui.lineComment.actions": "Acțiuni pentru selecție",
"ui.lineComment.contextPlaceholder": "Adaugă context pentru această modificare",
"ui.lineComment.submit": "Comentează",
"ui.lineComment.cancel": "Renunță",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Комментирование: ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Добавить комментарий",
"ui.lineComment.add": "Добавить комментарий",
"ui.lineComment.actions": "Действия с выделенным",
"ui.lineComment.contextPlaceholder": "Добавить контекст для этого изменения",
"ui.lineComment.submit": "Добавить комментарий",
"ui.lineComment.cancel": "Отмена",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "අදහස් දක්වමින්",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "අදහස් එක් කරන්න",
"ui.lineComment.add": "අදහස් එක් කරන්න",
"ui.lineComment.actions": "තේරීම් ක්‍රියා",
"ui.lineComment.contextPlaceholder": "මෙම වෙනස සඳහා සන්දර්භය එක් කරන්න",
"ui.lineComment.submit": "අදහස් දක්වන්න",
"ui.lineComment.cancel": "අවලංගු කරන්න",
+2
View File
@@ -76,6 +76,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Komentujete",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Pridať komentár",
"ui.lineComment.add": "Pridať komentár",
"ui.lineComment.actions": "Akcie výberu",
"ui.lineComment.contextPlaceholder": "Pridať kontext k tejto zmene",
"ui.lineComment.submit": "Komentovať",
"ui.lineComment.cancel": "Zrušiť",
+2
View File
@@ -77,6 +77,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Komentiranje ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Dodaj komentar",
"ui.lineComment.add": "Dodaj komentar",
"ui.lineComment.actions": "Dejanja izbora",
"ui.lineComment.contextPlaceholder": "Dodajte kontekst za to spremembo",
"ui.lineComment.submit": "Komentiraj",
"ui.lineComment.cancel": "Prekliči",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Duke komentuar ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Shto koment",
"ui.lineComment.add": "Shto koment",
"ui.lineComment.actions": "Veprimet e përzgjedhjes",
"ui.lineComment.contextPlaceholder": "Shto kontekst për këtë ndryshim",
"ui.lineComment.submit": "Komentoni",
"ui.lineComment.cancel": "Anulo",
+2
View File
@@ -63,6 +63,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "коментаришем",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Додајте коментар",
"ui.lineComment.add": "Додајте коментар",
"ui.lineComment.actions": "Радње избора",
"ui.lineComment.contextPlaceholder": "Додајте контекст за ову промену",
"ui.lineComment.submit": "Коментар",
"ui.lineComment.cancel": "Откажи",
+2
View File
@@ -85,6 +85,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Kommenterar ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Lägg till kommentar",
"ui.lineComment.add": "Lägg till kommentar",
"ui.lineComment.actions": "Markeringsåtgärder",
"ui.lineComment.contextPlaceholder": "Lägg till kontext för den här ändringen",
"ui.lineComment.submit": "Kommentera",
"ui.lineComment.cancel": "Avbryt",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Шарҳ дар бораи",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Иловаи шарҳ",
"ui.lineComment.add": "Иловаи шарҳ",
"ui.lineComment.actions": "Амалҳои интихоб",
"ui.lineComment.contextPlaceholder": "Барои ин тағирот контекст илова кунед",
"ui.lineComment.submit": "Шарҳ",
"ui.lineComment.cancel": "Бекор кардан",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "กำลังแสดงความคิดเห็นที่ ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "เพิ่มความคิดเห็น",
"ui.lineComment.add": "เพิ่มความคิดเห็น",
"ui.lineComment.actions": "การดำเนินการกับส่วนที่เลือก",
"ui.lineComment.contextPlaceholder": "เพิ่มบริบทสำหรับการเปลี่ยนแปลงนี้",
"ui.lineComment.submit": "แสดงความคิดเห็น",
"ui.lineComment.cancel": "ยกเลิก",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Düşündiriş ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Teswir goşuň",
"ui.lineComment.add": "Teswir goşuň",
"ui.lineComment.actions": "Saýlaw amallary",
"ui.lineComment.contextPlaceholder": "Bu üýtgeşmäniň mazmunyny goşuň",
"ui.lineComment.submit": "Düşündiriş",
"ui.lineComment.cancel": "Elatyr",
+2
View File
@@ -55,6 +55,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Yorum yapılıyor: ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Yorum ekle",
"ui.lineComment.add": "Yorum ekle",
"ui.lineComment.actions": "Seçim eylemleri",
"ui.lineComment.contextPlaceholder": "Bu değişiklik için bağlam ekle",
"ui.lineComment.submit": "Yorum yap",
"ui.lineComment.cancel": "İptal",
+2
View File
@@ -79,6 +79,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Коментування: ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Додати коментар",
"ui.lineComment.add": "Додати коментар",
"ui.lineComment.actions": "Дії з виділеним",
"ui.lineComment.contextPlaceholder": "Додати контекст для цієї зміни",
"ui.lineComment.submit": "Коментувати",
"ui.lineComment.cancel": "Скасувати",
+2
View File
@@ -49,6 +49,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "اس پر تبصرہ کیا جا رہا ہے: ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "تبصرہ شامل کریں۔",
"ui.lineComment.add": "تبصرہ شامل کریں۔",
"ui.lineComment.actions": "انتخاب کی کارروائیاں",
"ui.lineComment.contextPlaceholder": "اس تبدیلی کا سیاق و سباق شامل کریں",
"ui.lineComment.submit": "تبصرہ کریں",
"ui.lineComment.cancel": "منسوخ کریں۔",
+2
View File
@@ -50,6 +50,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Fikr bildirish ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Fikr qo'shing",
"ui.lineComment.add": "Fikr qo'shing",
"ui.lineComment.actions": "Tanlov amallari",
"ui.lineComment.contextPlaceholder": "Ushbu o'zgarish uchun kontekst qo'shing",
"ui.lineComment.submit": "Izoh",
"ui.lineComment.cancel": "Bekor qilish",
+2
View File
@@ -48,6 +48,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "Bình luận về ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "Thêm nhận xét",
"ui.lineComment.add": "Thêm nhận xét",
"ui.lineComment.actions": "Thao tác với phần đã chọn",
"ui.lineComment.contextPlaceholder": "Thêm ngữ cảnh cho thay đổi này",
"ui.lineComment.submit": "Bình luận",
"ui.lineComment.cancel": "Hủy",
+2
View File
@@ -53,6 +53,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "正在评论",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "添加评论",
"ui.lineComment.add": "添加评论",
"ui.lineComment.actions": "选择操作",
"ui.lineComment.contextPlaceholder": "添加此更改的上下文",
"ui.lineComment.submit": "发布评论",
"ui.lineComment.cancel": "取消",
+2
View File
@@ -53,6 +53,8 @@ export const dict = {
"ui.lineComment.editorLabel.prefix": "正在留言於 ",
"ui.lineComment.editorLabel.suffix": "",
"ui.lineComment.placeholder": "新增留言",
"ui.lineComment.add": "新增留言",
"ui.lineComment.actions": "選取操作",
"ui.lineComment.contextPlaceholder": "新增此變更的相關資訊",
"ui.lineComment.submit": "留言",
"ui.lineComment.cancel": "取消",