Skip to content

v5 E1: editor session and surfaces (E1a partial files + E1b session) - #708

Merged
TheJoeFin merged 25 commits into
devfrom
v5/e1b-editor-session
Nov 12, 2026
Merged

TheJoeFin merged 25 commits into
devfrom
v5/e1b-editor-session

Conversation

@TheJoeFin

@TheJoeFin TheJoeFin commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Implements v5 phase E1 in both of its parts. E1a splits the Edit Text Window's code-behind into partial files. E1b puts an editor session between the window's document and its three editor controls. The work plan is docs/v5/E1-Editor-Session-Surfaces.md, and each step is its own commit. E1a has no PR of its own; its commits are the first nine here.

E1a: partial files

  • EditTextWindow.xaml.cs (8,206 lines on dev) is split into the main file plus eight partial class files: Spreadsheet, Selection, Calc, Files, LocalAi, Transcription, Menus and Markdown. Only whole members moved, with no logic edits, and the main file is down to 2,367 lines.
  • The plan's name patterns would have left about 3,150 lines in the main file. Members that only one cluster calls moved with that cluster instead, and each commit message lists them.
  • ClearGrabTemplateMenuItems and ClearDynamicMenuItems stay in the main file, because EditTextWindowGrabTemplateMenuTests reads that file as text.

E1b: editor session

  • Core (Text_Grab.Core.Editing): IEditorSession and TextSpan(Start, Length). The session's members are:
    • Text, Mode, Selection, SelectedText
    • ReplaceSelection, ReplaceRange, AppendText
    • GetSelectedTextOrAllText, ReplaceSelectedTextOrAllText
    • SelectInEditor, ScrollToEnd
    • TextChanged, ModeChanged
  • App (Text-Grab/Editing/): IEditorSurface with TextBoxSurface, MarkdownSurface and SpreadsheetSurface. EditorSession now owns the cross-editor sync and its two guard flags. The isApplying* flags stay in the window.
  • Every window partial reads and writes the document through Session, and so do FindAndReplaceWindow, FullscreenGrab.SelectionStyles and QuickSimpleLookup. No file outside the window and Text-Grab/Editing/ touches the three editors, which are now x:FieldModifier="private".
  • The grab windows still receive a TextBox destination, now through GetMainTextBox().
  • NotifyIconUtilities.RefreshTrayIconStyle null-checks Application.Current, so tests can construct a real Edit Text Window.

Where the build differs from the plan's sketch:

  • TextSpan, not TextRange: WPF's System.Windows.Documents.TextRange is already used in the Markdown code, so the sketch's name would collide.
  • SelectInEditor replaces Select(range, scrollIntoView). Setting Selection never focuses or scrolls, while every "show this range" caller wants both, so they are separate members.
  • Added: AppendText (35 uses) and ScrollToEnd (4 uses).
  • Dropped: InsertAtCaret, FilePath, HasPendingEdits and SelectionChanged, because nothing outside the window needed them. File state stays in the window.

Plan corrections

  • PassedTextControl appears on 280 lines (301 occurrences) inside the window. Of the 29 other files that mention EditTextWindow, 24 reference the type.
  • The undo trap was wrong. In WPF, TextBox.Text = … is one undoable edit; EditorSessionCharacterizationTests.Text_UndoAfterWholeTextTransformRestoresTheText proves it.
  • The shared vocabulary in docs/v5/README.md and E5's plan now say TextSpan.

Tests

