-
Notifications
You must be signed in to change notification settings - Fork 2
Editor: overwrite / insert-replace mode (Insert key) #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "profiles": { | ||
| "ted": { | ||
| "commandName": "Project", | ||
| "commandLineArgs": "examples/ted/TedApp.cs", | ||
| "workingDirectory": "../.." | ||
| } | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Overwrite (Insert-Replace) Mode | ||
|
|
||
| **Status**: Implemented | ||
| **Issue**: [#146](https://github.com/gui-cs/Editor/issues/146) | ||
| **Updated**: 2026-05-17 | ||
|
|
||
| ## Summary | ||
|
|
||
| `Editor` supports an overwrite mode: when active, typed characters replace the grapheme under | ||
| the caret instead of inserting before it. At line-end or when a selection is active, typing | ||
| still inserts. The mode is toggled via the Insert key and can be controlled programmatically. | ||
|
|
||
| ## Public API | ||
|
|
||
| ```csharp | ||
| public partial class Editor : View | ||
| { | ||
| /// Gets or sets whether the editor is in overwrite mode. | ||
| public bool OverwriteMode { get; set; } | ||
|
|
||
| /// Raised whenever OverwriteMode changes. | ||
| public event EventHandler? OverwriteModeChanged; | ||
| } | ||
| ``` | ||
|
|
||
| ## Commands & Key Bindings | ||
|
|
||
| | Command | Default Key | Behaviour | | ||
| |----------------------------|-------------|------------------------------| | ||
| | `Command.ToggleOverwrite` | Insert | Toggles `OverwriteMode` | | ||
| | `Command.EnableOverwrite` | *(none)* | Sets `OverwriteMode = true` | | ||
| | `Command.DisableOverwrite` | *(none)* | Sets `OverwriteMode = false` | | ||
|
|
||
| All three are wired through `AddCommand` and the `ToggleOverwrite` binding lives in | ||
| `Editor.DefaultKeyBindings` (user-overridable via `[ConfigurationProperty]`). | ||
|
|
||
| ## Typing Behaviour | ||
|
|
||
| - **Overwrite on, no selection, caret not at line-end**: the grapheme cluster at the caret | ||
| is replaced by the typed character. Uses `RemoveAndInsert` offset mapping so the caret | ||
| anchor advances past the inserted text. Wide-rune safe (uses | ||
| `StringInfo.GetNextTextElementLength`). | ||
| - **Overwrite on, selection active**: selection is replaced (same as insert mode). | ||
| - **Overwrite on, caret at line-end**: plain insert (newline is never consumed). | ||
| - **Multi-caret**: each additional caret follows the same overwrite logic. | ||
| - **Undo**: each overwrite is a single undo step. | ||
|
|
||
| ## Caret Rendering | ||
|
|
||
| While `OverwriteMode` is active, the cursor style is forced to `CursorStyle.SteadyBlock` | ||
| (solid block), distinct from the default bar/underline style used in insert mode. | ||
|
|
||
| ## ted Integration | ||
|
|
||
| The `ted` demo shows an **INS** / **OVR** indicator in the status bar, updated whenever | ||
| `OverwriteModeChanged` fires. | ||
|
|
||
| ## Files Changed | ||
|
|
||
| - `src/Terminal.Gui.Editor/Editor.cs` — `OverwriteMode` property + `OverwriteModeChanged` event | ||
| - `src/Terminal.Gui.Editor/Editor.Commands.cs` — commands, key binding, `OverwriteAtOffset` helper | ||
| - `src/Terminal.Gui.Editor/Editor.Keyboard.cs` — overwrite path in `OnKeyDownNotHandled` | ||
| - `src/Terminal.Gui.Editor/Editor.Drawing.cs` — `SteadyBlock` cursor in overwrite mode | ||
| - `src/Terminal.Gui.Editor/Editor.MultiCaret.cs` — overwrite in multi-caret insert | ||
| - `examples/ted/TedApp.cs` — INS/OVR status bar indicator | ||
| - `specs/public-api.md` — updated with new property and event | ||
| - `tests/Terminal.Gui.Editor.IntegrationTests/EditorOverwriteTests.cs` — integration tests |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.