HighlightedTextEditor icon indicating copy to clipboard operation
HighlightedTextEditor copied to clipboard

AppKit Editor Unexpected Handling of Undo

Open dbarsamian opened this issue 2 years ago • 3 comments

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:

  1. Create a SwiftUI document-based app targeting the Mac.
  2. In the ContentView, add only a HighlightedTextEditor and bind the text to $document.text
  3. Run the app, and type some new text into the text editor
  4. 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.

Test.zip

dbarsamian avatar Apr 09 '22 03:04 dbarsamian

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 ?

9SL9 avatar Jul 21 '22 01:07 9SL9

Maybe updateUIView/updateNSView will make undo broken, Have a try with no code in this method?

hstdt avatar Jul 22 '22 04:07 hstdt

I will attempt to look into this and will share my findings, if any.

9SL9 avatar Jul 28 '22 06:07 9SL9