Suite Before (dev, as reported in #699) After (this branch's tip)
Tests.Core 1030 passed 1030 passed
Tests.Core.Windows 301 (4 skipped) 301 (4 skipped), 0 failed
Tests 950 (3 skipped) 983 (3 skipped), 0 failed

The 33 new tests are:

  • EditorSessionCharacterizationTests (19): written and passing against the old code before the session existed
  • EditorSessionTests (9)
  • EditorSessionSyncTests (5)

The build has no new compiler warnings. No NuGet packages were added, so there is nothing to check for MSIX.

Needs checking by hand

  • In each of Text, Markdown and Spreadsheet mode: type, select, apply three different transforms, undo, redo, find and replace, and switch mode and back.
  • Open a file, save, and close with unsaved edits.
  • A fullscreen grab into an open Edit Text Window, and Grab Frame sending text to it.
  • The clipboard watcher, and live transcription appending text.

Merging

v5/a1-action-registry (A1, not pushed yet) is stacked on this branch. Please merge with a merge commit rather than a squash. That way A1 needs no rebase, and the Done (hash) entries in the README stay reachable from dev.

🤖 Generated with Claude Code

TheJoeFin and others added 25 commits November 11, 2026 00:01
E1a, cluster 1 of 8. Whole members cut and pasted unchanged: every
member with Spreadsheet in its name, the nested
SpreadsheetCellTextWrappingConverter, plus TransposeTableExecuted and
GetContextMenuItem (only spreadsheet code calls them).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
E1a, cluster 2 of 8. Whole members cut and pasted unchanged: the
*Markdown* methods and the MarkdownEditorControl_* handlers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
E1a, cluster 3 of 8. Whole members cut and pasted unchanged:
InitializeExpressionEvaluator, EvaluateExpressions, the *Calc* and
*Aggregate* methods, the nested AggregateType, plus the calc-only
handlers DebounceTimer_Tick, ShowErrorsCheckBox_Changed,
ShowErrorsMenuItem_Click, TextBoxSplitter_MouseDoubleClick and
CopyAllContextItem_Click.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
E1a, cluster 4 of 8. Whole members cut and pasted unchanged:
TranscribeAudioFilesAsync, the *Transcription*, LiveTranscri* and
*LiveSource* members, plus InsertTranscribedText and the audio menu
handlers CaptureTranscribeAudioMenuItem_Click,
OpenAudioVideoMenuItem_Click, TranscribeJustIconMenuItem_Click and
MoreModelsMenuItem_Click.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
E1a, cluster 5 of 8. Whole members cut and pasted unchanged:
Summarize*, MeetingNotes*, *LocalAi*, Rewrite*, ConvertTable*,
Translate*, PerformTranslationAsync and ExtractRegexMenuItem_Click,
plus RestartLocalLlmMenuItem_Click, LearnAiMenuItem_Click and
OpenTextInNewEditTextWindow (only local AI code calls it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
E1a, cluster 6 of 8. Whole members cut and pasted unchanged: OpenPath,
Save*, SetOpenedFileState, UpdateWindowTitle, the *PendingFile* members
(including the nested PendingFileCloseAction enum),
GetDefaultSaveExtension, GetSaveDocumentFilterIndex, drag and drop,
folder OCR, plus OpenFileMenuItem_Click, GetWindowTitle,
ListFilesMenuItem_Click and ToggleWriteTxtFileForEachImage_Click.
SavePatternMenuItem_Click and SaveCurrentPatternToRegexManager match
Save* but are pattern-button code, so they go with Selection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
E1a, cluster 7 of 8. Whole members cut and pasted unchanged: Load*MenuItems,
Clear*MenuItems, Populate*Menu, *_SubmenuOpened and the recent-items
members, plus the handlers those populators attach
(LanguageMenuItem_Click, GrabTemplateMenuItem_Click, ApplyPattern*,
ApplyGrabTemplate*, ApplyTemplatePerLine) and the AddPossible*RightClickMenu
context-menu builders.

ClearGrabTemplateMenuItems and ClearDynamicMenuItems stay in
EditTextWindow.xaml.cs: EditTextWindowGrabTemplateMenuTests reads that
file's source text and expects both methods there, in that order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on.cs

E1a, cluster 8 of 8. Whole members cut and pasted unchanged:
UpdateLineAndColumnText, UpdateSelectionSpecificUI, the bottom-bar
pattern buttons (MatchCount, SimilarMatches, RegexPattern, CharDetails)
and Select*, plus the rest of the pattern-button code
(PatternContextOpening, PatternButton_MouseWheel, AnimatePrecisionChange,
ExplainPatternMenuItem_Click, ShowRegexExplanation,
LoadStoredPatternToSelection, LoadRegexPatterns, GenerateRegexPattern,
SavePatternMenuItem_Click, SaveCurrentPatternToRegexManager),
HideSelectionSpecificUi and the bottom-bar setup (SetBottomBarButtons,
ProcessBottomBarKeyPress, HideBottomBarMenuItem_Click,
EditBottomBarMenuItem_Click).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sets the E1 status row and records the E1a outcome in the phase file:
final line counts, the members moved beyond the name patterns, and the
two Clear*MenuItems methods kept in the main file for a source-reading
test. Also corrects the pre-E1a line count (8,206, not 8,176).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pins what the Edit Text Window does today across its three editors before
E1b puts IEditorSession in front of them: a transform applied to a
selection, undo after a transform, switching modes, and find-and-select,
each in text, Markdown and spreadsheet mode. Several tests pin quirks on
purpose (Markdown transforms ignore the rendered selection, Markdown undo
after a transform does nothing, leaving Markdown mode turns line breaks
into hard breaks, SelectInEditor has no spreadsheet branch).

These are the first tests to construct a real EditTextWindow, which needs
two test-only workarounds and no production change:
- WpfResourceAssemblySetup makes the app assembly WPF's resource assembly
  so the window's /Text-Grab;component/ content URIs resolve.
- The window's constructor reaches Application.Current through
  App.SetTheme, so it runs with a stand-in Application that is cleared
  right after. The tests sit in a non-parallel collection so no other
  test sees it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
App.SetTheme ends in NotifyIconUtilities.RefreshTrayIconStyle, which read
Application.Current.Dispatcher unguarded. Every window that calls
SetTheme from its constructor therefore could not be constructed in the
test host, which has no Application. With no Application there is no
tray icon to restyle, so return early. In the running app
Application.Current is never null, so nothing changes for users.

This replaces the stand-in Application the ETW characterization tests
used, and their non-parallel collection, which only existed to hide it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Core gets TextSpan and IEditorSession (Text_Grab.Core.Editing). The app
gets IEditorSurface, TextBoxSurface, MarkdownSurface, SpreadsheetSurface
and EditorSession (Text_Grab.Editing), and EditTextWindow.Session.
Nothing calls the session yet.

The members are the ones the census of PassedTextControl uses needs:
text, selection, replace selection or range, append, selected-or-all
text, show a range in the visible editor, scroll to end, and the
TextChanged and ModeChanged events. The raw text box holds the document
in every mode, so text and selection always go to TextBoxSurface; only
SelectInEditor goes to the surface for the current mode.

No logic moved. The surfaces wrap the text box's own members or delegate
to the window: the Markdown branch of SelectInEditor became
SelectInMarkdownEditor so MarkdownSurface can call it, and the
spreadsheet surface selects in the hidden raw text, as SelectInEditor
always has.

The window test helpers moved to EditTextWindowTestHost so the new
EditorSessionTests can share them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Find and Replace now reaches the Edit Text Window's document only
through EditTextWindow.Session: text, selected text, replacing one match
(ReplaceRange, the same select-then-replace the text box did), showing a
match (SelectInEditor), the mode, and the TextChanged and ModeChanged
events. Its 18 uses of PassedTextControl are gone. The spreadsheet cell
search, navigate and replace calls stay on the window; they are
spreadsheet-only and belong to that editor, not the session.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
QuickSimpleLookup sets the Edit Text Window's text through Session.Text.
FullscreenGrab hands the window's text box to OutputUtilities as the grab
destination through GetMainTextBox(), as GrabFrame already does. The
destination stays a TextBox: OpenMediaWindow and QuickSimpleLookup pass
their own text boxes down the same grab path, so it is not an
Edit Text Window concept.

No file outside EditTextWindow*.cs and Editing/ names PassedTextControl,
MarkdownEditorControl or SpreadsheetDataGrid now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Its three PassedTextControl uses (read text twice, write text once) go
through Session.Text.

The session is now created on first use instead of in the constructors.
Window_Initialized runs inside InitializeComponent and re-themes the
Markdown document, which raises the document's TextChanged and syncs the
text back through the session before the constructor reached the line
that created it. By the time anything asks for the session the editors
it wraps exist, as the old direct PassedTextControl reads required too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Its five PassedTextControl uses (read text three times, write text once, read the selected text once) go through Session.Text and Session.SelectedText.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Its one text read goes through Session.Text. The other six PassedTextControl uses are control-specific (the scroll viewer the calc pane follows, smooth wheel scrolling, text wrapping while the pane is open) and stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Its text, append, caret and scroll uses go through the session: reads of
Session.Text, Session.AppendText, Session.Selection for the caret (the
text box's CaretIndex is SelectionStart, and setting it is Select(i, 0)),
and Session.ScrollToEnd. The three IsReadOnly uses that lock the editor
while a file transcribes are control-specific and stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Its eight text and selected-text uses go through Session.Text and Session.SelectedText. The other 13 PassedTextControl uses build the text box's context menu (spelling suggestions, mailto and URL items, their command targets) and stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
All 39 PassedTextControl uses go through the session: 32 appends (folder OCR progress and results, directory listings), two scroll-to-ends, one whole-text write when a file opens, and four text reads for saving and the pending-edits check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Text, selected text, caret and select calls go through the session:
select line, word, all and none set Session.Selection; the pattern
buttons and match counts read Session.Text and Session.SelectedText.
SelectAll() became Selection = (0, Text.Length), the same range.

SelectInEditor(int, int) now forwards to Session.SelectInEditor, which
routes by mode to the same code it ran itself: SelectInMarkdownEditor in
Markdown mode, select-and-focus in the text box otherwise.

The six uses left are the bottom bar's line and column lookups
(GetLineIndexFromCharacterIndex and friends). They depend on the text
box's layout, where wrapped lines count, so they stay on the control.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The main file's text, selection, caret, replace and append uses go
through the session, one for one: TextBox.Text to Session.Text,
SelectedText reads to Session.SelectedText, SelectedText writes to
Session.ReplaceSelection, Select(i, n) to Session.Selection,
CaretIndex/SelectionStart/SelectionLength to Session.Selection, and
select-then-replace pairs to Session.ReplaceRange. Whole-text writes stay
whole-text writes and selection writes stay selection writes, so every
call site keeps the undo and caret behavior it had.
GetSelectedTextOrAllText and ReplaceSelectedTextOrAllText now forward to
the session's copies of the same logic.

What still names PassedTextControl is control-specific: visibility and
focus when switching modes, fonts, padding, wrapping, alignment, the
context menu, spell check, the calc pane's scroll viewer, the XAML event
handlers, and handing the text box to the grab windows as their
destination.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The session now owns the isSyncingTextFromSpreadsheet and
isSyncingTextFromMarkdown flags and the sync between the text and the
Markdown and spreadsheet editors:

- SyncTextFromActiveEditor and SyncActiveEditorFromText moved from the
  window into the session unchanged: sync the visible editor, a no-op in
  text mode.
- SetTextFromEditor is the guarded write the window did in
  SyncMarkdownTextFromDocument and UpdateTextFromSpreadsheetDocument:
  raise that editor's flag, set the text, lower it. Those two window
  methods now call it.
- SyncEditorFromText is the guard RefreshMarkdownFromText and
  RefreshSpreadsheetFromText had: skip the editor the text is being
  written from, otherwise rebuild it.

The surfaces gained GetText and SetText. MarkdownSurface serializes the
rendered document itself. Building the document and everything
spreadsheet-side (the grid, its table document, layout metrics, undo)
stays in the window, which the surfaces delegate to:
Refresh*FromText(string) are the old Refresh methods without the guard,
and GetSpreadsheetTextFromTable is the grid-commit-then-serialize that
SyncSpreadsheetDocumentFromTable() did. The window's TextChanged handler
reads the flags from the session. Every call keeps its order, its guard,
and the absence of try/finally around the flags.

RefreshSpreadsheetFromText lost its rebuildTable parameter; every caller
passed the default (true).

EditorSessionSyncTests pins the rules against fake surfaces.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PassedTextControl, MarkdownEditorControl and SpreadsheetDataGrid get x:FieldModifier="private", so the compiler now enforces what the earlier commits did by hand: nothing outside EditTextWindow reaches the editors. Other code goes through EditTextWindow.Session; grab windows that need a destination text box get it from GetMainTextBox(). ElementName bindings and FindName are unaffected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The E1 status row is Done. The phase file gets an E1b outcome section
(census totals, the members as built and why they differ from the
sketch, the tests), corrected Current state counts (280 is lines, 301
occurrences; 24 of the 29 files reference the type), and a correction
to the undo trap: TextBox.Text = is undoable in WPF. TextRange is now
TextSpan in the shared vocabulary and in E5's plan, which builds on it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@TheJoeFin
TheJoeFin merged commit 7de19ea into dev Nov 12, 2026
1 check passed
@TheJoeFin
TheJoeFin deleted the v5/e1b-editor-session branch November 12, 2026 03:40
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.

1 participant