diff --git a/spec/atom/buffer-spec.coffee b/spec/atom/buffer-spec.coffee index 69d4e78a0..a14a08d6e 100644 --- a/spec/atom/buffer-spec.coffee +++ b/spec/atom/buffer-spec.coffee @@ -243,6 +243,41 @@ describe 'Buffer', -> expect(matches[2][1]).toBe 'rr' expect(ranges[2]).toEqual [[6,34], [6,41]] + describe "when the last regex match exceeds the end of the range", -> + describe "when the portion of the match within the range also matches the regex", -> + it "calls the iterator with the truncated match", -> + matches = [] + ranges = [] + buffer.traverseRegexMatchesInRange /cu(r*)/g, [[4,0], [6,9]], (match, range) -> + matches.push(match) + ranges.push(range) + + expect(matches.length).toBe 2 + expect(ranges.length).toBe 2 + + expect(matches[0][0]).toBe 'curr' + expect(matches[0][1]).toBe 'rr' + expect(ranges[0]).toEqual [[5,6], [5,10]] + + expect(matches[1][0]).toBe 'cur' + expect(matches[1][1]).toBe 'r' + expect(ranges[1]).toEqual [[6,6], [6,9]] + + describe "when the portion of the match within the range does not matches the regex", -> + it "calls the iterator with the truncated match", -> + matches = [] + ranges = [] + buffer.traverseRegexMatchesInRange /cu(r*)e/g, [[4,0], [6,9]], (match, range) -> + matches.push(match) + ranges.push(range) + + expect(matches.length).toBe 1 + expect(ranges.length).toBe 1 + + expect(matches[0][0]).toBe 'curre' + expect(matches[0][1]).toBe 'rr' + expect(ranges[0]).toEqual [[5,6], [5,11]] + describe "when the iterator calls the 'replace' control function with a replacement string", -> it "replaces each occurrence of the regex match with the string", -> ranges = [] diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 808a7bbe4..932be1fd7 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -875,7 +875,7 @@ describe "Editor", -> expect(editor.getSelection().isReversed()).toBeFalsy() describe "select-to-beginning-of-line", -> - it "selects text from cusor position to end of line", -> + it "selects text from cusor position to beginning of line", -> editor.setCursorScreenPosition [12,2] editor.addCursorAtScreenPosition [11,3] editor.trigger 'select-to-beginning-of-line' @@ -908,6 +908,40 @@ describe "Editor", -> expect(selection2.getBufferRange()).toEqual [[11,3], [11,44]] expect(selection2.isReversed()).toBeFalsy() + describe "select-to-beginning-of-word", -> + it "selects text from cusor position to beginning of word", -> + editor.setCursorScreenPosition [0,13] + editor.addCursorAtScreenPosition [3,49] + editor.trigger 'select-to-beginning-of-word' + expect(editor.getCursors().length).toBe 2 + [cursor1, cursor2] = editor.getCursors() + expect(cursor1.getBufferPosition()).toEqual [0,4] + expect(cursor2.getBufferPosition()).toEqual [3,47] + + expect(editor.getSelections().length).toBe 2 + [selection1, selection2] = editor.getSelections() + expect(selection1.getBufferRange()).toEqual [[0,4], [0,13]] + expect(selection1.isReversed()).toBeTruthy() + expect(selection2.getBufferRange()).toEqual [[3,47], [3,49]] + expect(selection2.isReversed()).toBeTruthy() + + describe "select-to-end-of-word", -> + it "selects text from cusor position to end of word", -> + editor.setCursorScreenPosition [0,4] + editor.addCursorAtScreenPosition [3,48] + editor.trigger 'select-to-end-of-word' + expect(editor.getCursors().length).toBe 2 + [cursor1, cursor2] = editor.getCursors() + expect(cursor1.getBufferPosition()).toEqual [0,13] + expect(cursor2.getBufferPosition()).toEqual [3,50] + + expect(editor.getSelections().length).toBe 2 + [selection1, selection2] = editor.getSelections() + expect(selection1.getBufferRange()).toEqual [[0,4], [0,13]] + expect(selection1.isReversed()).toBeFalsy() + expect(selection2.getBufferRange()).toEqual [[3,48], [3,50]] + expect(selection2.isReversed()).toBeFalsy() + describe "multiple cursors", -> it "places multiple cursor with meta-click", -> editor.attachToDom() diff --git a/src/atom/buffer.coffee b/src/atom/buffer.coffee index a4c619662..d8dc4a9f3 100644 --- a/src/atom/buffer.coffee +++ b/src/atom/buffer.coffee @@ -158,7 +158,7 @@ class Buffer if matchEndIndex > endIndex regex.lastIndex = 0 - if matchStartIndex < endIndex and match = regex.exec(text[matchStartIndex..endIndex]) + if matchStartIndex < endIndex and match = regex.exec(text[matchStartIndex...endIndex]) matchLength = match[0].length matchEndIndex = matchStartIndex + matchLength else diff --git a/src/atom/composite-selection.coffee b/src/atom/composite-selection.coffee index 11b07df17..4e0e4e222 100644 --- a/src/atom/composite-selection.coffee +++ b/src/atom/composite-selection.coffee @@ -95,6 +95,14 @@ class CompositeSeleciton selection.selectToEndOfLine() for selection in @getSelections() @mergeIntersectingSelections() + selectToBeginningOfWord: -> + selection.selectToBeginningOfWord() for selection in @getSelections() + @mergeIntersectingSelections reverse: true + + selectToEndOfWord: -> + selection.selectToEndOfWord() for selection in @getSelections() + @mergeIntersectingSelections() + setBufferRange: (bufferRange, options) -> @getLastSelection().setBufferRange(bufferRange, options) diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 03772c424..9b84cc2a4 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -116,6 +116,8 @@ class Editor extends View @on 'select-to-bottom', => @selectToBottom() @on 'select-to-end-of-line', => @selectToEndOfLine() @on 'select-to-beginning-of-line', => @selectToBeginningOfLine() + @on 'select-to-end-of-word', => @selectToEndOfWord() + @on 'select-to-beginning-of-word', => @selectToBeginningOfWord() buildCursorAndSelection: -> @compositeSelection = new CompositeSelection(this) @@ -395,8 +397,10 @@ class Editor extends View selectDown: -> @compositeSelection.selectDown() selectToTop: -> @compositeSelection.selectToTop() selectToBottom: -> @compositeSelection.selectToBottom() - selectToEndOfLine: -> @compositeSelection.selectToEndOfLine() selectToBeginningOfLine: -> @compositeSelection.selectToBeginningOfLine() + selectToEndOfLine: -> @compositeSelection.selectToEndOfLine() + selectToBeginningOfWord: -> @compositeSelection.selectToBeginningOfWord() + selectToEndOfWord: -> @compositeSelection.selectToEndOfWord() selectToScreenPosition: (position) -> @compositeSelection.selectToScreenPosition(position) clearSelections: -> @compositeSelection.clearSelections() diff --git a/src/atom/keybindings/apple.coffee b/src/atom/keybindings/apple.coffee index 64b7ef0c1..5c045bd4b 100644 --- a/src/atom/keybindings/apple.coffee +++ b/src/atom/keybindings/apple.coffee @@ -1,9 +1,13 @@ window.keymap.bindKeys '.editor' 'meta-up': 'move-to-top' - 'meta-shift-up': 'select-to-top' 'meta-down': 'move-to-bottom' - 'meta-shift-down': 'select-to-bottom' 'meta-right': 'move-to-end-of-line' 'meta-left': 'move-to-beginning-of-line' 'alt-left': 'move-to-beginning-of-word' - 'alt-right': 'move-to-end-of-word' \ No newline at end of file + 'alt-right': 'move-to-end-of-word' + 'meta-shift-up': 'select-to-top' + 'meta-shift-down': 'select-to-bottom' + 'meta-shift-left': 'select-to-beginning-of-line' + 'meta-shift-right': 'select-to-end-of-line' + 'alt-shift-left': 'select-to-beginning-of-word' + 'alt-shift-right': 'select-to-end-of-word' \ No newline at end of file diff --git a/src/atom/selection.coffee b/src/atom/selection.coffee index 6cca582d8..e378cef99 100644 --- a/src/atom/selection.coffee +++ b/src/atom/selection.coffee @@ -236,6 +236,14 @@ class Selection extends View @modifySelection => @cursor.moveToEndOfLine() + selectToBeginningOfWord: -> + @modifySelection => + @cursor.moveToBeginningOfWord() + + selectToEndOfWord: -> + @modifySelection => + @cursor.moveToEndOfWord() + cut: (maintainPasteboard=false) -> @copy(maintainPasteboard) @delete()