From 44d88e082c6771f68804cf9e762b46664877b0e0 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 2 Apr 2015 16:28:22 +0200 Subject: [PATCH 1/2] :bug: Always copy selections in order --- spec/text-editor-spec.coffee | 14 ++++++++++++++ src/text-editor.coffee | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index bdb6b38fc..0caf62ada 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -2792,6 +2792,20 @@ describe "TextEditor", -> [[5, 8], [5, 8]] ]) + describe "when many selections get added in shuffle order", -> + it "copies them in order", -> + editor.setSelectedBufferRanges([ + [[2,8], [2, 13]] + [[0,4], [0,13]], + [[1,6], [1, 10]], + ]) + editor.copySelectedText() + expect(atom.clipboard.read()).toEqual """ + quicksort + sort + items + """ + describe ".pasteText()", -> copyText = (text, {startColumn, textEditor}={}) -> startColumn ?= 0 diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 355a644b8..d3b8200ab 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -2621,7 +2621,7 @@ class TextEditor extends Model # Essential: For each selection, copy the selected text. copySelectedText: -> maintainClipboard = false - for selection in @getSelections() + for selection in @getSelectionsOrderedByBufferPosition() if selection.isEmpty() previousRange = selection.getBufferRange() selection.selectLine() From b3bdad084f400eb4ab010b7e138c417e9b57e705 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 2 Apr 2015 16:35:26 +0200 Subject: [PATCH 2/2] Always mutate selections in order --- spec/text-editor-spec.coffee | 22 ++++++++++++++++++++-- src/text-editor.coffee | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 0caf62ada..51226a22b 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -2730,6 +2730,20 @@ describe "TextEditor", -> """ + describe "when many selections get added in shuffle order", -> + it "cuts them in order", -> + editor.setSelectedBufferRanges([ + [[2,8], [2, 13]] + [[0,4], [0,13]], + [[1,6], [1, 10]], + ]) + editor.cutSelectedText() + expect(atom.clipboard.read()).toEqual """ + quicksort + sort + items + """ + describe ".cutToEndOfLine()", -> describe "when soft wrap is on", -> it "cuts up to the end of the line", -> @@ -2900,8 +2914,12 @@ describe "TextEditor", -> editor.setSelectedBufferRanges([[[0, 4], [0, 13]], [[1, 6], [1, 10]]]) editor.copySelectedText() - it "pastes each selection separately into the buffer", -> - editor.copySelectedText() + it "pastes each selection in order separately into the buffer", -> + editor.setSelectedBufferRanges([ + [[1, 6], [1, 10]] + [[0, 4], [0, 13]], + ]) + editor.moveRight() editor.insertText("_") editor.pasteText() diff --git a/src/text-editor.coffee b/src/text-editor.coffee index d3b8200ab..548725cf6 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -843,7 +843,7 @@ class TextEditor extends Model mutateSelectedText: (fn) -> @mergeIntersectingSelections => @transact => - fn(selection, index) for selection, index in @getSelections() + fn(selection, index) for selection, index in @getSelectionsOrderedByBufferPosition() # Move lines intersection the most recent selection up by one row in screen # coordinates.