HighlightedTextEditor
HighlightedTextEditor copied to clipboard
AppKit Editor Unexpected Handling of Undo
Describe the bug When using a SwiftUI document-based App with HighlightedTextEditor, the editor view will handle undo actions one letter at a time instead of undoing words or phrases at a time.
To Reproduce Steps to reproduce the behavior:
- Create a SwiftUI document-based app targeting the Mac.
- In the ContentView, add only a HighlightedTextEditor and bind the text to
$document.text
- Run the app, and type some new text into the text editor
- Undo typing by either using Command + Z or the menu bar item Edit > Undo
Expected behavior
I expected the editor view to undo words or phrases at a time, similar to how the TextEditor
view handles undo, or any other standard NSTextView
.
Screenshots Please see attached video for demonstration, which compares HighlightedTextEditor's undo behavior with TextEdit's behavior.
https://user-images.githubusercontent.com/46636471/162554231-54ba6a53-aa58-44db-a02c-8fe4fe89c34d.mov
Environment
- macOS Monterey 12.3.1
- Xcode 13.3 (13E113)
Additional context I've attached a sample project to demonstrate the issue with minimal setup.
Has anybody figured out if this is a bug in HighlightedTextEditor or is it solved by configuration of the Undo system in the app? @kyle-n ?
Maybe updateUIView/updateNSView
will make undo broken, Have a try with no code in this method?
I will attempt to look into this and will share my findings, if any.