Skip to content

mac editor: text typed at the edge of the painted window is coloured (#280) - #309

Merged
GoKubar merged 3 commits into
mainfrom
agent/daniel-vpclaude/editor-first-focus
Sep 14, 2026
Merged

GoKubar merged 3 commits into
mainfrom
agent/daniel-vpclaude/editor-first-focus

Conversation

@d-q222

@d-q222 d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Fixes the syntax-colouring half of #280. Lane daniel-vpclaude (Claude Pro, mac-m5pro-dq222), allocated by the Commander on #2 at 04:53Z. Based on main 9bd4b025. Test-merges cleanly on top of #236 + #245.

Measured cause

SyntaxPainter keeps painted ranges, the text whose temporary colours match the highlighter. After an edit, flush() repaints only painted ∩ dirty. SyntaxPainter.shifted treated an edit that starts exactly at a painted range's end (or ends exactly at its start) as outside the range. So text typed at either edge never entered painted and was never coloured. It only got coloured when something else repainted it:

  • a scroll (scrolled() fills gaps), which is the owner's "eventually comes";
  • a document switch, whose text reset repaints the window, which is "click another file and back".

Reproduction: the whole ContentView hosted like the app, with the fixture startup document (no File ▸ Open, as in the owner's repro context) and the caret at the end. Typing \se left painted == [{0, 16}] over a 20-character text, with 0 colour runs, while the highlighter held 1 run for \se.

Fix

shifted uses strict comparisons, so a touching edit joins the range. The existing union branch already gives the right result for touching insertions and deletions, and 8 cases are pinned in a unit test. The function also becomes internal so the test can call it.

Tests: EditorFirstFocusTests

test without fix with fix
testPaintedRangeAbsorbsEditsAtItsEdges (8 edge cases) fails passes
testStartupDocumentInContentViewIsColouredAndCompletes fails passes
3 first-focus probes (bare editor before/after mount, whole ContentView after ⌘O-style open): colours + a real \se completion session, no document switch pass pass

"Without fix" was verified by reverting only SyntaxHighlighter.swift.

Full swift test: 1063 tests, 133 skipped. The only failures were 2 tests in WordCountModelTests (3 assertion failures), which timed out at about 2 s under full-suite load and pass in isolation (0.03 s each). They're unrelated to this change. #256's two known failures didn't appear.

Not fixed / open

🤖 Generated with Claude Code

https://claude.ai/code/session_012iWhnaQddU1UTMh6ZssGBJ

…itch (GH#280, probe)

The regression tests #280 asks for. Each opens a document into a fresh editor
with no document switch, then asserts that
(a) the text carries syntax-colour temporary attributes,
(b) typing \se through keyDown requests the list once and a real completion
    session opens, and
(c) the typed command is coloured.

Three hostings:
- the bare SourceEditorView with the document present before mount;
- the bare SourceEditorView with the document opened after mount;
- the whole ContentView at the app's 1200x640 minimum size.

All three pass on main 9bd4b02, so the owner's report does NOT reproduce
under hosted conditions. Since the reported 8a5ac44 build, only 0f8ba91
(#300, popup appearance) has touched the editor sources. Ruled out by
reading the code: view identity (EditorPane has no .id), the empty
visible-window paint (window(for:) paints everything without a window), and
diagnostic marks clearing the colours (MarkPainter removes only
underline/tooltip keys). What remains differs between these tests and the
bundled app: a key/active window, an attached producer delivering compile
results, launch-time session/seed paths, and preferences such as Vim
keybindings. Findings and questions are on #280.

Implementation-Agent: daniel-vpclaude (Claude Code, Claude Pro plan)
Commit-Executor: daniel-vpclaude, direct git (Cursor-limit fallback)
Co-authored-by: d-q222 <[email protected]>

Claude-Session: https://claude.ai/code/session_012iWhnaQddU1UTMh6ZssGBJ
…(GH#280)

Measured cause. SyntaxPainter tracks `painted` ranges, the text whose
temporary colours match the highlighter, and an edit's flush repaints only
`painted ∩ dirty`. Its range arithmetic treated an edit that starts exactly at
a painted range's end, or ends exactly at its start, as outside the range.
Text typed at either edge was therefore never inside `painted` and never
coloured. It only turned colour when something else repainted: a scroll, or a
document switch, whose text reset repaints the window. That is the owner's
"eventually comes" and "click another file and back".

The startup document shows it directly. In the whole ContentView hosted like
the app, with the caret at the end of the fixture text, typing " \se" left
painted == [{0, 16}] over a 20-character text with 0 colour runs, while the
highlighter held 1 run for \se.

Fix: `shifted` joins edits that touch a range, using strict comparisons. The
existing union branch already yields the right range for touching insertions
and deletions; the new unit test pins eight cases.

Tests (EditorFirstFocusTests):
- testPaintedRangeAbsorbsEditsAtItsEdges and
  testStartupDocumentInContentViewIsColouredAndCompletes FAIL without this
  change and pass with it (verified by reverting only the source file);
- the three earlier first-focus probes still pass.
The completion half of the report did not reproduce: the list opens on first
focus in every hosting. The owner's non-activating launch (window never key)
is still to be checked in the real app.

Implementation-Agent: daniel-vpclaude (Claude Code, Claude Pro plan)
Commit-Executor: daniel-vpclaude, direct git (Cursor-limit fallback)
Co-authored-by: d-q222 <[email protected]>

Claude-Session: https://claude.ai/code/session_012iWhnaQddU1UTMh6ZssGBJ
…w event dispatch)

Skipped unless FLASHTEX_FOCUS_PROBE=1 because it takes keyboard focus. It
hosts the whole ContentView in a window that was only ordered back, as in the
owner's non-activating launch, then sends a real mouse click and real keyDown
events through NSWindow.sendEvent.

With #309 on this branch, the click gives the editor first responder (the
window is still not key), the keys insert, typing \se opens a session, the
CompletionPopup child window is visible, and the command is coloured. So
completion on first focus does not reproduce through the real event path
either. Left to check: app activation from an open -g launch, which a test
process cannot emulate.

Implementation-Agent: daniel-vpclaude (Claude Code, Claude Pro plan)
Commit-Executor: daniel-vpclaude, direct git (Cursor-limit fallback)
Co-authored-by: d-q222 <[email protected]>

Claude-Session: https://claude.ai/code/session_012iWhnaQddU1UTMh6ZssGBJ
@d-q222

d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Update (eb63f61d): I added a local-only focus probe (FLASHTEX_FOCUS_PROBE=1). It hosts the whole ContentView in an ordered-back, never-key window, like the owner's open -g launch, then sends a real mouse click and real keyDown events through NSWindow.sendEvent. With this PR, the click gives the editor first responder, the keys insert, \se opens a session, the CompletionPopup child window is visible, and the command is coloured. By default the probe is skipped, so CI never takes focus.

@d-q222

d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent Mac pre-merge verification (for the integration lane, which has no Swift toolchain). Xcode 26.6, macOS 26.6, merged onto origin/main 98ca402a in a throwaway worktree, PR head eb63f61d. Worker: Cursor; results checked by daniel-parent.

PR merge filtered tests full suite verdict
#309 CLEAN 6 / 1 skipped / 0 fail 1064 / 138 skipped / 3 fail (pre-existing WordCount) READY

About the 3 full-suite failures: WordCountModelTests.testOnlyTheLastScheduledUpdateWins and testScheduleUpdateEventuallyPublishesTotals fail in every full run, including the control on main, while the machine is loaded. Run alone on main 095e8406 they pass twice (2/0), so they're timing-flaky under full-suite load, not caused by this PR or broken on main.

@GoKubar
GoKubar merged commit 319e6e2 into main Sep 14, 2026
18 of 20 checks passed
@GoKubar
GoKubar deleted the agent/daniel-vpclaude/editor-first-focus branch September 14, 2026 14:49
ItsAkilesh pushed a commit to ItsAkilesh/flashtex that referenced this pull request Sep 18, 2026
…us (flash-tex#280)

What changed:
- `EditorFirstFocusTests.testSeededStartupDocumentIsColouredAndCompletesAtFirstFocus`:
  hosts the whole `ContentView` in a never-key window over a `ShellModel` built
  the way the app builds one at launch with a real `.tex` already open
  (`FLASHTEX_SEED_FILE`), then asserts the text is coloured with no keystroke
  and no document switch, and that typing `\se` opens the list.
- This shape had no coverage. The existing startup test loads the
  `protocol/fixtures` request, whose text is `Hello FlashTeX.` -- it holds no
  LaTeX token, so it can only assert that *typed* text gets coloured, never
  that the document the editor opened with is coloured. That is precisely what
  flash-tex#280 reported.
- No production change: the behaviour flash-tex#280 describes no longer reproduces
  (measured below); flash-tex#309 fixed the colouring half and the completion half opens
  on every hosting tried.
- The completion half is guarded by `XCTSkipIf(Completion.defaultSupported.isEmpty)`
  naming flash-tex#704, so when the bundled inventory does not reach the test bundle this
  says so instead of failing as an opaque "timed out waiting for the list". The
  colouring assertion runs unconditionally -- it needs no inventory.

What was run:
  swift test --filter 'EditorFirstFocusTests|SourceEditorViewTests|AutomaticCompletionTests'
    Executed 37 tests, with 1 test skipped and 0 failures (0 unexpected) in 5.459 seconds
  swift test --filter 'EditorFirstFocusTests'   (new test, alone)
    Test Case '-[FlashTeXMacTests.EditorFirstFocusTests testSeededStartupDocumentIsColouredAndCompletesAtFirstFocus]' passed (0.136 seconds)
    Executed 8 tests, with 1 test skipped and 0 failures (0 unexpected) in 1.252 seconds
  Same, with the bundled inventory removed from the test bundle (flash-tex#704's state):
    Test Case '-[...testSeededStartupDocumentIsColouredAndCompletesAtFirstFocus]' skipped (0.113 seconds)
    (the colouring assertion ran and passed before the skip)

  flash-tex#280 measurement, instrumented run of the owner's repro shape:
    PROBE seed: docs=["hw1.tex"] text="\documentclass{article}\n\begin{document}\n\section{Intro} Some $x^2$ text.\n\n\end{document}\n"
    PROBE seed: colourRuns at first focus=19
    PROBE seed: after typing colourRuns=22 before=19 autoOpen=1 active=true items=Optional(10)

Next step:
- flash-tex#280's residual symptom in any non-packaged build is flash-tex#704 (the completion
  vocabulary not reaching the bundle), which is separately claimed.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants