GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(app): line selection styling · bpd1069/opencode@9a89cd9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/ui/src
    • components
      • diff-ssr.tsx
      • diff.tsx
    • pierre
      • index.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/ui/src/components/diff-ssr.tsx‎

Copy file name to clipboardExpand all lines: packages/ui/src/components/diff-ssr.tsx
+70-14Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ export function Diff<T>(props: SSRDiffProps<T>) {
2929
const getRoot = () => fileDiffRef?.shadowRoot ?? undefined
3030

3131
const findSide = (element: HTMLElement): "additions" | "deletions" => {
32+
const line = element.closest("[data-line], [data-alt-line]")
33+
if (line instanceof HTMLElement) {
34+
const type = line.dataset.lineType
35+
if (type === "change-deletion") return "deletions"
36+
if (type === "change-addition" || type === "change-additions") return "additions"
37+
}
38+
3239
const code = element.closest("[data-code]")
3340
if (!(code instanceof HTMLElement)) return "additions"
34-
if (code.hasAttribute("data-deletions")) return "deletions"
35-
return "additions"
41+
return code.hasAttribute("data-deletions") ? "deletions" : "additions"
3642
}
3743

3844
const applyCommentedLines = (ranges: SelectedLineRange[]) => {
@@ -45,19 +51,69 @@ export function Diff<T>(props: SSRDiffProps<T>) {
4551
node.removeAttribute("data-comment-selected")
4652
}
4753

54+
const diffs = root.querySelector("[data-diffs]")
55+
if (!(diffs instanceof HTMLElement)) return
56+
57+
const split = diffs.dataset.type === "split"
58+
59+
const code = Array.from(diffs.querySelectorAll("[data-code]")).filter(
60+
(node): node is HTMLElement => node instanceof HTMLElement,
61+
)
62+
if (code.length === 0) return
63+
64+
const lineIndex = (element: HTMLElement) => {
65+
const raw = element.dataset.lineIndex
66+
if (!raw) return
67+
const values = raw
68+
.split(",")
69+
.map((value) => parseInt(value, 10))
70+
.filter((value) => !Number.isNaN(value))
71+
if (values.length === 0) return
72+
if (!split) return values[0]
73+
if (values.length === 2) return values[1]
74+
return values[0]
75+
}
76+
77+
const rowIndex = (line: number, side: "additions" | "deletions" | undefined) => {
78+
const nodes = Array.from(root.querySelectorAll(`[data-line="${line}"], [data-alt-line="${line}"]`)).filter(
79+
(node): node is HTMLElement => node instanceof HTMLElement,
80+
)
81+
if (nodes.length === 0) return
82+
83+
const targetSide = side ?? "additions"
84+
85+
for (const node of nodes) {
86+
if (findSide(node) === targetSide) return lineIndex(node)
87+
if (parseInt(node.dataset.altLine ?? "", 10) === line) return lineIndex(node)
88+
}
89+
}
90+
4891
for (const range of ranges) {
49-
const start = Math.max(1, Math.min(range.start, range.end))
50-
const end = Math.max(range.start, range.end)
51-
52-
for (let line = start; line <= end; line++) {
53-
const expectedSide =
54-
line === end ? (range.endSide ?? range.side) : line === start ? range.side : (range.side ?? range.endSide)
55-
56-
const nodes = Array.from(root.querySelectorAll(`[data-line="${line}"], [data-alt-line="${line}"]`))
57-
for (const node of nodes) {
58-
if (!(node instanceof HTMLElement)) continue
59-
if (expectedSide && findSide(node) !== expectedSide) continue
60-
node.setAttribute("data-comment-selected", "")
92+
const start = rowIndex(range.start, range.side)
93+
if (start === undefined) continue
94+
95+
const end = (() => {
96+
const same = range.end === range.start && (range.endSide == null || range.endSide === range.side)
97+
if (same) return start
98+
return rowIndex(range.end, range.endSide ?? range.side)
99+
})()
100+
if (end === undefined) continue
101+
102+
const first = Math.min(start, end)
103+
const last = Math.max(start, end)
104+
105+
for (const block of code) {
106+
for (const element of Array.from(block.children)) {
107+
if (!(element instanceof HTMLElement)) continue
108+
const idx = lineIndex(element)
109+
if (idx === undefined) continue
110+
if (idx > last) break
111+
if (idx < first) continue
112+
element.setAttribute("data-comment-selected", "")
113+
const next = element.nextSibling
114+
if (next instanceof HTMLElement && next.hasAttribute("data-line-annotation")) {
115+
next.setAttribute("data-comment-selected", "")
116+
}
61117
}
62118
}
63119
}
Collapse file

‎packages/ui/src/components/diff.tsx‎

Copy file name to clipboardExpand all lines: packages/ui/src/components/diff.tsx
+59-14Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,24 +191,69 @@ export function Diff<T>(props: DiffProps<T>) {
191191
node.removeAttribute("data-comment-selected")
192192
}
193193

194-
for (const range of ranges) {
195-
const start = Math.max(1, Math.min(range.start, range.end))
196-
const end = Math.max(range.start, range.end)
194+
const diffs = root.querySelector("[data-diffs]")
195+
if (!(diffs instanceof HTMLElement)) return
196+
197+
const split = diffs.dataset.type === "split"
198+
199+
const code = Array.from(diffs.querySelectorAll("[data-code]")).filter(
200+
(node): node is HTMLElement => node instanceof HTMLElement,
201+
)
202+
if (code.length === 0) return
203+
204+
const lineIndex = (element: HTMLElement) => {
205+
const raw = element.dataset.lineIndex
206+
if (!raw) return
207+
const values = raw
208+
.split(",")
209+
.map((value) => parseInt(value, 10))
210+
.filter((value) => !Number.isNaN(value))
211+
if (values.length === 0) return
212+
if (!split) return values[0]
213+
if (values.length === 2) return values[1]
214+
return values[0]
215+
}
197216

198-
for (let line = start; line <= end; line++) {
199-
const expectedSide =
200-
line === end ? (range.endSide ?? range.side) : line === start ? range.side : (range.side ?? range.endSide)
217+
const rowIndex = (line: number, side: SelectionSide | undefined) => {
218+
const nodes = Array.from(root.querySelectorAll(`[data-line="${line}"], [data-alt-line="${line}"]`)).filter(
219+
(node): node is HTMLElement => node instanceof HTMLElement,
220+
)
221+
if (nodes.length === 0) return
201222

202-
const nodes = Array.from(root.querySelectorAll(`[data-line="${line}"], [data-alt-line="${line}"]`))
203-
for (const node of nodes) {
204-
if (!(node instanceof HTMLElement)) continue
223+
const targetSide = side ?? "additions"
205224

206-
if (expectedSide) {
207-
const side = findSide(node)
208-
if (side && side !== expectedSide) continue
209-
}
225+
for (const node of nodes) {
226+
if (findSide(node) === targetSide) return lineIndex(node)
227+
if (parseInt(node.dataset.altLine ?? "", 10) === line) return lineIndex(node)
228+
}
229+
}
210230

211-
node.setAttribute("data-comment-selected", "")
231+
for (const range of ranges) {
232+
const start = rowIndex(range.start, range.side)
233+
if (start === undefined) continue
234+
235+
const end = (() => {
236+
const same = range.end === range.start && (range.endSide == null || range.endSide === range.side)
237+
if (same) return start
238+
return rowIndex(range.end, range.endSide ?? range.side)
239+
})()
240+
if (end === undefined) continue
241+
242+
const first = Math.min(start, end)
243+
const last = Math.max(start, end)
244+
245+
for (const block of code) {
246+
for (const element of Array.from(block.children)) {
247+
if (!(element instanceof HTMLElement)) continue
248+
const idx = lineIndex(element)
249+
if (idx === undefined) continue
250+
if (idx > last) break
251+
if (idx < first) continue
252+
element.setAttribute("data-comment-selected", "")
253+
const next = element.nextSibling
254+
if (next instanceof HTMLElement && next.hasAttribute("data-line-annotation")) {
255+
next.setAttribute("data-comment-selected", "")
256+
}
212257
}
213258
}
214259
}
Collapse file

‎packages/ui/src/pierre/index.ts‎

Copy file name to clipboardExpand all lines: packages/ui/src/pierre/index.ts
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ const unsafeCSS = `
4444
background-color: var(--diffs-bg-selection-text);
4545
}
4646
47-
[data-diffs] [data-comment-selected] {
48-
background-color: var(--diffs-bg-selection);
47+
[data-diffs] [data-comment-selected]:not([data-selected-line]) [data-column-content] {
48+
box-shadow: inset 0 0 0 9999px var(--diffs-bg-selection);
4949
}
5050
51-
[data-diffs] [data-comment-selected] [data-column-number] {
52-
background-color: var(--diffs-bg-selection-number);
51+
[data-diffs] [data-comment-selected]:not([data-selected-line]) [data-column-number] {
52+
box-shadow: inset 0 0 0 9999px var(--diffs-bg-selection-number);
5353
color: var(--diffs-selection-number-fg);
5454
}
5555
@@ -73,7 +73,7 @@ const unsafeCSS = `
7373
/* The deletion word-diff emphasis is stronger than additions; soften it while selected so the selection highlight reads consistently. */
7474
[data-diffs] [data-line-type='change-deletion'][data-selected-line] {
7575
--diffs-bg-deletion-emphasis: light-dark(
76-
rgb(from var(--diffs-deletion-base) r g b / 0.15),
76+
rgb(from var(--diffs-deletion-base) r g b / 0.07),
7777
rgb(from var(--diffs-deletion-base) r g b / 0.1)
7878
);
7979
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.