Skip to content
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

exceptions thrown when undoing (SwiftUI, macOS) #29

Open
wtholliday opened this issue Sep 29, 2021 · 4 comments
Open

exceptions thrown when undoing (SwiftUI, macOS) #29

wtholliday opened this issue Sep 29, 2021 · 4 comments

Comments

@wtholliday
Copy link

wtholliday commented Sep 29, 2021

To reproduce (macOS 11.6 (20G165)):

  1. Run attached project
  2. Create a new document
  3. Place insertion point at the end of the document
  4. Add two characters
  5. Undo 2x
  6. Observe: *** -[NSBigMutableString substringWithRange:]: Range {14, 1} out of bounds; string length 14
  7. Redo.
  8. Observe: __redoCommonDoSingle:: NSUndoManager 0x600003d12580 is in invalid state, do not invoke this method while undoing

UndoTest.zip

@wtholliday
Copy link
Author

wtholliday commented Sep 29, 2021

Given the stack trace, this seems like it might be an apple bug:

0   CoreFoundation                      0x00007fff205ab1db __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007fff202e4d92 objc_exception_throw + 48
	2   Foundation                          0x00007fff2128c91d -[NSString substringWithRange:] + 223
	3   AppKit                              0x00007fff22f66881 -[NSTextStorage(NSUndo) _undoRedoAttributedSubstringFromRange:] + 145
	4   AppKit                              0x00007fff23514fd7 -[NSUndoTyping undoRedo:] + 142
	5   Foundation                          0x00007fff21390e26 -[_NSUndoStack popAndInvoke] + 187
	6   Foundation                          0x00007fff21390b9d -[NSUndoManager undoNestedGroup] + 296
	7   AppKit                              0x00007fff22f592bb -[NSApplication(NSResponder) sendAction:to:from:] + 288
	8   AppKit                              0x00007fff2305bcc9 -[NSMenuItem _corePerformAction] + 413

@wtholliday
Copy link
Author

This change works around the behavior: audulus@b724bc8

Undo still works, but each undo will change a single character, instead of the typical smarter NSTextView behavior.

@twostraws
Copy link
Owner

Single character undo seems like a pretty serious breakage. Is there really no other approach here?

@wtholliday
Copy link
Author

wtholliday commented Oct 14, 2021

@twostraws I'm not sure. There's a somewhat similar bug with SwiftUI's TextEditor which I've filed with Apple. Once they fix that, the situation here might improve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants