fix(app): line selection ux fixes

This commit is contained in:
adamelmore
2026-01-24 12:19:39 -06:00
parent fa1a54ba3d
commit 42b802b688
5 changed files with 57 additions and 22 deletions

View File

@@ -66,28 +66,16 @@ export function Code<T>(props: CodeProps<T>) {
"selectedLines", "selectedLines",
"commentedLines", "commentedLines",
"onRendered", "onRendered",
"onLineSelectionEnd",
]) ])
const [rendered, setRendered] = createSignal(0) const [rendered, setRendered] = createSignal(0)
const handleLineClick: FileOptions<T>["onLineClick"] = (info) => {
props.onLineClick?.(info)
if (props.enableLineSelection !== true) return
if (info.numberColumn) return
if (!local.selectedLines) return
file().setSelectedLines(null)
}
const file = createMemo( const file = createMemo(
() => () =>
new File<T>( new File<T>(
{ {
...createDefaultOptions<T>("unified"), ...createDefaultOptions<T>("unified"),
...others, ...others,
onLineClick: props.enableLineSelection === true || props.onLineClick ? handleLineClick : undefined,
}, },
getWorkerPool("unified"), getWorkerPool("unified"),
), ),
@@ -332,12 +320,21 @@ export function Code<T>(props: CodeProps<T>) {
if (props.enableLineSelection !== true) return if (props.enableLineSelection !== true) return
if (dragStart === undefined) return if (dragStart === undefined) return
if (dragMoved) { if (!dragMoved) {
pendingSelectionEnd = true pendingSelectionEnd = false
scheduleDragUpdate() const line = dragStart
scheduleSelectionUpdate() setSelectedLines({ start: line, end: line })
props.onLineSelectionEnd?.(lastSelection)
dragStart = undefined
dragEnd = undefined
dragMoved = false
return
} }
pendingSelectionEnd = true
scheduleDragUpdate()
scheduleSelectionUpdate()
dragStart = undefined dragStart = undefined
dragEnd = undefined dragEnd = undefined
dragMoved = false dragMoved = false

View File

@@ -35,6 +35,13 @@ function findSide(node: Node | null): SelectionSide | undefined {
const element = findElement(node) const element = findElement(node)
if (!element) return if (!element) return
const line = element.closest("[data-line], [data-alt-line]")
if (line instanceof HTMLElement) {
const type = line.dataset.lineType
if (type === "change-deletion") return "deletions"
if (type === "change-addition" || type === "change-additions") return "additions"
}
const code = element.closest("[data-code]") const code = element.closest("[data-code]")
if (!(code instanceof HTMLElement)) return if (!(code instanceof HTMLElement)) return
@@ -303,6 +310,12 @@ export function Diff<T>(props: DiffProps<T>) {
numberColumn = numberColumn || item.dataset.columnNumber != null numberColumn = numberColumn || item.dataset.columnNumber != null
if (side === undefined) {
const type = item.dataset.lineType
if (type === "change-deletion") side = "deletions"
if (type === "change-addition" || type === "change-additions") side = "additions"
}
if (side === undefined && item.dataset.code != null) { if (side === undefined && item.dataset.code != null) {
side = item.hasAttribute("data-deletions") ? "deletions" : "additions" side = item.hasAttribute("data-deletions") ? "deletions" : "additions"
} }
@@ -364,12 +377,28 @@ export function Diff<T>(props: DiffProps<T>) {
if (props.enableLineSelection !== true) return if (props.enableLineSelection !== true) return
if (dragStart === undefined) return if (dragStart === undefined) return
if (dragMoved) { if (!dragMoved) {
pendingSelectionEnd = true pendingSelectionEnd = false
scheduleDragUpdate() const line = dragStart
scheduleSelectionUpdate() const selected: SelectedLineRange = {
start: line,
end: line,
}
if (dragSide) selected.side = dragSide
setSelectedLines(selected)
props.onLineSelectionEnd?.(lastSelection)
dragStart = undefined
dragEnd = undefined
dragSide = undefined
dragEndSide = undefined
dragMoved = false
return
} }
pendingSelectionEnd = true
scheduleDragUpdate()
scheduleSelectionUpdate()
dragStart = undefined dragStart = undefined
dragEnd = undefined dragEnd = undefined
dragSide = undefined dragSide = undefined

View File

@@ -13,7 +13,7 @@
justify-content: center; justify-content: center;
background: var(--icon-interactive-base); background: var(--icon-interactive-base);
box-shadow: var(--shadow-xs); box-shadow: var(--shadow-xs);
cursor: pointer; cursor: default;
border: none; border: none;
} }

View File

@@ -618,7 +618,7 @@ export const SessionReview = (props: SessionReviewProps) => {
/> />
<div data-slot="session-review-comment-actions"> <div data-slot="session-review-comment-actions">
<div data-slot="session-review-comment-draft-label"> <div data-slot="session-review-comment-draft-label">
Commenting on {getFilename(diff.file)}:{selectionLabel(range())} Commenting on {selectionLabel(range())}
</div> </div>
<Button size="small" variant="ghost" onClick={() => setCommenting(null)}> <Button size="small" variant="ghost" onClick={() => setCommenting(null)}>
Cancel Cancel

View File

@@ -87,6 +87,15 @@ const unsafeCSS = `
} }
[data-column-number] { [data-column-number] {
background-color: var(--background-stronger); background-color: var(--background-stronger);
cursor: default !important;
}
&[data-interactive-line-numbers] [data-column-number] {
cursor: default !important;
}
&[data-interactive-lines] [data-line] {
cursor: auto !important;
} }
[data-code] { [data-code] {
overflow-x: auto !important; overflow-x: auto !important;