From 7f7ca75113533cefb7a4f283f66437245b831794 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Sun, 3 May 2015 19:44:26 -0400 Subject: [PATCH 01/16] Implement editor:move-selection-right command --- menus/darwin.cson | 1 + src/text-editor-element.coffee | 1 + src/text-editor.coffee | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/menus/darwin.cson b/menus/darwin.cson index 17072e14f..7fef9f9a4 100644 --- a/menus/darwin.cson +++ b/menus/darwin.cson @@ -128,6 +128,7 @@ { label: 'Select to First Character of Line', command: 'editor:select-to-first-character-of-line' } { label: 'Select to End of Word', command: 'editor:select-to-end-of-word' } { label: 'Select to End of Line', command: 'editor:select-to-end-of-line' } + { label: 'Move Selection Right', command: 'editor:move-selection-right' } ] } diff --git a/src/text-editor-element.coffee b/src/text-editor-element.coffee index e3eaaeb2a..8e6878a16 100644 --- a/src/text-editor-element.coffee +++ b/src/text-editor-element.coffee @@ -343,6 +343,7 @@ atom.commands.add 'atom-text-editor:not([mini])', stopEventPropagationAndGroupUn 'editor:checkout-head-revision': -> @checkoutHeadRevision() 'editor:move-line-up': -> @moveLineUp() 'editor:move-line-down': -> @moveLineDown() + 'editor:move-selection-right': -> @moveSelectionRight() 'editor:duplicate-lines': -> @duplicateLines() 'editor:join-lines': -> @joinLines() ) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 7afc99236..59bb91ebe 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -932,6 +932,25 @@ class TextEditor extends Model @setSelectedBufferRange(selection.translate([insertDelta]), preserveFolds: true, autoscroll: true) + moveSelectionRight: -> + selections = @getSelectedBufferRanges() + + translationDelta = [0, 1] + translatedRanges = [] + + @transact => + for selection in selections + range = new Range(selection.end, selection.end.translate(translationDelta)) + + insertionPoint = selection.start + text = @buffer.getTextInRange(range) + + @buffer.delete(range) + @buffer.insert(insertionPoint, text) + translatedRanges.push(selection.translate(translationDelta)) + + @setSelectedBufferRanges(translatedRanges) + # Duplicate the most recent cursor's current line. duplicateLines: -> @transact => From 1f023d1d2c64b44e1d120872c67c30426916ffaf Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Sun, 3 May 2015 20:25:47 -0400 Subject: [PATCH 02/16] Implement editor:move-selection-left --- keymaps/darwin.cson | 2 ++ menus/darwin.cson | 8 +++++++- src/text-editor-element.coffee | 1 + src/text-editor.coffee | 21 +++++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/keymaps/darwin.cson b/keymaps/darwin.cson index 34d18e159..cd7d0ecb6 100644 --- a/keymaps/darwin.cson +++ b/keymaps/darwin.cson @@ -127,6 +127,8 @@ # Atom Specific 'ctrl-W': 'editor:select-word' + 'cmd-ctrl-left': 'editor:move-selection-left' + 'cmd-ctrl-right': 'editor:move-selection-right' # Sublime Parity 'cmd-a': 'core:select-all' diff --git a/menus/darwin.cson b/menus/darwin.cson index 7fef9f9a4..642126259 100644 --- a/menus/darwin.cson +++ b/menus/darwin.cson @@ -74,6 +74,13 @@ { label: 'Join Lines', command: 'editor:join-lines' } ] } + { + label: 'Columns', + submenu: [ + { label: 'Move Selection Left', command: 'editor:move-selection-left' } + { label: 'Move Selection Right', command: 'editor:move-selection-right' } + ] + } { label: 'Text', submenu: [ @@ -128,7 +135,6 @@ { label: 'Select to First Character of Line', command: 'editor:select-to-first-character-of-line' } { label: 'Select to End of Word', command: 'editor:select-to-end-of-word' } { label: 'Select to End of Line', command: 'editor:select-to-end-of-line' } - { label: 'Move Selection Right', command: 'editor:move-selection-right' } ] } diff --git a/src/text-editor-element.coffee b/src/text-editor-element.coffee index 8e6878a16..f428e3ced 100644 --- a/src/text-editor-element.coffee +++ b/src/text-editor-element.coffee @@ -343,6 +343,7 @@ atom.commands.add 'atom-text-editor:not([mini])', stopEventPropagationAndGroupUn 'editor:checkout-head-revision': -> @checkoutHeadRevision() 'editor:move-line-up': -> @moveLineUp() 'editor:move-line-down': -> @moveLineDown() + 'editor:move-selection-left': -> @moveSelectionLeft() 'editor:move-selection-right': -> @moveSelectionRight() 'editor:duplicate-lines': -> @duplicateLines() 'editor:join-lines': -> @joinLines() diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 59bb91ebe..4071e5cfc 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -932,6 +932,27 @@ class TextEditor extends Model @setSelectedBufferRange(selection.translate([insertDelta]), preserveFolds: true, autoscroll: true) + moveSelectionLeft: -> + selections = @getSelectedBufferRanges() + + translationDelta = [0, -1] + translatedRanges = [] + + @transact => + for selection in selections + range = new Range(selection.start.translate(translationDelta), selection.start) + + insertionPoint = selection.end + text = @buffer.getTextInRange(range) + + console.log(text) + + @buffer.insert(insertionPoint, text) + @buffer.delete(range) + translatedRanges.push(selection.translate(translationDelta)) + + @setSelectedBufferRanges(translatedRanges) + moveSelectionRight: -> selections = @getSelectedBufferRanges() From 93e019407d99e83d170d73f781fbb5c7d40b4242 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Sun, 3 May 2015 20:32:44 -0400 Subject: [PATCH 03/16] :fire: Errant console.log --- src/text-editor.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 4071e5cfc..e7dcd3f26 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -945,8 +945,6 @@ class TextEditor extends Model insertionPoint = selection.end text = @buffer.getTextInRange(range) - console.log(text) - @buffer.insert(insertionPoint, text) @buffer.delete(range) translatedRanges.push(selection.translate(translationDelta)) From 7a928be1143e3d7b2923afe10f9d886953d32d19 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Sun, 3 May 2015 20:58:52 -0400 Subject: [PATCH 04/16] Rename range to make its contents more clear --- src/text-editor.coffee | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index e7dcd3f26..720171c0a 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -940,13 +940,13 @@ class TextEditor extends Model @transact => for selection in selections - range = new Range(selection.start.translate(translationDelta), selection.start) + charToLeftOfSelection = new Range(selection.start.translate(translationDelta), selection.start) insertionPoint = selection.end - text = @buffer.getTextInRange(range) + text = @buffer.getTextInRange(charToLeftOfSelection) @buffer.insert(insertionPoint, text) - @buffer.delete(range) + @buffer.delete(charToLeftOfSelection) translatedRanges.push(selection.translate(translationDelta)) @setSelectedBufferRanges(translatedRanges) @@ -959,12 +959,12 @@ class TextEditor extends Model @transact => for selection in selections - range = new Range(selection.end, selection.end.translate(translationDelta)) + charToRightOfSelection = new Range(selection.end, selection.end.translate(translationDelta)) insertionPoint = selection.start - text = @buffer.getTextInRange(range) + text = @buffer.getTextInRange(charToRightOfSelection) - @buffer.delete(range) + @buffer.delete(charToRightOfSelection) @buffer.insert(insertionPoint, text) translatedRanges.push(selection.translate(translationDelta)) From 4931609d4ba0109cafd60cc934653ba0749243c5 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Sun, 3 May 2015 22:55:55 -0400 Subject: [PATCH 05/16] Add specs for moveSelectionLeft() --- spec/text-editor-spec.coffee | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 53eb32acb..df87a29e4 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -3427,6 +3427,36 @@ describe "TextEditor", -> expect(cursor1.getBufferPosition()).toEqual [0, 0] expect(cursor3.getBufferPosition()).toEqual [1, 2] + describe ".moveSelectionLeft()", -> + it "moves one active selection on one line one column to the left", -> + editor.setSelectedBufferRange [[0, 4], [0, 13]] + expect(editor.getSelectedText()).toBe 'quicksort' + editor.moveSelectionLeft() + expect(editor.getSelectedText()).toBe 'quicksort' + expect(editor.getSelectedBufferRange()).toEqual [[0, 3], [0, 12]] + + it "moves multiple active selections on one line one column to the left", -> + editor.setSelectedBufferRanges([[[0, 4], [0, 13]], [[0, 16], [0, 24]]]) + selections = editor.getSelections() + + expect(selections[0].getText()).toBe 'quicksort' + expect(selections[1].getText()).toBe 'function' + editor.moveSelectionLeft() + expect(selections[0].getText()).toBe 'quicksort' + expect(selections[1].getText()).toBe 'function' + expect(editor.getSelectedBufferRanges()).toEqual [[[0, 3], [0, 12]], [[0, 15], [0, 23]]] + + it "moves multiple active selections on multiple lines one column to the left", -> + editor.setSelectedBufferRanges([[[0, 4], [0, 13]], [[1, 6], [1, 10]]]) + selections = editor.getSelections() + + expect(selections[0].getText()).toBe 'quicksort' + expect(selections[1].getText()).toBe 'sort' + editor.moveSelectionLeft() + expect(selections[0].getText()).toBe 'quicksort' + expect(selections[1].getText()).toBe 'sort' + expect(editor.getSelectedBufferRanges()).toEqual [[[0, 3], [0, 12]], [[1, 5], [1, 9]]] + describe 'reading text', -> it '.lineTextForScreenRow(row)', -> editor.foldBufferRow(4) From c2132114af7fb8c0dd01ca07e6de51bcacada546 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Sun, 3 May 2015 22:59:17 -0400 Subject: [PATCH 06/16] Add specs for moveSelectionRight() --- spec/text-editor-spec.coffee | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index df87a29e4..83747aee4 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -3457,6 +3457,36 @@ describe "TextEditor", -> expect(selections[1].getText()).toBe 'sort' expect(editor.getSelectedBufferRanges()).toEqual [[[0, 3], [0, 12]], [[1, 5], [1, 9]]] + describe ".moveSelectionRight()", -> + it "moves one active selection on one line one column to the right", -> + editor.setSelectedBufferRange [[0, 4], [0, 13]] + expect(editor.getSelectedText()).toBe 'quicksort' + editor.moveSelectionRight() + expect(editor.getSelectedText()).toBe 'quicksort' + expect(editor.getSelectedBufferRange()).toEqual [[0, 5], [0, 14]] + + it "moves multiple active selections on one line one column to the right", -> + editor.setSelectedBufferRanges([[[0, 4], [0, 13]], [[0, 16], [0, 24]]]) + selections = editor.getSelections() + + expect(selections[0].getText()).toBe 'quicksort' + expect(selections[1].getText()).toBe 'function' + editor.moveSelectionRight() + expect(selections[0].getText()).toBe 'quicksort' + expect(selections[1].getText()).toBe 'function' + expect(editor.getSelectedBufferRanges()).toEqual [[[0, 5], [0, 14]], [[0, 17], [0, 25]]] + + it "moves multiple active selections on multiple lines one column to the right", -> + editor.setSelectedBufferRanges([[[0, 4], [0, 13]], [[1, 6], [1, 10]]]) + selections = editor.getSelections() + + expect(selections[0].getText()).toBe 'quicksort' + expect(selections[1].getText()).toBe 'sort' + editor.moveSelectionRight() + expect(selections[0].getText()).toBe 'quicksort' + expect(selections[1].getText()).toBe 'sort' + expect(editor.getSelectedBufferRanges()).toEqual [[[0, 5], [0, 14]], [[1, 7], [1, 11]]] + describe 'reading text', -> it '.lineTextForScreenRow(row)', -> editor.foldBufferRow(4) From aabde38f614ac781b230c92e3e965759c480cd49 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Sun, 3 May 2015 23:32:52 -0400 Subject: [PATCH 07/16] Fix case when selection is at the beginning or end of a line --- src/text-editor.coffee | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 720171c0a..0594b7365 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -942,14 +942,15 @@ class TextEditor extends Model for selection in selections charToLeftOfSelection = new Range(selection.start.translate(translationDelta), selection.start) - insertionPoint = selection.end - text = @buffer.getTextInRange(charToLeftOfSelection) + unless charToLeftOfSelection.start.column < 0 + insertionPoint = selection.end + text = @buffer.getTextInRange(charToLeftOfSelection) - @buffer.insert(insertionPoint, text) - @buffer.delete(charToLeftOfSelection) - translatedRanges.push(selection.translate(translationDelta)) + @buffer.insert(insertionPoint, text) + @buffer.delete(charToLeftOfSelection) + translatedRanges.push(selection.translate(translationDelta)) - @setSelectedBufferRanges(translatedRanges) + @setSelectedBufferRanges(translatedRanges) if translatedRanges.length > 0 moveSelectionRight: -> selections = @getSelectedBufferRanges() @@ -961,14 +962,15 @@ class TextEditor extends Model for selection in selections charToRightOfSelection = new Range(selection.end, selection.end.translate(translationDelta)) - insertionPoint = selection.start - text = @buffer.getTextInRange(charToRightOfSelection) + unless charToRightOfSelection.end.column > @buffer.lineLengthForRow(charToRightOfSelection.end.row) + insertionPoint = selection.start + text = @buffer.getTextInRange(charToRightOfSelection) - @buffer.delete(charToRightOfSelection) - @buffer.insert(insertionPoint, text) - translatedRanges.push(selection.translate(translationDelta)) + @buffer.delete(charToRightOfSelection) + @buffer.insert(insertionPoint, text) + translatedRanges.push(selection.translate(translationDelta)) - @setSelectedBufferRanges(translatedRanges) + @setSelectedBufferRanges(translatedRanges) if translatedRanges.length > 0 # Duplicate the most recent cursor's current line. duplicateLines: -> From e269b3bad9bc2e1b5329af9c8bbd2e86d2d5aff5 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Sun, 3 May 2015 23:43:19 -0400 Subject: [PATCH 08/16] :art: --- src/text-editor.coffee | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 0594b7365..8ecd5bf40 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -943,10 +943,9 @@ class TextEditor extends Model charToLeftOfSelection = new Range(selection.start.translate(translationDelta), selection.start) unless charToLeftOfSelection.start.column < 0 - insertionPoint = selection.end text = @buffer.getTextInRange(charToLeftOfSelection) - @buffer.insert(insertionPoint, text) + @buffer.insert(selection.end, text) @buffer.delete(charToLeftOfSelection) translatedRanges.push(selection.translate(translationDelta)) @@ -963,11 +962,10 @@ class TextEditor extends Model charToRightOfSelection = new Range(selection.end, selection.end.translate(translationDelta)) unless charToRightOfSelection.end.column > @buffer.lineLengthForRow(charToRightOfSelection.end.row) - insertionPoint = selection.start text = @buffer.getTextInRange(charToRightOfSelection) @buffer.delete(charToRightOfSelection) - @buffer.insert(insertionPoint, text) + @buffer.insert(selection.start, text) translatedRanges.push(selection.translate(translationDelta)) @setSelectedBufferRanges(translatedRanges) if translatedRanges.length > 0 From 8479e1c34f5866d97998e9fdcfdf6e39cdbb74ec Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Sun, 3 May 2015 23:59:33 -0400 Subject: [PATCH 09/16] Fix selection behavior at beginning or end of line --- src/text-editor.coffee | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 8ecd5bf40..c35438cdb 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -942,14 +942,16 @@ class TextEditor extends Model for selection in selections charToLeftOfSelection = new Range(selection.start.translate(translationDelta), selection.start) - unless charToLeftOfSelection.start.column < 0 + if charToLeftOfSelection.start.column < 0 + translatedRanges.push(selection) + else text = @buffer.getTextInRange(charToLeftOfSelection) @buffer.insert(selection.end, text) @buffer.delete(charToLeftOfSelection) translatedRanges.push(selection.translate(translationDelta)) - @setSelectedBufferRanges(translatedRanges) if translatedRanges.length > 0 + @setSelectedBufferRanges(translatedRanges) moveSelectionRight: -> selections = @getSelectedBufferRanges() @@ -961,14 +963,16 @@ class TextEditor extends Model for selection in selections charToRightOfSelection = new Range(selection.end, selection.end.translate(translationDelta)) - unless charToRightOfSelection.end.column > @buffer.lineLengthForRow(charToRightOfSelection.end.row) + if charToRightOfSelection.end.column > @buffer.lineLengthForRow(charToRightOfSelection.end.row) + translatedRanges.push(selection) + else text = @buffer.getTextInRange(charToRightOfSelection) @buffer.delete(charToRightOfSelection) @buffer.insert(selection.start, text) translatedRanges.push(selection.translate(translationDelta)) - @setSelectedBufferRanges(translatedRanges) if translatedRanges.length > 0 + @setSelectedBufferRanges(translatedRanges) # Duplicate the most recent cursor's current line. duplicateLines: -> From f396b972987ec170a32cbbc411aa057f464f7bf0 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Mon, 4 May 2015 00:11:42 -0400 Subject: [PATCH 10/16] Add specs for first / last column cases --- spec/text-editor-spec.coffee | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 83747aee4..ee1d513ae 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -3457,6 +3457,19 @@ describe "TextEditor", -> expect(selections[1].getText()).toBe 'sort' expect(editor.getSelectedBufferRanges()).toEqual [[[0, 3], [0, 12]], [[1, 5], [1, 9]]] + describe "when a selection is at the first column of a line", -> + it "does not change the selection", -> + editor.setSelectedBufferRanges([[[0, 0], [0, 3]], [[1, 0], [1, 3]]]) + selections = editor.getSelections() + + expect(selections[0].getText()).toBe 'var' + expect(selections[1].getText()).toBe ' v' + editor.moveSelectionLeft() + editor.moveSelectionLeft() + expect(selections[0].getText()).toBe 'var' + expect(selections[1].getText()).toBe ' v' + expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [0, 3]], [[1, 0], [1, 3]]] + describe ".moveSelectionRight()", -> it "moves one active selection on one line one column to the right", -> editor.setSelectedBufferRange [[0, 4], [0, 13]] @@ -3487,6 +3500,19 @@ describe "TextEditor", -> expect(selections[1].getText()).toBe 'sort' expect(editor.getSelectedBufferRanges()).toEqual [[[0, 5], [0, 14]], [[1, 7], [1, 11]]] + describe "when a selection is at the last column of a line", -> + it "does not change the selection", -> + editor.setSelectedBufferRanges([[[2, 34], [2, 40]], [[5, 22], [5, 30]]]) + selections = editor.getSelections() + + expect(selections[0].getText()).toBe 'items;' + expect(selections[1].getText()).toBe 'shift();' + editor.moveSelectionRight() + editor.moveSelectionRight() + expect(selections[0].getText()).toBe 'items;' + expect(selections[1].getText()).toBe 'shift();' + expect(editor.getSelectedBufferRanges()).toEqual [[[2, 34], [2, 40]], [[5, 22], [5, 30]]] + describe 'reading text', -> it '.lineTextForScreenRow(row)', -> editor.foldBufferRow(4) From 7028fb4add1670518c6fcd924c8fc4e3a95448c8 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Mon, 4 May 2015 00:17:43 -0400 Subject: [PATCH 11/16] Add Linux and Windows menu items --- menus/linux.cson | 7 +++++++ menus/win32.cson | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/menus/linux.cson b/menus/linux.cson index 9363d02e5..6253f21eb 100644 --- a/menus/linux.cson +++ b/menus/linux.cson @@ -48,6 +48,13 @@ { label: '&Join Lines', command: 'editor:join-lines' } ] } + { + label: 'Columns', + submenu: [ + { label: 'Move Selection &Left', command: 'editor:move-selection-left' } + { label: 'Move Selection &Right', command: 'editor:move-selection-right' } + ] + } { label: 'Text', submenu: [ diff --git a/menus/win32.cson b/menus/win32.cson index 068817888..f612983f7 100644 --- a/menus/win32.cson +++ b/menus/win32.cson @@ -55,6 +55,13 @@ { label: '&Join Lines', command: 'editor:join-lines' } ] } + { + label: 'Columns', + submenu: [ + { label: 'Move Selection &Left', command: 'editor:move-selection-left' } + { label: 'Move Selection &Right', command: 'editor:move-selection-right' } + ] + } { label: 'Text', submenu: [ From b0f38066fa7d188115e6f257f9e34831eee138f1 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Mon, 4 May 2015 00:39:07 -0400 Subject: [PATCH 12/16] :art: Add comments to new methods --- src/text-editor.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index c35438cdb..106309235 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -932,6 +932,7 @@ class TextEditor extends Model @setSelectedBufferRange(selection.translate([insertDelta]), preserveFolds: true, autoscroll: true) + # Move any active selections one column to the left. moveSelectionLeft: -> selections = @getSelectedBufferRanges() @@ -953,6 +954,7 @@ class TextEditor extends Model @setSelectedBufferRanges(translatedRanges) + # Move any active selections one column to the right. moveSelectionRight: -> selections = @getSelectedBufferRanges() From 98aac5aba62da12692fbb88ae2c2503a13d80620 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Mon, 4 May 2015 10:04:54 -0400 Subject: [PATCH 13/16] :art: Better name for text --- src/text-editor.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 106309235..54f1d61de 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -946,9 +946,9 @@ class TextEditor extends Model if charToLeftOfSelection.start.column < 0 translatedRanges.push(selection) else - text = @buffer.getTextInRange(charToLeftOfSelection) + charTextToLeftOfSelection = @buffer.getTextInRange(charToLeftOfSelection) - @buffer.insert(selection.end, text) + @buffer.insert(selection.end, charTextToLeftOfSelection) @buffer.delete(charToLeftOfSelection) translatedRanges.push(selection.translate(translationDelta)) @@ -968,10 +968,10 @@ class TextEditor extends Model if charToRightOfSelection.end.column > @buffer.lineLengthForRow(charToRightOfSelection.end.row) translatedRanges.push(selection) else - text = @buffer.getTextInRange(charToRightOfSelection) + charTextToRightOfSelection = @buffer.getTextInRange(charToRightOfSelection) @buffer.delete(charToRightOfSelection) - @buffer.insert(selection.start, text) + @buffer.insert(selection.start, charTextToRightOfSelection) translatedRanges.push(selection.translate(translationDelta)) @setSelectedBufferRanges(translatedRanges) From de186c1d0eea729a3fdf8467152aef202f06a0a3 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Thu, 7 May 2015 13:03:19 -0400 Subject: [PATCH 14/16] Add Linux and Windows keybindings for move selection --- keymaps/linux.cson | 2 ++ keymaps/win32.cson | 2 ++ 2 files changed, 4 insertions(+) diff --git a/keymaps/linux.cson b/keymaps/linux.cson index cd71d99e7..31218b428 100644 --- a/keymaps/linux.cson +++ b/keymaps/linux.cson @@ -15,6 +15,8 @@ 'ctrl-shift-pageup': 'pane:move-item-left' 'ctrl-shift-pagedown': 'pane:move-item-right' 'F11': 'window:toggle-full-screen' + 'alt-shift-left': 'editor:move-selection-left' + 'alt-shift-right': 'editor:move-selection-right' # Sublime Parity 'ctrl-,': 'application:show-settings' diff --git a/keymaps/win32.cson b/keymaps/win32.cson index 5d3629386..7422d045d 100644 --- a/keymaps/win32.cson +++ b/keymaps/win32.cson @@ -19,6 +19,8 @@ 'ctrl-shift-left': 'pane:move-item-left' 'ctrl-shift-right': 'pane:move-item-right' 'F11': 'window:toggle-full-screen' + 'alt-shift-left': 'editor:move-selection-left' + 'alt-shift-right': 'editor:move-selection-right' # Sublime Parity 'ctrl-,': 'application:show-settings' From 3b222dbee82a2d98351296bdde0d874c4ed14eb3 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Mon, 28 Mar 2016 23:26:28 -0700 Subject: [PATCH 15/16] Don't merge selections if at start or end of line --- spec/text-editor-spec.coffee | 44 ++++++++++++++++++++++++++++++++++++ src/text-editor.coffee | 28 +++++++++++------------ 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 261d311c1..4de7168b7 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -4565,7 +4565,9 @@ describe "TextEditor", -> it "moves one active selection on one line one column to the left", -> editor.setSelectedBufferRange [[0, 4], [0, 13]] expect(editor.getSelectedText()).toBe 'quicksort' + editor.moveSelectionLeft() + expect(editor.getSelectedText()).toBe 'quicksort' expect(editor.getSelectedBufferRange()).toEqual [[0, 3], [0, 12]] @@ -4575,7 +4577,9 @@ describe "TextEditor", -> expect(selections[0].getText()).toBe 'quicksort' expect(selections[1].getText()).toBe 'function' + editor.moveSelectionLeft() + expect(selections[0].getText()).toBe 'quicksort' expect(selections[1].getText()).toBe 'function' expect(editor.getSelectedBufferRanges()).toEqual [[[0, 3], [0, 12]], [[0, 15], [0, 23]]] @@ -4586,7 +4590,9 @@ describe "TextEditor", -> expect(selections[0].getText()).toBe 'quicksort' expect(selections[1].getText()).toBe 'sort' + editor.moveSelectionLeft() + expect(selections[0].getText()).toBe 'quicksort' expect(selections[1].getText()).toBe 'sort' expect(editor.getSelectedBufferRanges()).toEqual [[[0, 3], [0, 12]], [[1, 5], [1, 9]]] @@ -4598,17 +4604,35 @@ describe "TextEditor", -> expect(selections[0].getText()).toBe 'var' expect(selections[1].getText()).toBe ' v' + editor.moveSelectionLeft() editor.moveSelectionLeft() + expect(selections[0].getText()).toBe 'var' expect(selections[1].getText()).toBe ' v' expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [0, 3]], [[1, 0], [1, 3]]] + describe "when multiple selections are active on one line", -> + it "does not change the selection", -> + editor.setSelectedBufferRanges([[[0, 0], [0, 3]], [[0, 4], [0, 13]]]) + selections = editor.getSelections() + + expect(selections[0].getText()).toBe 'var' + expect(selections[1].getText()).toBe 'quicksort' + + editor.moveSelectionLeft() + + expect(selections[0].getText()).toBe 'var' + expect(selections[1].getText()).toBe 'quicksort' + expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [0, 3]], [[0, 4], [0, 13]]] + describe ".moveSelectionRight()", -> it "moves one active selection on one line one column to the right", -> editor.setSelectedBufferRange [[0, 4], [0, 13]] expect(editor.getSelectedText()).toBe 'quicksort' + editor.moveSelectionRight() + expect(editor.getSelectedText()).toBe 'quicksort' expect(editor.getSelectedBufferRange()).toEqual [[0, 5], [0, 14]] @@ -4618,7 +4642,9 @@ describe "TextEditor", -> expect(selections[0].getText()).toBe 'quicksort' expect(selections[1].getText()).toBe 'function' + editor.moveSelectionRight() + expect(selections[0].getText()).toBe 'quicksort' expect(selections[1].getText()).toBe 'function' expect(editor.getSelectedBufferRanges()).toEqual [[[0, 5], [0, 14]], [[0, 17], [0, 25]]] @@ -4629,7 +4655,9 @@ describe "TextEditor", -> expect(selections[0].getText()).toBe 'quicksort' expect(selections[1].getText()).toBe 'sort' + editor.moveSelectionRight() + expect(selections[0].getText()).toBe 'quicksort' expect(selections[1].getText()).toBe 'sort' expect(editor.getSelectedBufferRanges()).toEqual [[[0, 5], [0, 14]], [[1, 7], [1, 11]]] @@ -4641,12 +4669,28 @@ describe "TextEditor", -> expect(selections[0].getText()).toBe 'items;' expect(selections[1].getText()).toBe 'shift();' + editor.moveSelectionRight() editor.moveSelectionRight() + expect(selections[0].getText()).toBe 'items;' expect(selections[1].getText()).toBe 'shift();' expect(editor.getSelectedBufferRanges()).toEqual [[[2, 34], [2, 40]], [[5, 22], [5, 30]]] + describe "when multiple selections are active on one line", -> + it "does not change the selection", -> + editor.setSelectedBufferRanges([[[2, 27], [2, 33]], [[2, 34], [2, 40]]]) + selections = editor.getSelections() + + expect(selections[0].getText()).toBe 'return' + expect(selections[1].getText()).toBe 'items;' + + editor.moveSelectionRight() + + expect(selections[0].getText()).toBe 'return' + expect(selections[1].getText()).toBe 'items;' + expect(editor.getSelectedBufferRanges()).toEqual [[[2, 27], [2, 33]], [[2, 34], [2, 40]]] + describe 'reading text', -> it '.lineTextForScreenRow(row)', -> editor.foldBufferRow(4) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 6f075b579..b6be33071 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -1077,46 +1077,46 @@ class TextEditor extends Model # Move any active selections one column to the left. moveSelectionLeft: -> selections = @getSelectedBufferRanges() + noSelectionAtStartOfLine = selections.every((selection) -> + selection.start.column isnt 0 + ) translationDelta = [0, -1] translatedRanges = [] @transact => - for selection in selections - charToLeftOfSelection = new Range(selection.start.translate(translationDelta), selection.start) - - if charToLeftOfSelection.start.column < 0 - translatedRanges.push(selection) - else + if noSelectionAtStartOfLine + for selection in selections + charToLeftOfSelection = new Range(selection.start.translate(translationDelta), selection.start) charTextToLeftOfSelection = @buffer.getTextInRange(charToLeftOfSelection) @buffer.insert(selection.end, charTextToLeftOfSelection) @buffer.delete(charToLeftOfSelection) translatedRanges.push(selection.translate(translationDelta)) - @setSelectedBufferRanges(translatedRanges) + @setSelectedBufferRanges(translatedRanges) # Move any active selections one column to the right. moveSelectionRight: -> selections = @getSelectedBufferRanges() + noSelectionAtEndOfLine = selections.every((selection) => + selection.end.column isnt @buffer.lineLengthForRow(selection.end.row) + ) translationDelta = [0, 1] translatedRanges = [] @transact => - for selection in selections - charToRightOfSelection = new Range(selection.end, selection.end.translate(translationDelta)) - - if charToRightOfSelection.end.column > @buffer.lineLengthForRow(charToRightOfSelection.end.row) - translatedRanges.push(selection) - else + if noSelectionAtEndOfLine + for selection in selections + charToRightOfSelection = new Range(selection.end, selection.end.translate(translationDelta)) charTextToRightOfSelection = @buffer.getTextInRange(charToRightOfSelection) @buffer.delete(charToRightOfSelection) @buffer.insert(selection.start, charTextToRightOfSelection) translatedRanges.push(selection.translate(translationDelta)) - @setSelectedBufferRanges(translatedRanges) + @setSelectedBufferRanges(translatedRanges) # Duplicate the most recent cursor's current line. duplicateLines: -> From 3068631d19b500162e3eb633cc36da5c20321597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Machist=C3=A9=20N=2E=20Quintana?= Date: Wed, 30 Mar 2016 12:48:11 -0700 Subject: [PATCH 16/16] Don't open a transaction if there's a selection at the start / end of line --- src/text-editor.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index b6be33071..58ecf4712 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -1084,8 +1084,8 @@ class TextEditor extends Model translationDelta = [0, -1] translatedRanges = [] - @transact => - if noSelectionAtStartOfLine + if noSelectionAtStartOfLine + @transact => for selection in selections charToLeftOfSelection = new Range(selection.start.translate(translationDelta), selection.start) charTextToLeftOfSelection = @buffer.getTextInRange(charToLeftOfSelection) @@ -1106,8 +1106,8 @@ class TextEditor extends Model translationDelta = [0, 1] translatedRanges = [] - @transact => - if noSelectionAtEndOfLine + if noSelectionAtEndOfLine + @transact => for selection in selections charToRightOfSelection = new Range(selection.end, selection.end.translate(translationDelta)) charTextToRightOfSelection = @buffer.getTextInRange(charToRightOfSelection)