From 45a3dbca4edccf0019bd28a358470e28e716bdf6 Mon Sep 17 00:00:00 2001 From: abe33 Date: Mon, 12 Oct 2015 22:05:25 +0200 Subject: [PATCH] :bug: Fix folds not preserved when moving multiple selections down When two or more selections span the rows immediately before a fold, the `did-change` event dispatched on the deletion will trigger a merge of the selections, which in turn trigger an unfold at the buffer position of the new selection, which is now the position of the fold. Consolidating the selections at the begin of the transaction will prevent the merge and will keep the fold untouched. --- spec/text-editor-spec.coffee | 23 +++++++++++++++++++++++ src/text-editor.coffee | 1 + 2 files changed, 24 insertions(+) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 307d72656..105463993 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -2067,6 +2067,29 @@ describe "TextEditor", -> expect(editor.lineTextForBufferRow(7)).toBe " var pivot = items.shift(), current, left = [], right = [];" expect(editor.lineTextForBufferRow(9)).toBe " return sort(left).concat(pivot).concat(sort(right));" + describe "and the multiple selections spans the two line before it", -> + it "moves all the lines, preserving the fold", -> + editor.createFold(4, 7) + + expect(editor.isFoldedAtBufferRow(4)).toBeTruthy() + expect(editor.isFoldedAtBufferRow(5)).toBeTruthy() + expect(editor.isFoldedAtBufferRow(6)).toBeTruthy() + expect(editor.isFoldedAtBufferRow(7)).toBeTruthy() + expect(editor.isFoldedAtBufferRow(8)).toBeFalsy() + + editor.setSelectedBufferRanges([[[2, 2], [2, 6]], [[3, 0], [3, 4]]]) + editor.moveLineDown() + + expect(editor.getSelectedBufferRanges()).toEqual [[[7, 0], [7, 4]], [[6, 2], [6, 6]]] + expect(editor.lineTextForBufferRow(2)).toBe " while(items.length > 0) {" + expect(editor.isFoldedAtBufferRow(2)).toBeTruthy() + expect(editor.isFoldedAtBufferRow(3)).toBeTruthy() + expect(editor.isFoldedAtBufferRow(4)).toBeTruthy() + expect(editor.isFoldedAtBufferRow(5)).toBeTruthy() + expect(editor.isFoldedAtBufferRow(6)).toBeFalsy() + expect(editor.lineTextForBufferRow(6)).toBe " if (items.length <= 1) return items;" + expect(editor.lineTextForBufferRow(7)).toBe " var pivot = items.shift(), current, left = [], right = [];" + describe "when some of the selections span the same lines", -> it "moves lines that contain multiple selections correctly", -> editor.setSelectedBufferRanges([[[3, 2], [3, 9]], [[3, 12], [3, 13]]]) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 9988bc203..a22b79205 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -863,6 +863,7 @@ class TextEditor extends Model selections = selections.reverse() @transact => + @consolidateSelections() newSelectionRanges = [] while selections.length > 0