Skip to content

mac: code folding — environments and sections fold from the gutter or Editor menu - #423

Merged
GoKubar merged 7 commits into
mainfrom
agent/daniel-parent/editor-folding
Sep 14, 2026
Merged

GoKubar merged 7 commits into
mainfrom
agent/daniel-parent/editor-folding

Conversation

@d-q222

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

Copy link
Copy Markdown
Contributor

daniel-parent (Cursor Grok lane GH-EDITOR-FOLDING, reviewed by daniel-parent plus an independent read-only Codex review). Adds code folding to the Mac editor, which had none.

What changes

  • What folds: any \begin…\end pair (from EditorNavigation.environmentPairs) and any sectioning span (from DocumentOutline).
  • Editor ▸ Fold / Unfold / Fold All / Unfold All: ⌥⌘← / ⌥⌘→, and the same with ⇧ for All, as in Xcode. The line-number gutter gains disclosure triangles.
  • How it works:
    • Hidden text stays in NSTextStorage and is drawn as null glyphs plus a "…" marker, so undo, compile and source mapping are unchanged. This uses TextKit 1 glyph hiding.
    • A fold is dropped when an edit overlaps it or a \begin becomes unbalanced.
  • Unfolds on demand: Find, go-to-definition, diagnostics and preview-reveal all unfold their target. Vim j/k skips a fold as one line.
  • Typing cost:
    • The region scan for gutter triangles is debounced 250 ms after typing.
    • SwiftUI updateNSView without a text change does zero region scans (tested).
    • A programmatic text reset (revert, reload, switching documents) rescans, retrying if the highlighter's line table hasn't caught up yet.

Review rounds

  1. A review found a retain cycle (a duplicate onToggleFold closure captured the coordinator strongly) and a whole-buffer rescan on every updateNSView. Both are fixed at 2d9f08b7, and a hosted test checks zero rescans across 8 updates and that the coordinator is released.
  2. The lane owner found that a text reset left the previous document's triangles. Fixed at f4916d09, and a hosted A→B reset test was confirmed failing before the fix: ("[0]") is not equal to ("[2]").

Tests

  • EditorFoldingTests (20), CommandTableTests (8), HostedWindowSupportTests (4): all pass.
  • Full swift test (apps/mac) at f4916d09: Executed 1149 tests, with 135 tests skipped and 0 failures.

Overlap check

Not done

  • Not driven in a live app window; covered by hosted tests.
  • The table-lag retry has no cap. It stops once the highlighter's table length matches, which it always does after a reset, and each retry is only a length check.
  • Fold state isn't persisted across document reopen.

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

d-q222 and others added 4 commits September 14, 2026 09:32
What changed: foldable regions from EditorNavigation.environmentPairs
and DocumentOutline sectioning; folds tracked as shifted ranges that
drop on an overlapping edit or an unbalanced \begin; Editor menu Fold/
Unfold/Fold All/Unfold All (⌘⌥←/→ and with shift); LineNumberGutter
disclosure triangles (the ruler already existed); Find/go-to-definition/
diagnostics/preview reveal unfold the target; vim j/k skip a fold as
one line. Hidden characters stay in NSTextStorage (null glyphs + drawn
“…”), so undo/compile/source-mapping are unchanged.

What was run: `swift test --filter 'EditorFoldingTests|CommandTableTests'`
in apps/mac.
test result: EditorFoldingTests executed 18 tests, with 0 failures
test result: CommandTableTests executed 8 tests, with 0 failures
(Selected tests: Executed 26 tests, with 0 failures)

Next step: full `swift test` in apps/mac; test-merge
origin/agent/daniel-parent/mac-v2-diagnostics before push.

Open questions: none on the fold model. Gutter triangles for unfolded
foldable lines refresh 250ms after typing so region computation is not
per keystroke.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent (this session)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
What changed: dropped the duplicate `onToggleFold` assignment in
`installIntelligence` (it captured the coordinator strongly and
rescanned regions). The gutter still gets the handler once in
`setLineNumbers` with `[weak self]`. `updateNSView` now calls at most
`refreshFoldGutter(rescan: false)` and only when the text actually
reset; marks/diagnostics updates do nothing to fold regions.
`scheduleFoldGutterRefresh` (0.25 s) is already called from
`textDidChange` — kept, not dead. New hosted test: N updateNSView /
`rescan: false` calls with no text change bump `regionComputeCount`
by zero, and a weak coordinator goes nil on teardown.

