scrod / nv

Notational Velocity: modeless, mouseless Mac OS X note-taking application
http://notational.net
GNU General Public License v3.0
2.07k stars 403 forks source link

undo/redo broken in 2.0 β5 #194

Open jlevasseur opened 13 years ago

jlevasseur commented 13 years ago

Undo and redo do not work for me when writing in the primary edit window.

scrod commented 13 years ago

Please provide some steps to reproduce the problem. Also, if you could send me any related output that NV may have printed to the console (/Applications/Utilities/Console > All Messages) then other clues may exist. Otherwise I'm afraid this problem will remain, because it doesn't occur for me.

jlevasseur commented 13 years ago

Here are the relevant entries from the console. I'm not sure how to describe how to reproduce, because I don't know what is abnormal about my environment, but if you need more info, I'll keep digging. I was inserting lists, with tab and than dash.

    4/5/11 11:22:44 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:22:46 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:22:50 AM      Notational Velocity[4267]       HIToolbox: ignoring exception 'undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups' that raised inside Carbon event dispatch
    (
            0   CoreFoundation                      0x00007fff885b97b4 __exceptionPreprocess + 180
            1   libobjc.A.dylib                     0x00007fff81bfd0f3 objc_exception_throw + 45
            2   CoreFoundation                      0x00007fff885b95d7 +[NSException raise:format:arguments:] + 103
            3   CoreFoundation                      0x00007fff885b9564 +[NSException raise:format:] + 148
            4   Foundation                          0x00007fff824b1413 -[NSUndoManager undo] + 239
            5   AppKit                              0x00007fff80457e9a -[NSApplication sendAction:to:from:] + 95
            6   AppKit                              0x00007fff8047c41e -[NSMenuItem _corePerformAction] + 365
            7   AppKit                              0x00007fff8047c188 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 121
            8   AppKit                              0x00007fff80700279 -[NSMenu _internalPerformActionForItemAtIndex:] + 35
            9   AppKit                              0x00007fff805b1f77 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 136
            10  AppKit                              0x00007fff8045e95c NSSLMMenuEventHandler + 321
            11  HIToolbox                           0x00007fff812217f7 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1002
            12  HIToolbox                           0x00007fff81220d46 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 395
            13  HIToolbox                           0x00007fff8123ea81 SendEventToEventTarget + 45
            14  HIToolbox                           0x00007fff8126dc35 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 387
            15  HIToolbox                           0x00007fff8129aa0a SendMenuCommandWithContextAndModifiers + 56
            16  HIToolbox                           0x00007fff8129a9c2 SendMenuItemSelectedEvent + 101
            17  HIToolbox                           0x00007fff8129a8d2 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 150
            18  HIToolbox                           0x00007fff8127bc27 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 467
            19  HIToolbox                           0x00007fff8127b37c _HandleMenuSelection2 + 453
            20  AppKit                              0x00007fff8032f7dd _NSHandleCarbonMenuEvent + 236
            21  AppKit                              0x00007fff80303317 _DPSNextEvent + 1921
            22  AppKit                              0x00007fff803027a9 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
            23  AppKit                              0x00007fff802c848b -[NSApplication run] + 395
            24  AppKit                              0x00007fff802c11a8 NSApplicationMain + 364
            25  Notational Velocity                 0x0000000100009650 0x0 + 4295005776
            26  ???                                 0x0000000000000002 0x0 + 2
    )
    4/5/11 11:22:53 AM      Notational Velocity[4267]       HIToolbox: ignoring exception 'redo: NSUndoManager 0x101892e50 is in invalid state, do not invoke this method while undoing
    ' that raised inside Carbon event dispatch
    (
            0   CoreFoundation                      0x00007fff885b97b4 __exceptionPreprocess + 180
            1   libobjc.A.dylib                     0x00007fff81bfd0f3 objc_exception_throw + 45
            2   CoreFoundation                      0x00007fff885b95d7 +[NSException raise:format:arguments:] + 103
            3   CoreFoundation                      0x00007fff885b9564 +[NSException raise:format:] + 148
            4   Foundation                          0x00007fff824b105d -[NSUndoManager redo] + 218
            5   AppKit                              0x00007fff80457e9a -[NSApplication sendAction:to:from:] + 95
            6   AppKit                              0x00007fff8047c41e -[NSMenuItem _corePerformAction] + 365
            7   AppKit                              0x00007fff8047c188 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 121
            8   AppKit                              0x00007fff80700279 -[NSMenu _internalPerformActionForItemAtIndex:] + 35
            9   AppKit                              0x00007fff805b1f77 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 136
            10  AppKit                              0x00007fff8045e95c NSSLMMenuEventHandler + 321
            11  HIToolbox                           0x00007fff812217f7 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1002
            12  HIToolbox                           0x00007fff81220d46 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 395
            13  HIToolbox                           0x00007fff8123ea81 SendEventToEventTarget + 45
            14  HIToolbox                           0x00007fff8126dc35 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 387
            15  HIToolbox                           0x00007fff8129aa0a SendMenuCommandWithContextAndModifiers + 56
            16  HIToolbox                           0x00007fff8129a9c2 SendMenuItemSelectedEvent + 101
            17  HIToolbox                           0x00007fff8129a8d2 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 150
            18  HIToolbox                           0x00007fff8127bc27 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 467
            19  HIToolbox                           0x00007fff8127b37c _HandleMenuSelection2 + 453
            20  AppKit                              0x00007fff8032f7dd _NSHandleCarbonMenuEvent + 236
            21  AppKit                              0x00007fff80303317 _DPSNextEvent + 1921
            22  AppKit                              0x00007fff803027a9 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
            23  AppKit                              0x00007fff802c848b -[NSApplication run] + 395
            24  AppKit                              0x00007fff802c11a8 NSApplicationMain + 364
            25  Notational Velocity                 0x0000000100009650 0x0 + 4295005776
            26  ???                                 0x0000000000000002 0x0 + 2
    )

    4/5/11 11:22:55 AM      Notational Velocity[4267]       HIToolbox: ignoring exception 'redo: NSUndoManager 0x101892e50 is in invalid state, do not invoke this method while undoing
    ' that raised inside Carbon event dispatch
    (
            0   CoreFoundation                      0x00007fff885b97b4 __exceptionPreprocess + 180
            1   libobjc.A.dylib                     0x00007fff81bfd0f3 objc_exception_throw + 45
            2   CoreFoundation                      0x00007fff885b95d7 +[NSException raise:format:arguments:] + 103
            3   CoreFoundation                      0x00007fff885b9564 +[NSException raise:format:] + 148
            4   Foundation                          0x00007fff824b105d -[NSUndoManager redo] + 218
            5   AppKit                              0x00007fff80457e9a -[NSApplication sendAction:to:from:] + 95
            6   AppKit                              0x00007fff8047c41e -[NSMenuItem _corePerformAction] + 365
            7   AppKit                              0x00007fff8047c188 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 121
            8   AppKit                              0x00007fff80700279 -[NSMenu _internalPerformActionForItemAtIndex:] + 35
            9   AppKit                              0x00007fff805b1f77 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 136
            10  AppKit                              0x00007fff8045e95c NSSLMMenuEventHandler + 321
            11  HIToolbox                           0x00007fff812217f7 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1002
            12  HIToolbox                           0x00007fff81220d46 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 395
            13  HIToolbox                           0x00007fff8123ea81 SendEventToEventTarget + 45
            14  HIToolbox                           0x00007fff8126dc35 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 387
            15  HIToolbox                           0x00007fff8129aa0a SendMenuCommandWithContextAndModifiers + 56
            16  HIToolbox                           0x00007fff8129a9c2 SendMenuItemSelectedEvent + 101
            17  HIToolbox                           0x00007fff8129a8d2 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 150
            18  HIToolbox                           0x00007fff8127bc27 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 467
            19  HIToolbox                           0x00007fff8127b37c _HandleMenuSelection2 + 453
            20  AppKit                              0x00007fff8032f7dd _NSHandleCarbonMenuEvent + 236
            21  AppKit                              0x00007fff80303317 _DPSNextEvent + 1921
            22  AppKit                              0x00007fff803027a9 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
            23  AppKit                              0x00007fff802c848b -[NSApplication run] + 395
            24  AppKit                              0x00007fff802c11a8 NSApplicationMain + 364
            25  Notational Velocity                 0x0000000100009650 0x0 + 4295005776
            26  ???                                 0x0000000000000002 0x0 + 2
    )
    4/5/11 11:23:06 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:23:07 AM      Notational Velocity[4267]       redo: NSUndoManager 0x101892e50 is in invalid state, do not invoke this method while undoing
    4/5/11 11:23:20 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:23:21 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:23:22 AM      Notational Velocity[4267]       redo: NSUndoManager 0x101892e50 is in invalid state, do not invoke this method while undoing
    4/5/11 11:23:26 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:23:27 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:23:27 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:25:07 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:25:07 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:25:12 AM      Notational Velocity[4267]       redo: NSUndoManager 0x101892e50 is in invalid state, do not invoke this method while undoing
    4/5/11 11:25:13 AM      Notational Velocity[4267]       redo: NSUndoManager 0x101892e50 is in invalid state, do not invoke this method while undoing
    4/5/11 11:25:13 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:26:19 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:26:19 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
    4/5/11 11:26:19 AM      Notational Velocity[4267]       undo: NSUndoManager 0x101892e50 is in invalid state, undo was called with too many nested undo groups
