fix(app): line selection ux

This commit is contained in:
adamelmore
2026-01-24 12:40:45 -06:00
parent 42b802b688
commit d90b4c9ebd

View File

@@ -131,18 +131,23 @@ function findSide(element: HTMLElement): "additions" | "deletions" {
} }
function findMarker(root: ShadowRoot, range: SelectedLineRange) { function findMarker(root: ShadowRoot, range: SelectedLineRange) {
const line = Math.max(range.start, range.end) const marker = (line: number, side?: "additions" | "deletions") => {
const side = range.endSide ?? range.side
const nodes = Array.from(root.querySelectorAll(`[data-line="${line}"], [data-alt-line="${line}"]`)).filter( const nodes = Array.from(root.querySelectorAll(`[data-line="${line}"], [data-alt-line="${line}"]`)).filter(
(node): node is HTMLElement => node instanceof HTMLElement, (node): node is HTMLElement => node instanceof HTMLElement,
) )
if (nodes.length === 0) return if (nodes.length === 0) return
if (!side) return nodes[0] if (!side) return nodes[0]
const match = nodes.find((node) => findSide(node) === side) const match = nodes.find((node) => findSide(node) === side)
return match ?? nodes[0] return match ?? nodes[0]
} }
const a = marker(range.start, range.side)
const b = marker(range.end, range.endSide ?? range.side)
if (!a) return b
if (!b) return a
return a.getBoundingClientRect().top > b.getBoundingClientRect().top ? a : b
}
function markerTop(wrapper: HTMLElement, marker: HTMLElement) { function markerTop(wrapper: HTMLElement, marker: HTMLElement) {
const wrapperRect = wrapper.getBoundingClientRect() const wrapperRect = wrapper.getBoundingClientRect()
const rect = marker.getBoundingClientRect() const rect = marker.getBoundingClientRect()
@@ -602,6 +607,12 @@ export const SessionReview = (props: SessionReviewProps) => {
value={draft()} value={draft()}
onInput={(e) => setDraft(e.currentTarget.value)} onInput={(e) => setDraft(e.currentTarget.value)}
onKeyDown={(e) => { onKeyDown={(e) => {
if (e.key === "Escape") {
e.preventDefault()
e.stopPropagation()
setCommenting(null)
return
}
if (e.key !== "Enter") return if (e.key !== "Enter") return
if (e.shiftKey) return if (e.shiftKey) return
e.preventDefault() e.preventDefault()