What was run: `swift test --filter 'EditorFoldingTests|CommandTableTests'`
in apps/mac.
Test Suite 'EditorFoldingTests' passed: Executed 19 tests, with 0 failures
Test Suite 'CommandTableTests' passed: Executed 8 tests, with 0 failures
Selected tests: Executed 27 tests, with 0 failures
Full `swift test` in apps/mac: Executed 1148 tests, with 135 tests skipped
and 0 failures (first full run had 1 failure in HostedWindowSupportTests
because prepare() was not on the line above NSWindow; fixed, re-run green).

Next step: lane owner review; do not merge to main from this worker.

Open questions: none. Debounce is wired from textDidChange.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent (this session)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
What changed: added testTextResetRescansFoldGutterForTheNewDocument. It
installs document A (\begin{itemize} on line 0) then resets the bound
text to document B (\begin{enumerate} on line 2). After debounce /
run-loop, gutter.foldableLines must be B's lines.

What was run: `swift test --filter 'EditorFoldingTests.testTextResetRescansFoldGutterForTheNewDocument'`
in apps/mac.
Test Case failed: XCTAssertEqual ("[0]") is not equal to ("[2]") —
text reset still shows A's fold triangles. Reproduction of the review
gap: updateNSView calls refreshFoldGutter(rescan: false) and no
textDidChange fires, so scheduleFoldGutterRefresh never runs.

Next step: on textReset, invalidate and schedule a rescan (retry if the
highlighter table length does not yet match); keep no-text-change
updateNSView at zero region scans.

Open questions: none.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent (this session)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
What changed: updateNSView on a programmatic string replace now calls
refreshFoldGutter(rescan: true) and scheduleFoldGutterRefresh (made
callable from the representable). textDidChange never fires on
tv.string =, so the previous rescan:false left A's triangles. If the
highlighter line table length does not yet match, the gutter guard
clears triangles and the debounce retries once it matches. Marks-only
updateNSView still does not scan. Hosted test waits for document B's
foldable lines after an ObservableObject text reset.

What was run: `swift test --filter 'EditorFoldingTests|HostedWindowSupportTests'`
in apps/mac.
Test Suite 'EditorFoldingTests' passed: Executed 20 tests, with 0 failures
Test Suite 'HostedWindowSupportTests' passed: Executed 4 tests, with 0 failures
Selected tests: Executed 24 tests, with 0 failures
Full `swift test` in apps/mac: Executed 1149 tests, with 135 tests skipped
and 0 failures.

Next step: lane owner review; do not merge to main from this worker.

