Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Correctly restore markers when undoing/redoing transactions - #53

Merged
kevinsawicki merged 8 commits into
masterfrom
ks-grouped-undo-marker-updates
Mar 19, 2015
Merged

kevinsawicki merged 8 commits into
masterfrom
ks-grouped-undo-marker-updates

Conversation

@nathansobo

Copy link
Copy Markdown
Contributor

This is a continuation of #52. It fixes issues where markers weren't restored correctly when undoing transactions with multiple changes.

Whenever a buffer change occurs that overlaps or invalidates a marker, we record the previous state of the marker on the patch causing that change. When a buffer patch is undone, we restore any markers that have their previous state saved on the patch object. This replaces a previous approach to synthesizing marker patches ahead of time that was breaking down in the presence of multiple changes.

Fixes atom/bracket-matcher#110

kevinsawicki and others added 5 commits March 17, 2015 15:41
Previously, we attempted to associate patches for all markers with every
buffer patch. Now, we allow the application of buffer patches to update
markers directly. When undoing or redoing a transaction, we additionally
restore all markers to the state they had when the transaction was
constructed.
In the previous commits, we snapshotted all markers before every
transaction and restored them on undo. This caused markers to not be
in the correct state during buffer change events, which changed our
contract.

Now the state of every marker that is changed destructively by a buffer
change is recorded with the buffer change. Additionally, we also restore
any markers that were explicitly moved during the transaction.

Signed-off-by: Max Brunsfeld <[email protected]>
@nathansobo
nathansobo force-pushed the ks-grouped-undo-marker-updates branch from 421f628 to 79dc8e1 Compare March 18, 2015 00:49
This ensures that manual marker updates are undone in the correct order.
@nathansobo nathansobo changed the title WIP: Correctly restore markers when undoing/redoing transactions Correctly restore markers when undoing/redoing transactions Mar 18, 2015
@nathansobo

Copy link
Copy Markdown
Contributor Author

@kevinsawicki This should be ready to 🤘 when you're ready to publish. Core specs pass with it but I haven't run a full CI pass. Happy to address anything that comes up once it's published but @maxbrunsfeld and I are feeling pretty good about it.

@kevinsawicki

Copy link
Copy Markdown
Contributor

Awesome, I'm ready to go, want me to merge and publish this?

@nathansobo

Copy link
Copy Markdown
Contributor Author

Shoot, one more change I need to make then yes. We no longer need to change the serialization version.

Nathan Sobo added 2 commits March 18, 2015 11:07
This is required because we dropped `markerPatches` from the serialized
data for `BufferPatch`, which causes exceptions when deserializing in
older versions.
Comment thread src/history.coffee

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now wrap everything in a transaction so the history always contains the same kind of object. We thought it was required for our first attempt at fixing this, but it ended up being optional. Still, it's a structural improvement so we decided to leave it.

@nathansobo

Copy link
Copy Markdown
Contributor Author

@kevinsawicki Okay this is ready. We did a final review and caught one last issue.

kevinsawicki added a commit that referenced this pull request Mar 19, 2015
Correctly restore markers when undoing/redoing transactions
@kevinsawicki
kevinsawicki merged commit 3b68d36 into master Mar 19, 2015
@kevinsawicki

Copy link
Copy Markdown
Contributor

👍

@kevinsawicki
kevinsawicki deleted the ks-grouped-undo-marker-updates branch March 19, 2015 22:33
@kevinsawicki

Copy link
Copy Markdown
Contributor

This broke some specs in Atom so I unpublished it for now:

>> bracket matching
>>   matching bracket insertion
>>     when in language specific scope
>>       string interpolation
>>         it does not wrap the selection in the interpolation brackets when the selection is mutli-line
>>           TypeError: Cannot read property 'tokenAtBufferColumn' of undefined
>>             at TokenizedBuffer.module.exports.TokenizedBuffer.tokenForPosition (/private/var/lib/jenkins/workspace/atom/src/tokenized-buffer.coffee:371:25)
>>             at TokenizedBuffer.module.exports.TokenizedBuffer.scopeDescriptorForPosition (/private/var/lib/jenkins/workspace/atom/src/tokenized-buffer.coffee:367:34)
>>             at DisplayBuffer.module.exports.DisplayBuffer.scopeDescriptorForBufferPosition (/private/var/lib/jenkins/workspace/atom/src/display-buffer.coffee:790:22)
>>             at TextEditor.module.exports.TextEditor.scopeDescriptorForBufferPosition (/private/var/lib/jenkins/workspace/atom/src/text-editor.coffee:2574:20)
>>             at Cursor.module.exports.Cursor.getScopeDescriptor (/private/var/lib/jenkins/workspace/atom/src/cursor.coffee:231:13)
>>             at TagFinder.module.exports.TagFinder.isCursorOnTag (/private/var/lib/jenkins/workspace/atom/node_modules/bracket-matcher/lib/tag-finder.coffee:29:50)
>>             at TagFinder.module.exports.TagFinder.findMatchingTags (/private/var/lib/jenkins/workspace/atom/node_modules/bracket-matcher/lib/tag-finder.coffee:96:29)
>>             at BracketMatcherView.module.exports.BracketMatcherView.updateMatch (/private/var/lib/jenkins/workspace/atom/node_modules/bracket-matcher/lib/bracket-matcher-view.coffee:90:28)
>>             at /private/var/lib/jenkins/workspace/atom/node_modules/bracket-matcher/lib/bracket-matcher-view.coffee:59:8
>>             at Emitter.module.exports.Emitter.emit (/private/var/lib/jenkins/workspace/atom/node_modules/event-kit/lib/emitter.js:82:11)
>>             at /private/var/lib/jenkins/workspace/atom/src/cursor.coffee:48:16
>>             at Emitter.module.exports.Emitter.emit (/private/var/lib/jenkins/workspace/atom/node_modules/event-kit/lib/emitter.js:82:11)
>>             at Marker.module.exports.Marker.notifyObservers (/private/var/lib/jenkins/workspace/atom/src/marker.coffee:381:16)
>>             at /private/var/lib/jenkins/workspace/atom/src/marker.coffee:73:54
>>             at Emitter.module.exports.Emitter.emit (/private/var/lib/jenkins/workspace/atom/node_modules/event-kit/lib/emitter.js:82:11)
>>             at Marker.module.exports.Marker.update (/private/var/lib/jenkins/workspace/atom/node_modules/text-buffer/lib/marker.js:567:22)
>>             at MarkerPatch.module.exports.MarkerPatch.applyTo (/private/var/lib/jenkins/workspace/atom/node_modules/text-buffer/lib/marker-patch.js:50:75)
>>             at Transaction.module.exports.Transaction.applyTo (/private/var/lib/jenkins/workspace/atom/node_modules/text-buffer/lib/transaction.js:60:29)
>>             at History.module.exports.History.undo (/private/var/lib/jenkins/workspace/atom/node_modules/text-buffer/lib/history.js:91:24)
>>             at TextBuffer.module.exports.TextBuffer.undo (/private/var/lib/jenkins/workspace/atom/node_modules/text-buffer/lib/text-buffer.js:679:27)
>>             at TextEditor.module.exports.TextEditor.undo (/private/var/lib/jenkins/workspace/atom/src/text-editor.coffee:1136:13)
>>             at [object Object].<anonymous> (/private/var/lib/jenkins/workspace/atom/node_modules/bracket-matcher/spec/bracket-matcher-spec.coffee:899:18)
>>
>> TextEditor
>>   cursor
>>     autoscroll
>>       it autoscrolls to the cursor when it moves due to undo
>>         Expected 75 to be 0.
>>           at [object Object].<anonymous> (/private/var/lib/jenkins/workspace/atom/spec/text-editor-spec.coffee:995:39)
>>   buffer manipulation
>>     .undo() and .redo()
>>       it restores the selected ranges after undo and redo
>>         Expected [ { start : { row : 1, column : 6 }, end : { row : 1, column : 6 } }, { start : { row : 1, column : 19 }, end : { row : 1, column : 19 } } ] to equal [ [ [ 1, 6 ], [ 1, 6 ] ], [ [ 1, 18 ], [ 1, 18 ] ] ].
>>           at [object Object].<anonymous> (/private/var/lib/jenkins/workspace/atom/spec/text-editor-spec.coffee:3182:50)
>>         Expected [ { start : { row : 1, column : 6 }, end : { row : 1, column : 10 } }, { start : { row : 1, column : 26 }, end : { row : 1, column : 31 } } ] to equal [ [ [ 1, 6 ], [ 1, 10 ] ], [ [ 1, 22 ], [ 1, 27 ] ] ].
>>           at [object Object].<anonymous> (/private/var/lib/jenkins/workspace/atom/spec/text-editor-spec.coffee:3185:50)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught TypeError: Cannot read property 'tokenAtBufferColumn' of undefined

2 participants