Repository navigation
fix: typing keeps the caret's formatting; toolbar shows it; SelectionChanged on undo/load - #37
Merged
Merged
Conversation
With nothing selected, typed text used TextStyle.Default unless a pending style had been picked, so typing after a bold word was not bold. Typed text now inherits the style of the character before the caret (or after it at a paragraph start) via the new DocumentEditor.GetInsertionStyle; a pending style still wins. Pending styles now start from the caret's style, so toggling Bold inside bold text turns it off instead of keeping it on. FormattingEngine.GetEffectiveCaretStyle combines both rules and is shared by the input controller and the toolbar. Typing at the start or end of a hyperlink now inserts plain text next to the link instead of extending it; typing inside a link still edits it. ToolbarRenderer.UpdateToggleStates showed toggles active only for a selection; at a collapsed caret it now reflects the effective caret style. MintedEditorView.Undo/Redo raise SelectionChanged when they move the caret, and LoadHtml/LoadMarkdown raise it after resetting the caret. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0197tHRWhTiagB1MTsDuPkoa
There was a problem hiding this comment.
🟡 Changes recommended
Hyperlink-boundary handling incorrectly moves replacement text outside existing links.
1 open issue
What changed in this PR
Aligns typing and toolbar formatting with the caret’s style and improves selection notifications.
Changes:
- Inherits caret formatting while honoring pending styles.
- Inserts text outside hyperlink boundaries.
- Raises selection-change events after loading and caret-moving undo/redo operations.
| File | Description |
|---|---|
| tests/MintedTextEditor.Core.Tests/CharacterFormattingTests.cs | Updates subsequent-typing expectations. |
| tests/MintedTextEditor.Core.Tests/CaretFormattingTests.cs | Adds caret formatting and hyperlink tests. |
| src/MintedTextEditor.Maui/MintedEditorView.cs | Adds selection notifications. |
| src/MintedTextEditor.Core/Toolbar/ToolbarRenderer.cs | Reflects effective caret formatting. |
| src/MintedTextEditor.Core/Input/EditorInputController.cs | Applies effective formatting when typing. |
| src/MintedTextEditor.Core/Formatting/FormattingEngine.cs | Resolves caret and pending styles. |
| src/MintedTextEditor.Core/Formatting/FontFormattingEngine.cs | Seeds pending formatting from caret style. |
| src/MintedTextEditor.Core/Document/DocumentEditor.cs | Adds style lookup and hyperlink-boundary handling. |
| docs/formatting.md | Documents formatting behavior. |
| docs/commands-events.md | Documents selection notifications. |
| CHANGELOG.md | Records the fixes. |
Review effort: Balanced
# Conflicts: # CHANGELOG.md
The link-boundary rule (typing at the start or end of a hyperlink does not extend it) lived in DocumentEditor.InsertText, so it also applied after a selection or find match had been deleted: replacing "ite" in the linked word "site" with "pot" gave linked "s" plus unlinked "pot". The rule is now opt-in through a new InsertText overload and InsertTextAction.EscapeHyperlinkBoundary. The input controller sets it only for text typed or pasted at a caret that was collapsed to begin with, and keeps the decision for characters typed straight after, so typing a word over a selection stays in the link. When the replaced selection starts at the start of a link, the insertion point is moved back into that link, and InsertTextAction keeps that affinity on redo. The 4-argument InsertText (used by find and replace) inserts into the link again, whichever order Replace/ReplaceAll delete and insert in. Also: Enter at the end of formatted text gives the new paragraph an empty run with the caret's style, so text typed after Enter keeps it (e.g. bold). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0197tHRWhTiagB1MTsDuPkoa
# Conflicts: # CHANGELOG.md # src/MintedTextEditor.Core/Editing/UndoableActions.cs # src/MintedTextEditor.Maui/MintedEditorView.cs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0197tHRWhTiagB1MTsDuPkoa
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.

Summary
Three related bugs the housekeeping work turned up:
DocumentEditor.GetInsertionStyleandFormattingEngine.GetEffectiveCaretStyledo this, and the toolbar uses the same code.SelectionChanged. Undo and redo now raise it when the caret moves.LoadHtmlandLoadMarkdownalways raise it, because the document is replaced.Testing
CaretFormattingTestscover:Found but not changed here
These are tracked as follow-ups:
Checklist
Generated by Claude Code