From b35cfaed20151623d68c477cd9146575640d0877 Mon Sep 17 00:00:00 2001 From: t9md Date: Mon, 15 Jan 2018 17:40:51 +0900 Subject: [PATCH] Pass selectionsMarkerLayer on transact, undo and redo To restore selections of change initiated editor on undo/redo. --- src/text-editor.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/text-editor.js b/src/text-editor.js index 9bfa8ff3e..51470a6b2 100644 --- a/src/text-editor.js +++ b/src/text-editor.js @@ -224,7 +224,7 @@ class TextEditor { this.defaultMarkerLayer = this.displayLayer.addMarkerLayer() if (!this.selectionsMarkerLayer) { - this.selectionsMarkerLayer = this.addMarkerLayer({maintainHistory: true, persistent: true}) + this.selectionsMarkerLayer = this.addMarkerLayer({maintainHistory: true, persistent: true, role: 'selections'}) } this.decorationManager = new DecorationManager(this) @@ -1808,13 +1808,13 @@ class TextEditor { // Essential: Undo the last change. undo () { - this.avoidMergingSelections(() => this.buffer.undo()) + this.avoidMergingSelections(() => this.buffer.undo({selectionsMarkerLayer: this.selectionsMarkerLayer})) this.getLastSelection().autoscroll() } // Essential: Redo the last change. redo () { - this.avoidMergingSelections(() => this.buffer.redo()) + this.avoidMergingSelections(() => this.buffer.redo({selectionsMarkerLayer: this.selectionsMarkerLayer})) this.getLastSelection().autoscroll() } @@ -1831,7 +1831,13 @@ class TextEditor { // still 'groupable', the two transactions are merged with respect to undo and redo. // * `fn` A {Function} to call inside the transaction. transact (groupingInterval, fn) { - return this.buffer.transact(groupingInterval, fn) + const options = {selectionsMarkerLayer: this.selectionsMarkerLayer} + if (typeof groupingInterval === 'function') { + fn = groupingInterval + } else { + options.groupingInterval = groupingInterval + } + return this.buffer.transact(options, fn) } // Extended: Abort an open transaction, undoing any operations performed so far @@ -1842,7 +1848,9 @@ class TextEditor { // with {::revertToCheckpoint} and {::groupChangesSinceCheckpoint}. // // Returns a checkpoint value. - createCheckpoint () { return this.buffer.createCheckpoint() } + createCheckpoint () { + return this.buffer.createCheckpoint({selectionsMarkerLayer: this.selectionsMarkerLayer}) + } // Extended: Revert the buffer to the state it was in when the given // checkpoint was created. @@ -1866,7 +1874,9 @@ class TextEditor { // * `checkpoint` The checkpoint from which to group changes. // // Returns a {Boolean} indicating whether the operation succeeded. - groupChangesSinceCheckpoint (checkpoint) { return this.buffer.groupChangesSinceCheckpoint(checkpoint) } + groupChangesSinceCheckpoint (checkpoint) { + return this.buffer.groupChangesSinceCheckpoint(checkpoint, {selectionsMarkerLayer: this.selectionsMarkerLayer}) + } /* Section: TextEditor Coordinates