Open questions: none.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent (this session)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
d-q222 added a commit that referenced this pull request Sep 14, 2026
SwiftUI makes one top-level menu per CommandMenu("Editor"). The folding
lane (#423) declares its own inside NavigationCommands; the two branches
merge without a git conflict and would show two Editor menus. This source
scan fails unless EditorMenu.swift is the only declaration, so whichever
lands second has to fold its items into EditorMenuCommands.

What was run: swift test --filter EditorMenuTests (apps/mac)
Executed 1 test, with 0 failures

Implementation-Agent: daniel-parent (Claude Code, mac-m5pro-dq222)
Commit-Executor: daniel-parent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent: merge-order note. The line-commands PR adds EditorMenu.swift, the single CommandMenu("Editor"), plus EditorMenuTests, which fails if any other file declares one. Whichever of the two lands second must move this PR's Fold/Unfold items out of NavigationCommands into EditorMenuCommands as a section. I'll do that merge; no action needed from integration.

…ditor-folding

# Conflicts:
#	apps/mac/Sources/FlashTeXAccessibility/AccessibilityCommands.swift
@d-q222

d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent: merged main (#419) and resolved the command-table conflicts in AccessibilityCommands.swift and CommandPalette.swift, keeping both sides. The targeted tests pass apart from 2 CommandTableTests failures that main itself has: #419's Duplicate Line has no README row. #435 fixes that.

…ditor-folding

# Conflicts:
#	apps/mac/Sources/FlashTeXMac/Completion.swift
@d-q222

d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent: merged main after #445. The Completion.swift conflict was two adjacent property blocks: kept both folds and #445's caretFixVisible/dismissCaretFix. Ran swift test --filter 'EditorFoldingTests|EditorCaretFixTests|CommandTableTests|EditorKeyHandlingTests': Executed 58 tests, with 0 failures. CommandTableTests is green again now that #442 carries the README row.

d-q222 added a commit that referenced this pull request Sep 14, 2026
Merged origin/main (includes #413 Re-indent, #419 duplicate line, #442 Vim
status line, #445 caret fix). Conflict in apps/mac/README.md: kept both
the ⌘L Go to Line row (ours) and the ⌃I / Re-indent Document rows (theirs).
AccessibilityCommands.swift and CommandPalette.swift auto-merged with both
enum cases, entries, and palette actions.

Ran: cd apps/mac && swift test --filter 'GoToLineTests|CommandTableTests'
Executed 17 tests, with 0 failures (0 unexpected) in 0.125 (0.126) seconds.
grep -rn '<<<<<<<\|>>>>>>>' apps/mac: empty. README shortcuts unique.

Next: merge origin/main into editor-folding (#423).

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
Merged origin/main (#413 Re-indent plus later Print/duplicate/Vim/caret).
Conflicts:
- apps/mac/README.md: kept Fold/Unfold/Fold All/Unfold All rows and
  ⌃I / Re-indent Document rows.
- AccessibilityCommands.swift: kept fold/unfold/foldAll/unfoldAll cases
  and entries together with reindentLines/reindentDocument.
CommandPalette.swift auto-merged both palette actions.

Ran: cd apps/mac && swift test --filter 'EditorFoldingTests|CommandTableTests|EditorKeyHandlingTests'
Executed 43 tests, with 0 failures (0 unexpected) in 0.438 (0.441) seconds.
grep -rn '<<<<<<<\|>>>>>>>' apps/mac: empty.

Next: merge origin/main into editor-line-commands (#426).

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
@GoKubar
GoKubar merged commit 9d50d31 into main Sep 14, 2026
21 checks passed
@GoKubar
GoKubar deleted the agent/daniel-parent/editor-folding branch September 14, 2026 19:42
d-q222 added a commit that referenced this pull request Sep 14, 2026
…nd folding

#423 declared its own CommandMenu("Editor") (EditorFoldCommands, inside
NavigationCommands), which EditorMenuTests forbids. The fold items are now
FoldMenuItems, a Divider()-separated section of EditorMenuCommands in
EditorMenu.swift, and NavigationCommands no longer adds them. Conflicts:
AccessibilityCommands (both case lists kept) and CommandTableTests.
commandFiles now lists EditorMenu.swift. The shortcut spelling accepts
up/down (line commands) and left/right (folding) arrows.

What was run (apps/mac): swift test --filter 'CommandTableTests|EditorMenuTests|
EditorFoldingTests|EditorLineCommandsTests|EditorLineCommandsHostTests|
EditorKeyHandlingTests|WorkspaceShellTests|EditorIndentation'
Executed 125 tests, with 0 failures (0 unexpected)

Implementation-Agent: daniel-parent (Claude Code, mac-m5pro-dq222)
Commit-Executor: daniel-parent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
d-q222 added a commit that referenced this pull request Sep 14, 2026
…ne Editor menu)

Conflicts in EditorMenu.swift: kept ChangeEnvironmentMenuItems and added
#423's FoldMenuItems as its own Divider()-separated section. In
FlashTeXMacApp.swift, NavigationCommands no longer adds the fold menu.

What was run (apps/mac): swift test --filter 'EditorChangeEnvironmentTests|
EditorLineCommandsTests|CommandTableTests|EditorMenuTests|WorkspaceShellTests|
EnvironmentPairTests|EditorFoldingTests|EditorIndentation'
Executed 138 tests, with 0 failures (0 unexpected)

Implementation-Agent: daniel-parent (Claude Code, mac-m5pro-dq222)
Commit-Executor: daniel-parent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
GoKubar added a commit that referenced this pull request Sep 14, 2026
…ort through the HostedWindows module (#466)

**main's test target does not compile right now.** `swift test` fails before it
runs anything:

    EditorFoldingTests.swift:243: error: cannot find 'HostedWindowSupport' in scope
    EditorFoldingTests.swift:287: error: cannot find 'HostedWindowSupport' in scope
    EditorFoldingTests.swift:361: error: cannot find 'HostedWindowSupport' in scope
    EditorIndentationTests.swift:294: error: cannot find 'HostedWindowSupport' in scope

This is a three-way collision, and no single PR is at fault:

* #464 extracted `HostedWindowSupport` out of the `FlashTeXMacTests` target into
  a new `HostedWindows` target (`apps/mac/Tests/HostedWindows/`, added in
  Package.swift by that PR). Call sites now need `import HostedWindows`, and
  #464 updated all 37 sites that existed on its base.
* #413 (Re-indent) and #423 (code folding) each added a new hosted test file
  that calls `HostedWindowSupport.prepare()` and constructs `NSWindow` directly.
  Both were cut before #464 existed, when `HostedWindowSupport` was in the same
  target and needed no import, so both compiled and both were green when gated.
* The two landed either side of #464, so the new sites were never updated.

The ubuntu jobs compile no Swift, so nothing in CI could see this.

This change, in those two files only:

* adds `import HostedWindows`;
* routes the four `NSWindow(contentRect:…)` constructions through
  `HostedWindowSupport.window(contentRect:styleMask:)`, which is what #464 made
  mandatory — its guard test `testEveryHostedWindowComesFromTheHelper` scans
  every test source for bare `NSWindow(` and fails on one. Adding only the
  import would have fixed the compile and then failed that guard.

The existing `HostedWindowSupport.prepare()` calls are left in place; `window()`
calls `prepare()` itself, and the extra call is idempotent.

Verified on the Mac (apps/mac, fresh /tmp worktree and build directory, this
change on top of main @ 64cb851):
    swift build                                                      ok
    swift test --skip NearbyInterfaceTests --skip NearbyLANInterfaceTests
      main @ 64cb851 unmodified: test target fails to compile, 0 tests run
      with this change:           1214 tests, 138 skipped, 0 failures

Implementation-Agent: Claude Opus 5 (lane linux-integration-2, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
GoKubar added a commit that referenced this pull request Sep 15, 2026
… one Editor menu (#426)

* wip(#EDITOR-LINE-COMMANDS): add Duplicate/Move/Delete/Join/Sort/Trim line commands

Pure plans live in EditorLineCommands.swift (text + selection → trimmed
UTF-16 replacement and new selection). CompletingTextView hooks apply each
as one insertText undo step. Editor menu + palette + accessibility table
list every command.

VimMode already had Join/Delete (modal) and moveLines (scroll); those are
unchanged. Duplicate, Sort, and Trim were missing.

Shortcut conflicts (not stolen):
- Duplicate is ⌘D (⇧⌘D is Go to Matching)
- Move is ⌥⌘↑/↓ (⌥⌘[/] are Previous/Next Occurrence)
- Delete is ⌃⌘K (⇧⌘K is Attach Built Compiler)
- Join is ⌃J (free; Vim J stays modal)
- Sort / Trim have no key equivalent

Ran: cd apps/mac && swift test --filter 'EditorLineCommandsTests|EditorLineCommandsHostTests|CommandTableTests|WorkspaceShellTests'
Result: Executed 60 tests, with 0 failures (CommandTableTests 8, Host 4, pure 38, WorkspaceShell 10).

Next: git fetch origin main && git merge origin/main, then full swift test in apps/mac.

Open questions: no GitHub issue number exists for GH-EDITOR-LINE-COMMANDS (search returned none); sibling #412/#413 are still unmerged.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#EDITOR-LINE-COMMANDS): add failing tests for review defects

Pin exact selection ranges for duplicate/move/join/trim so the previously
weak substring checks cannot pass for the original line or a caret at EOF.

What changed: EditorLineCommandsTests.swift only. Duplicate last unterminated
line now places the caret at original EOF (offset 5) and expects the copy
(offset 6). Join requires "a\nb  \nc\n" → "a b c\n" and the same trailing-%
rule on middle lines. Trim maps several carets through two independent
removals. Multi-line duplicate/move now assert the selection stays on the
block (those already pass).

Ran: cd apps/mac && swift test --filter 'EditorLineCommandsTests'
Result: Executed 41 tests, with 7 failures (join×2, trim×3 assertions, duplicate last-line×2). Host testDuplicateLastUnterminatedLineSelectsTheCopyNotEOF: {8, 0} vs {6, 0}.

Next: fix duplicate EOF mapping, join rtrim/strip on every non-last line, and trim selection mapping by subtracting removals.

Open questions: none; middle-line `%` matches the existing single-line rule.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#EDITOR-LINE-COMMANDS): fix duplicate EOF, join trim, trim mapping

Duplicate of an unterminated last line snaps a caret that relative-maps to
the new EOF onto the copy start. Join now left-trims every line after the
first and right-trims / strips a trailing line-ending % on every non-last
line (same TeX rule as a two-line join). Trim maps carets by clamping
inside a removed range then subtracting removals that end at or before it.

Ran: cd apps/mac && swift test --filter 'EditorLineCommandsTests|EditorLineCommandsHostTests'
Result: Executed 46 tests, with 0 failures (41 pure + 5 host).

Next: consolidate the Editor menu into EditorMenu.swift; keep FindCommands
out of a Group unless CommandsBuilder's 10-child limit requires it.

Open questions: none.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#EDITOR-LINE-COMMANDS): one shared Editor menu in EditorMenu.swift

Move line-command items into LineCommandMenuItems and declare the single
CommandMenu("Editor") in EditorMenuCommands. Folding and re-indent join
that menu later as Divider-separated sections; Go to Line stays in Navigate.

FlashTeXMacApp still wraps FindCommands + EditorMenuCommands in Group:
CommandsBuilder accepts at most 10 children and the .commands block already
has 10 statements without the Editor menu, so a sibling EditorMenuCommands()
does not compile. The Group is that extra child, not a rewrite of Find.

Ran: cd apps/mac && swift test --filter 'EditorLineCommandsTests|EditorLineCommandsHostTests|CommandTableTests'
Result: Executed 54 tests, with 0 failures (CommandTableTests 8, Host 5, pure 41).

Next: git fetch origin main && git merge origin/main, then the filtered
suite and full swift test in apps/mac.

Open questions: none.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#EDITOR-LINE-COMMANDS): guard against a second Editor menu

SwiftUI makes one top-level menu per CommandMenu("Editor"). The folding
lane (#423) declares its own inside NavigationCommands; the two branches
merge without a git conflict and would show two Editor menus. This source
scan fails unless EditorMenu.swift is the only declaration, so whichever
lands second has to fold its items into EditorMenuCommands.

What was run: swift test --filter EditorMenuTests (apps/mac)
Executed 1 test, with 0 failures

Implementation-Agent: daniel-parent (Claude Code, mac-m5pro-dq222)
Commit-Executor: daniel-parent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* wip(#426): keep main's duplicate; menu ⌥⇧↓/⌥⇧↑; drop ⌘D

Deleted this lane's EditorLineCommands.duplicate plan and
duplicateLines(_:) hook. Editor ▸ Duplicate Line / Duplicate Line Up
call CompletingTextView.duplicateLines(below:), matching the key
handler. performKeyEquivalent consumes the chord so the menu equivalent
and keyDown cannot both apply one keystroke.

Ported the review cases onto EditorKeyHandling.duplicateLinesEdit:
unterminated last line selects the copy (same column, which is the
copy's end when the caret was at EOF — main already did this, no edit
to duplicateLinesEdit); multi-line selection stays on the copy.

Move/Delete/Join/Sort/Trim shortcuts unchanged; none collide with #419
(⌥⇧↓/↑) or ⌥⇧R.

Ran:
- cd apps/mac && swift test --filter 'EditorLineCommandsTests|EditorLineCommandsHostTests|EditorKeyHandlingTests|CommandTableTests|EditorMenuTests|WorkspaceShellTests'
  Result: Executed 79 tests, with 0 failures (0 unexpected).
- cd apps/mac && swift test
  Result: Executed 1189 tests, with 135 tests skipped and 3 failures (0 unexpected).
  Failures: WordCountModelTests debounce waits (2s timeout under full-suite load).
  Control: same two tests passed in isolation on unmodified 33621f4 (0.015s) and on this tree (0.015s). Not this change.

Next: none; acceptance criteria met pending parent review.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* Merge origin/main (#464, #466): line-command host tests use HostedWindows

#464 moved HostedWindowSupport into the HostedWindows test target and requires
every hosted window to come from HostedWindowSupport.window(...). #466 fixed
main's folding and indentation tests; this branch's
EditorLineCommandsTests.swift needed the same import and helper.

What was run: swift test --skip NearbyInterfaceTests --skip NearbyLANInterfaceTests (apps/mac), see PR comment

Implementation-Agent: daniel-parent (Claude Code, mac-m5pro-dq222)
Commit-Executor: daniel-parent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* mac: palette ranks by the worst-placed term, so a full title match wins

Making the line commands runnable put Duplicate Line in the palette, and it
took first place for the query "go to line" — ahead of Go to Line itself.

`rank` scored a row by its BEST-placed term. Duplicate Line's title supplies
"line" (rank 0); "go" and "to" are found only in its description, which ends
"⇧⌘D remains Go to Matching" (rank 3). The minimum threw those away and scored
the row 0, tying Go to Line — whose title holds all three terms — and the tie
broke on declaration order, which Duplicate Line wins.

Every term must already match somewhere, so the meaningful score is the
worst-placed one: a row matching everything in its title now beats a row that
only gets there through an incidental word in its prose. Single-term queries
are unchanged.

Found by GoToLineTests.testPaletteListsGoToLineAndColonQueryJumpsDirectly
(#412) failing when this branch merged onto it.

Implementation-Agent: orchestrator-astra
Commit-Executor: orchestrator-astra (direct; Cursor usage limit)

---------

Co-authored-by: Cursor <[email protected]>
Co-authored-by: GoKubar <[email protected]>
GoKubar added a commit that referenced this pull request Sep 15, 2026
)

* wip(#EDITOR-LINE-COMMANDS): add Duplicate/Move/Delete/Join/Sort/Trim line commands

Pure plans live in EditorLineCommands.swift (text + selection → trimmed
UTF-16 replacement and new selection). CompletingTextView hooks apply each
as one insertText undo step. Editor menu + palette + accessibility table
list every command.

VimMode already had Join/Delete (modal) and moveLines (scroll); those are
unchanged. Duplicate, Sort, and Trim were missing.

Shortcut conflicts (not stolen):
- Duplicate is ⌘D (⇧⌘D is Go to Matching)
- Move is ⌥⌘↑/↓ (⌥⌘[/] are Previous/Next Occurrence)
- Delete is ⌃⌘K (⇧⌘K is Attach Built Compiler)
- Join is ⌃J (free; Vim J stays modal)
- Sort / Trim have no key equivalent

Ran: cd apps/mac && swift test --filter 'EditorLineCommandsTests|EditorLineCommandsHostTests|CommandTableTests|WorkspaceShellTests'
Result: Executed 60 tests, with 0 failures (CommandTableTests 8, Host 4, pure 38, WorkspaceShell 10).

Next: git fetch origin main && git merge origin/main, then full swift test in apps/mac.

Open questions: no GitHub issue number exists for GH-EDITOR-LINE-COMMANDS (search returned none); sibling #412/#413 are still unmerged.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(editor-change-env): Change Environment… (⌃⌘E) plus linked name editing

New EditorChangeEnvironment.swift: (text, caret, newName) → the two name-span
replacements, innermost balanced pair, verbatim/unbalanced refusal. Editor ▸
Change Environment… opens a field prefilled with the current name; Enter
applies both names as one pendingEdit. Typing inside a \begin/\end name
updates the partner; the partner write is not its own undo item so ⌘Z of
the typing restores both.

No existing ⌃⌘E. ⌘E is Use Selection for Find, ⌘⇧E Export PDF, ⌘⌥E Export
via Rust. Menu lives under Editor (not Navigate) because NavigationCommands
is already a CommandsBuilder child and an 11th .commands child overflows.

What ran: swift test --filter 'CommandTableTests|EnvironmentPairTests|EditorChangeEnvironmentTests'
  CommandTableTests: Executed 8 tests, with 0 failures
  EditorChangeEnvironmentTests: Executed 15 tests, with 0 failures
  EnvironmentPairTests: Executed 9 tests, with 0 failures
  combined: Executed 32 tests, with 0 failures

Next: full `swift test` in apps/mac, then `git fetch origin main && git merge origin/main` and re-run.

Open questions: no numeric GH issue found for GH-EDITOR-CHANGE-ENV (using the slug).
Pausing the caret in a name does not use a timer; leaving the name span ends the link.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(editor-change-env): skip O(n) pair scan unless the caret is in a name

Linked editing scanned environmentPairs on every keystroke. The 60 KB
keystroke bench types on the \end{document} line, so a line-level
\begin/\end guard still paid the scan (~7 ms round trip vs ~0.09 ms on
unmodified a63537f). isOnEnvironmentName is O(line) on the live storage
and returns false for a caret on the backslash.

What ran:
  swift test --filter EditorChangeEnvironmentTests
    Executed 15 tests, with 0 failures
  swift test --filter testLargeDocumentKeystrokeRoundTripAndCaretBytesStayCorrect
    Executed 1 test, with 0 failures — wall p50 0.091667 ms
  control on a63537f (worktree /tmp/flashtex-mac-base):
    Executed 1 test, with 0 failures — wall p50 0.087917 ms

Next: git fetch origin main && git merge origin/main; full swift test in apps/mac.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#EDITOR-LINE-COMMANDS): add failing tests for review defects

Pin exact selection ranges for duplicate/move/join/trim so the previously
weak substring checks cannot pass for the original line or a caret at EOF.

What changed: EditorLineCommandsTests.swift only. Duplicate last unterminated
line now places the caret at original EOF (offset 5) and expects the copy
(offset 6). Join requires "a\nb  \nc\n" → "a b c\n" and the same trailing-%
rule on middle lines. Trim maps several carets through two independent
removals. Multi-line duplicate/move now assert the selection stays on the
block (those already pass).

Ran: cd apps/mac && swift test --filter 'EditorLineCommandsTests'
Result: Executed 41 tests, with 7 failures (join×2, trim×3 assertions, duplicate last-line×2). Host testDuplicateLastUnterminatedLineSelectsTheCopyNotEOF: {8, 0} vs {6, 0}.

Next: fix duplicate EOF mapping, join rtrim/strip on every non-last line, and trim selection mapping by subtracting removals.

Open questions: none; middle-line `%` matches the existing single-line rule.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#EDITOR-LINE-COMMANDS): fix duplicate EOF, join trim, trim mapping

Duplicate of an unterminated last line snaps a caret that relative-maps to
the new EOF onto the copy start. Join now left-trims every line after the
first and right-trims / strips a trailing line-ending % on every non-last
line (same TeX rule as a two-line join). Trim maps carets by clamping
inside a removed range then subtracting removals that end at or before it.

Ran: cd apps/mac && swift test --filter 'EditorLineCommandsTests|EditorLineCommandsHostTests'
Result: Executed 46 tests, with 0 failures (41 pure + 5 host).

Next: consolidate the Editor menu into EditorMenu.swift; keep FindCommands
out of a Group unless CommandsBuilder's 10-child limit requires it.

Open questions: none.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#EDITOR-LINE-COMMANDS): one shared Editor menu in EditorMenu.swift

Move line-command items into LineCommandMenuItems and declare the single
CommandMenu("Editor") in EditorMenuCommands. Folding and re-indent join
that menu later as Divider-separated sections; Go to Line stays in Navigate.

FlashTeXMacApp still wraps FindCommands + EditorMenuCommands in Group:
CommandsBuilder accepts at most 10 children and the .commands block already
has 10 statements without the Editor menu, so a sibling EditorMenuCommands()
does not compile. The Group is that extra child, not a rewrite of Find.

Ran: cd apps/mac && swift test --filter 'EditorLineCommandsTests|EditorLineCommandsHostTests|CommandTableTests'
Result: Executed 54 tests, with 0 failures (CommandTableTests 8, Host 5, pure 41).

Next: git fetch origin main && git merge origin/main, then the filtered
suite and full swift test in apps/mac.

Open questions: none.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#EDITOR-LINE-COMMANDS): guard against a second Editor menu

SwiftUI makes one top-level menu per CommandMenu("Editor"). The folding
lane (#423) declares its own inside NavigationCommands; the two branches
merge without a git conflict and would show two Editor menus. This source
scan fails unless EditorMenu.swift is the only declaration, so whichever
lands second has to fold its items into EditorMenuCommands.

What was run: swift test --filter EditorMenuTests (apps/mac)
Executed 1 test, with 0 failures

Implementation-Agent: daniel-parent (Claude Code, mac-m5pro-dq222)
Commit-Executor: daniel-parent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* wip(editor-change-env): failing tests for undo corruption, deletion, covering edit

Hosted tests that check text AND both names after every ⌘Z/⌘⇧Z:
(a) type x into the \end name; (b) paste xyz; (c) three separate
undo groups; (d) the same on \begin. Backspace and forward-delete
on both names. Change Environment… must not cover the body.

What ran: swift test --filter EditorChangeEnvironmentTests
  Executed 27 tests, with 35 failures (0 unexpected)
  FAIL (the blockers): end-name insert/paste/three-keystrokes undo;
  end-name backspace/forward-delete undo; applyChangeEnvironment
  covering-edit (pendingEdit.nsRange includes UNIQUE_BODY).
  PASS: begin-name insert/paste/three-keystrokes undo; begin-name
  backspace/forward-delete; hosted covering-edit still yields
  identical body bytes (the range, not the result, is the defect).

Next: register the partner edit on the normal undo path; treat
deletion as replacement ""; apply the two name spans via
applyLineEdits and delete groupedReplacement.

Open questions: begin-name deletion already mirrors (AppKit may
pass "" not nil); end-name deletion fails on undo, same shift bug.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(editor-change-env): register partner edits; two name spans; deletion as ""

The partner rewrite now goes through shouldChangeText / replaceCharacters /
didChangeText in an undo group opened for a name-span keystroke, and is
skipped during undo/redo so mirroring does not re-apply. Deletion is
recorded as replacement "". Change Environment… posts groupedEdits for
the two name spans; applyPendingEdit uses applyLineEdits. groupedReplacement
is deleted.

What ran: swift test --filter EditorChangeEnvironmentTests
  Executed 27 tests, with 0 failures (0 unexpected)

Next: git fetch origin && git merge origin/agent/daniel-parent/editor-line-commands;
move Change Environment… into EditorMenuCommands; comment-pairing test.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(editor-change-env): one Editor menu; skip comment/verbatim env names

Change Environment… (⌃⌘E) is a Divider()-separated section of
EditorMenuCommands (ChangeEnvironmentMenuItems). This lane's own
CommandMenu("Editor") is gone. documentEnvironments uses
EditorNavigation.uses so names that appear only in comments or
verbatim bodies are not offered as suggestions.

What ran: swift test --filter 'EditorChangeEnvironmentTests|EnvironmentPairTests|CommandTableTests|EditorMenuTests'
  CommandTableTests: Executed 8 tests, with 0 failures
  EditorChangeEnvironmentTests: Executed 27 tests, with 0 failures
  EditorMenuTests: Executed 1 test, with 0 failures
  EnvironmentPairTests: Executed 10 tests, with 0 failures
  combined: Executed 46 tests, with 0 failures

Next: git fetch origin main && git merge origin/main; targeted tests,
full swift test in apps/mac, large-document keystroke perf test.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(editor-change-env): keep ⌘D Duplicate Line after merging main

Main's duplicateLine entry (⌥⇧↑/⌥⇧↓, not a menu item) and notRunnable
membership overwrote the editor-line-commands table. Drop the stale
case; Duplicate Line/Selection stays ⌘D and palette-runnable.

What ran: swift test --filter 'EditorChangeEnvironmentTests|EnvironmentPairTests|CommandTableTests|EditorMenuTests'
  combined: Executed 46 tests, with 0 failures (0 unexpected)

Next: full swift test in apps/mac and the large-document keystroke test.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(editor-change-env): Duplicate Line is a menu item after line-commands

CommandTableTests still allowed duplicateLine to have no Button; it is
now Editor ▸ Duplicate Line/Selection.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(editor-change-env): palette test: Duplicate Line is runnable

Main's WorkspaceShellTests still listed duplicateLine as a notRunnable
hint. After editor-line-commands it is Editor ▸ Duplicate Line/Selection
and CommandPaletteModel runs it.

What ran: swift test --filter 'WorkspaceShellTests|WordCountModelTests|RustPDFExportPipeTests'
  Executed 16 tests, with 0 failures (0 unexpected)
Full apps/mac swift test (before this fix): Executed 1218 tests, with
136 tests skipped and 6 failures. Isolation re-run: WordCountModelTests
and RustPDFExportPipeTests pass (full-suite contention). Remaining
failure was this palette assertion.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#426): keep main's duplicate; menu ⌥⇧↓/⌥⇧↑; drop ⌘D

Deleted this lane's EditorLineCommands.duplicate plan and
duplicateLines(_:) hook. Editor ▸ Duplicate Line / Duplicate Line Up
call CompletingTextView.duplicateLines(below:), matching the key
handler. performKeyEquivalent consumes the chord so the menu equivalent
and keyDown cannot both apply one keystroke.

Ported the review cases onto EditorKeyHandling.duplicateLinesEdit:
unterminated last line selects the copy (same column, which is the
copy's end when the caret was at EOF — main already did this, no edit
to duplicateLinesEdit); multi-line selection stays on the copy.

Move/Delete/Join/Sort/Trim shortcuts unchanged; none collide with #419
(⌥⇧↓/↑) or ⌥⇧R.

Ran:
- cd apps/mac && swift test --filter 'EditorLineCommandsTests|EditorLineCommandsHostTests|EditorKeyHandlingTests|CommandTableTests|EditorMenuTests|WorkspaceShellTests'
  Result: Executed 79 tests, with 0 failures (0 unexpected).
- cd apps/mac && swift test
  Result: Executed 1189 tests, with 135 tests skipped and 3 failures (0 unexpected).
  Failures: WordCountModelTests debounce waits (2s timeout under full-suite load).
  Control: same two tests passed in isolation on unmodified 33621f4 (0.015s) and on this tree (0.015s). Not this change.

Next: none; acceptance criteria met pending parent review.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* Merge origin/main (#464, #466): line-command host tests use HostedWindows

#464 moved HostedWindowSupport into the HostedWindows test target and requires
every hosted window to come from HostedWindowSupport.window(...). #466 fixed
main's folding and indentation tests; this branch's
EditorLineCommandsTests.swift needed the same import and helper.

What was run: swift test --skip NearbyInterfaceTests --skip NearbyLANInterfaceTests (apps/mac), see PR comment

Implementation-Agent: daniel-parent (Claude Code, mac-m5pro-dq222)
Commit-Executor: daniel-parent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* Merge #426 fix-up (#464 HostedWindows); change-env host tests use the helper

EditorChangeEnvironmentTests.swift imports HostedWindows and builds its window
with HostedWindowSupport.window(...), as #464 requires.

Implementation-Agent: daniel-parent (Claude Code, mac-m5pro-dq222)
Commit-Executor: daniel-parent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

---------

Co-authored-by: Cursor <[email protected]>
Co-authored-by: GoKubar <[email protected]>
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