Repository navigation
Highlight the active line in the code editor - #266
ArthurArthurArthur0817 wants to merge 1 commit into
Conversation
9f8587c to
b4c154b
Compare
b4c154b to
a10d77b
Compare
There was a problem hiding this comment.
1 issue found across 4 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/browser/editor-font-size.test.js">
<violation number="1" location="tests/browser/editor-font-size.test.js:223">
P2: This scroll assertion only rereads `--active-line`, so it passes even if the gradient scrolls away from line 2. Assert the rendered layers’ scroll behavior, such as their `background-attachment`, or measure the painted row after scrolling.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Re-trigger cubic
| assert.equal( | ||
| await activeLine(), | ||
| "2", | ||
| "highlight stays anchored to its row when scrolled natively", |
There was a problem hiding this comment.
P2: This scroll assertion only rereads --active-line, so it passes even if the gradient scrolls away from line 2. Assert the rendered layers’ scroll behavior, such as their background-attachment, or measure the painted row after scrolling.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/browser/editor-font-size.test.js, line 223:
<comment>This scroll assertion only rereads `--active-line`, so it passes even if the gradient scrolls away from line 2. Assert the rendered layers’ scroll behavior, such as their `background-attachment`, or measure the painted row after scrolling.</comment>
<file context>
@@ -181,3 +181,72 @@ test("a stored size the page does not offer falls back to the default", async (t
+ assert.equal(
+ await activeLine(),
+ "2",
+ "highlight stays anchored to its row when scrolled natively",
+ );
+
</file context>
e3b9a64 to
8539578
Compare
jserv
left a comment
There was a problem hiding this comment.
Rebase the current branch onto the upstream default branch and rework the series into functionally minimal commits, folding similar ones and enforcing the project's commit message rules.
|
@ArthurArthurArthur0817 The
Also restore the final newline that the diff removes from |
8539578 to
ec02814
Compare
During an interview, candidates often navigate long snippets or discuss specific line numbers referenced by the interviewer. Tracking the caret across the editor and gutter without an active-line indicator makes it harder to locate the current row. Set a 0-based --active-line CSS custom property on .editor-stack during paintEditor when the editor is focused with a collapsed selection, and render a linear-gradient across #editor-highlight and #editor-lines without mutating the syntax layer DOM.
ec02814 to
59220fe
Compare
|
I have rebased onto the latest upstream/main (resolving conflicts with the new indent guides and scroll tests) and addressed all feedback: Async Paint Timing in Tests: Integrated page.waitForFunction in editor-font-size.test.js to wait for --active-line to match the expected value before asserting. This resolves the race condition caused by async paint timing after cursor movements and scrolling. Editor Theme Variable Integration: Replaced hardcoded highlight colors with --code-active-line scoped across themes (#ffffff0f for dark mode, #0000000d for light mode under .editor-stack[data-theme="light"] and the prefers-color-scheme: light media query) to align with PR #251. I also restored the final newline in tests/browser/dom-contract.test.js.Thanks for the reminder. |
Don't make statements too early. Continue resolving. |
jserv
left a comment
There was a problem hiding this comment.
Rebase latest main branch and resolve conflicts.
The code editor lacked an active-line indicator, leaving candidates scanning for a thin caret when navigating long snippets or discussing specific line numbers referenced by the interviewer. This made it harder to quickly locate the current row across the editor and the gutter.
When the editor is focused,
paintEditornow computes the 0-based active line from a collapsed selection and exposes it to the.editor-stackas an--active-linecustom property. The syntax overlay and gutter read this property to position a subtlelinear-gradientbackground behind the text. Moving the caret or scrolling the textarea updates the scroll and line position variables accordingly.The CSS approach keeps the syntax layer DOM untouched. Inserting markup for the active row would mutate the
codeoverlay, tripping theMutationObserverthat guarantees single-pass rendering, and breaking the plain-text nature of the gutter. The highlight is cleared completely when the editor loses focus or when a selection range is active, ensuring it only tracks a collapsed caret.Testing:
New tests: the DOM contract test verifies the active line tracks the caret when the editor is focused without a selection, asserting the exact caret conditions in the script and the custom properties in the stylesheet. The test was checked by breaking the strict equality it covers and watching it fail.
node --test tests/browser/dom-contract.test.jswas run on Windows; against the baseline (withCRLFchecked out toLFvia dos2unix) this change adds no failure.Closes #247
Summary by cubic
Highlights the active line in the code editor so candidates can quickly locate the current row while editing or discussing line numbers.
Sets a 0-based
--active-linecustom property on.editor-stackwhen the editor is focused with a collapsed caret. The syntax overlay and gutter paint a subtle gradient behind that line, anchored withbackground-attachment: localso it stays put while scrolling. The highlight clears on blur or while a selection is active. Keeping it in CSS leaves the syntax layer DOM untouched, so theMutationObserverthat guarantees single-pass rendering never trips.Adds an end-to-end test in
tests/browser/editor-font-size.test.jsverifying the highlight tracks the caret, stays anchored while scrolling, and clears on selection or blur.Closes #247
Written for commit 59220fe. Summary will update on new commits.