scrod commented 13 years ago

Thank you for responding. Are these the only messages that NV posted? Does the problem occur upon using undo for the first time after launching the application? In a blank, new note? Precisely what are you typing before trying to undo it, or doing in the program elsewhere?

jlevasseur commented 13 years ago

Undo/redo work after restarting NV. It gets confused after pasting some code snippets into a list, and then hitting undo/redo several times. I've reproduced it several times now, but don't yet know the magic sequence. And now I can't reproduce it. I'll follow up if I can find a consistent way to reproduce it.

jlevasseur commented 13 years ago

I figured it out: make a list (hit tab, then dash, then space, then text), and enter list items; then hit enter to create an empty list item, and hit enter several times, which should keep auto-indenting the line but without the dash. Then start hitting undo, and it will eventually stop working once it undoes everything up to the bottom-most dash. Example:

<tab> - A
<tab> - B
<tab> - C
<tab>
<tab> 
<tab>
scrod commented 13 years ago

Thank you! This is very helpful — I'm able to reproduce it so I ought to find the problem eventually.

pendolino commented 13 years ago

i am having the same problem with undo not working.

tewe commented 13 years ago

I found no relation to the problem above, but there was another bug causing characters to be left over when undoing a paste. Fixed in https://github.com/tewe/nv/commit/10533d0b6646a4dd6994e2c93cd1623ca15de808 by moving [newString indentTextLists (which changes length) before shouldChangeTextInRange instead of after.

It might be helpful to debug undo problems by overriding shouldChangeTextInRange and replaceCharactersInRange with functions that simply add logging.