Repository navigation
Add a Code mode to the Edit Text Window (#645) - #710
Merged
Merged
Conversation
A fourth editor mode beside Raw Text, Spreadsheet and Markdown: the text in an AvalonEdit editor with syntax highlighting and line numbers. - The raw text box stays the document. The code editor holds the same characters, so the two sync edit by edit in both directions, and the selection is mirrored, so every existing command works in code mode. - The language comes from the file extension, history, the person's pick (Format > Code Language, or the status-bar button), or a heuristic detector in Core for pasted and OCR'd code. - On the dark theme AvalonEdit's light-theme colors are remapped to keep their hue and reach 4.5:1 contrast. - Code file extensions (.cs, .json, .py, .xml, ...) now open in Code mode. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AvalonEdit draws line numbers against the left edge and the code against the gutter's dotted line, and its current-line border defaults to a translucent green that setting null never replaces. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collapse/expand markers in the code editor's gutter, using AvalonEdit's folding manager with folding rules written in Core: - Brackets for C#, Java, C/C++, JavaScript, JSON, CSS, PHP and PowerShell. Brackets in strings, comments and character literals are skipped. When a brace starts its own line, the fold starts at the end of the header above it, so the collapsed line still shows the signature. - Tags for XML and HTML: elements, multi-line start and self-closing tags, and comments. A forgiving scanner rather than AvalonEdit's XmlFoldingStrategy, which stops at the first XML error and so fails on ordinary HTML and on OCR'd markup. Regions are recomputed 400 ms after the text stops changing, and once on entering Code mode. Showing a range (Find, Go to) expands any collapsed region hiding it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Edit Text Window's SmoothScrollBehavior (eased wheel scrolling, touch panning with flick inertia) works on AvalonEdit unchanged: its text area scrolls in pixels, so each frame of the ease moves it a little instead of AvalonEdit's default three-line jump per wheel notch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… Code mode (#645) Install AvalonEdit's SearchPanel (Ctrl+F), add a Show Whitespace toggle, shade other occurrences of the selection, outline matching brackets (BracketMatcher in Core, with tests), and use brace-aware auto-indent for C-like languages. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A JSON array of objects folded only every other item: an object whose brace sits on its own line started its fold at the end of the previous line, which for array siblings is the previous item's closing brace, so neighbouring folds overlapped. A line ending in a comma or an opening bracket is no longer treated as a header to keep visible. The folding scan now runs on a worker thread and is applied only if the text is unchanged, so large documents no longer freeze the UI (#645). Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Replace AvalonEdit's find bar template with a themed one: match case, whole word and regex toggles plus vector previous/next/close icons, colored from the editor's palette. The editor's Transparent background is #00FFFFFF, so it is only used as a base when opaque; otherwise a dark or light default applies. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Opening a file whose text was already showing left the code editor holding older text, which OpenPath then copied back into the document and recorded as saved. Opening now always loads the code editor. Entering Code mode and opening a file also left the fill on AvalonEdit's undo stack, so Ctrl+Z emptied the document or brought back the previous file. Both now start the code editor with no undo history. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Entering Code mode always folded on the UI thread, whatever the size, and setting the language scanned the editor's old text first, with a third scan after the typing delay. UpdateFoldings now sends documents over 50k characters to a worker thread and skips a scan already done or under way for the same text, language and folding manager. Entering Code mode and opening a file load the text before setting the language, so each does one scan, of the text being shown. A background scan's result is also dropped if the language changed meanwhile. Co-Authored-By: Claude Opus 5.5 <[email protected]>
History saved Plain Text as a null language, the same as no choice, so a restored window detected a language again and overrode the person's choice. Plain Text is now saved as "". Restoring a Recent text history item into an empty window also ignored the saved language entirely; it now restores it the same way the history constructor does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A line of 1.6M characters (a report's embedded data) froze the editor for good when it scrolled into view: AvalonEdit highlighted it into some 100,000 sections in seconds, then applied them in quadratic time, and WPF alone takes 16 s to lay out a line that long. Lines over 10,000 characters now show only that much, followed by a marker for the rest; the text stays in the document. They are also not highlighted: LongLineHighlighter, adapted from AvalonEdit's DocumentHighlighter, leaves them plain and carries the highlighting state across them unscanned. Folds starting in a hidden part are not offered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ApplyEditFromCodeEditor left the text box caret at the end of the edit, a guess that is wrong for any change that doesn't move the caret, such as text inserted after the selection. It now takes the code editor's own selection, which AvalonEdit has already updated when the window hears of the change. In practice AvalonEdit 6.3 hid the wrong guess: its caret never resets the flag that raises PositionChanged after an update, so the window re-mirrored the real selection after every edit. The sync no longer depends on that. Adds TextSpan.ClampTo for the clamping that was written out in three places. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the Code mode find bar open, Shift+F3 goes to the previous match, as the find bar's own button says, but the Code context menu and the Edit menu still showed it as Toggle Case's shortcut. Both menus now leave the shortcut out while the find bar is open. The key itself is unchanged: taking it from the find bar would change the text of someone stepping back through matches. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The bracket highlight redraws on every caret move, keystroke and scroll, and each draw copied up to 40,000 characters around the caret into a new string before checking for a bracket. BracketMatcher.Find now also reads through a character accessor, and the renderer hands it the document's GetCharAt: most draws read just the two characters beside the caret, and none copies the text. Co-Authored-By: Claude Opus 5.5 <[email protected]>
EditorSession.ScrollToEnd checked for the concrete CodeSurface type to scroll the code editor, so any other code surface, such as a test fake, was silently skipped. ScrollToEnd is now on IEditorSurface, and the session scrolls the text box and then the visible editor. Markdown and spreadsheet do nothing, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Drops the editor's own brace-language list, which left PowerShell folded by braces but not indented by them. A test keeps the two in step. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #645
Adds a Code editor mode to the Edit Text Window, beside Raw Text, Spreadsheet and Markdown: the text in an AvalonEdit editor with syntax highlighting, line numbers, bracket and tag folding, and the same smooth scrolling as the other editors. It started as a spike, so the gaps are listed at the end.
What it does
CodeLanguageDetectorin Core). If nothing scores high enough, it stays plain text..cs,.json,.xml,.xaml,.py,.js,.ps1,.sqland the other extensions inCodeLanguages. This changes behavior: those files opened as Raw Text before.IoUtilitiesTestshad a row pinning.jsonto Text; it now expects Code.CodeHighlightColors).XmlFoldingStrategy, which stops at the first XML error and so fails on ordinary HTML and on OCR'd markup. Showing a range (Find & Replace) expands any collapsed region hiding it.How it fits the editor session (E1)
The raw text box stays the document, as in every mode. The code editor holds the same characters, so:
EditorSession.ApplyEditFromCodeEditor), not a whole-text copy per keystroke;TextEdit.Between), so its caret, scroll position, undo history and collapsed regions survive;CodeSurfaceis the fourthIEditorSurface, andEtwEditorModegainsCode. This is relevant to decision D3 indocs/v5/README.md: AvalonEdit can sit behind the session as one more surface without touching the rest of the window.Needs checking before release
AvalonEdit6.3.1.120 (MIT, ~620 KB). The MSIX package build has to be checked in Visual Studio; it can't be built from the CLI. ThirdPartyNotices / the licenses window need an entry.EditorMode: "Code"can't be read by an older build. From the code, its item-by-item recovery should drop just those entries; not tested.Not done yet
#regionfolding.@$"…"strings, PowerShell here-strings and C++ raw strings can confuse the bracket rule if they contain an unmatched bracket.class A { int x; }) stay plain text until a language is picked.Tests
Tests.exe1,020 (3 existing skips),Tests.Core.exe1,254,Tests.Core.Windows.exe322 (4 existing skips), all passing..csfile in the app (isolated automation profile, dark theme): it opened in Code mode with C# detected, highlighting readable. Light-theme highlighting and folding were checked from offscreen renders, not in the running app.🤖 Generated with Claude Code