From 8577bf9a4c3cf9928e8b9ec044ebad0444a99e62 Mon Sep 17 00:00:00 2001 From: karlin Date: Fri, 6 Jun 2014 08:37:59 -0400 Subject: [PATCH 1/2] select to beginning of next or previous paragraph commands --- spec/editor-spec.coffee | 24 ++++++++++++++++++++++++ src/editor-component.coffee | 2 ++ src/editor-view.coffee | 2 ++ src/editor.coffee | 14 ++++++++++++++ src/selection.coffee | 10 ++++++++++ 5 files changed, 52 insertions(+) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index f037ac6af..16a231d9a 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -863,6 +863,30 @@ describe "Editor", -> expect(selection1.getScreenRange()).toEqual [[3, 0], [4, 5]] expect(selection2.getScreenRange()).toEqual [[5, 6], [6, 2]] + fdescribe ".selectToBeginningOfNextParagraph()", -> + it "selects from the cursor to first line of the next paragraph", -> + editor.setSelectedBufferRange([[3, 0], [4, 5]]) + editor.addCursorAtScreenPosition([5, 6]) + editor.selectToScreenPosition([6, 2]) + + editor.selectToBeginningOfNextParagraph() + + selections = editor.getSelections() + expect(selections.length).toBe 1 + expect(selections[0].getScreenRange()).toEqual [[3, 0], [10, 0]] + + fdescribe ".selectToBeginningOfPreviousParagraph()", -> + it "selects from the cursor to the first line of the pevious paragraph", -> + editor.setSelectedBufferRange([[3, 0], [4, 5]]) + editor.addCursorAtScreenPosition([5, 6]) + editor.selectToScreenPosition([6, 2]) + + editor.selectToBeginningOfPreviousParagraph() + + selections = editor.getSelections() + expect(selections.length).toBe 1 + expect(selections[0].getScreenRange()).toEqual [[0, 0], [5, 6]] + it "merges selections if they intersect, maintaining the directionality of the last selection", -> editor.setCursorScreenPosition([4, 10]) editor.selectToScreenPosition([5, 27]) diff --git a/src/editor-component.coffee b/src/editor-component.coffee index c93b75eb3..13568ea7f 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -202,6 +202,8 @@ EditorComponent = React.createClass 'editor:move-to-beginning-of-next-word': => editor.moveCursorToBeginningOfNextWord() 'editor:move-to-previous-word-boundary': => editor.moveCursorToPreviousWordBoundary() 'editor:move-to-next-word-boundary': => editor.moveCursorToNextWordBoundary() + 'editor:select-to-beginning-of-next-paragraph': => editor.selectToBeginningOfNextParagraph() + 'editor:select-to-beginning-of-previous-paragraph': => editor.selectToBeginningOfPreviousParagraph() 'editor:select-to-end-of-line': => editor.selectToEndOfLine() 'editor:select-to-beginning-of-line': => editor.selectToBeginningOfLine() 'editor:select-to-end-of-word': => editor.selectToEndOfWord() diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 18f8a2427..564a439ba 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -171,6 +171,8 @@ class EditorView extends View 'editor:move-to-beginning-of-next-word': => @editor.moveCursorToBeginningOfNextWord() 'editor:move-to-previous-word-boundary': => @editor.moveCursorToPreviousWordBoundary() 'editor:move-to-next-word-boundary': => @editor.moveCursorToNextWordBoundary() + 'editor:select-to-beginning-of-next-paragraph': => @editor.selectToBeginningOfNextParagraph() + 'editor:select-to-beginning-of-previous-paragraph': => @editor.selectToBeginningOfPreviousParagraph() 'editor:select-to-end-of-line': => @editor.selectToEndOfLine() 'editor:select-to-beginning-of-line': => @editor.selectToBeginningOfLine() 'editor:select-to-end-of-word': => @editor.selectToEndOfWord() diff --git a/src/editor.coffee b/src/editor.coffee index d995b2757..61aac473b 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -1725,6 +1725,20 @@ class Editor extends Model selectWord: -> @expandSelectionsForward (selection) => selection.selectWord() + # Public: Expand selections to the beginning of the next paragraph. + # + # Operates on all selections. Moves the cursor to the beginning of the next + # paragraph while preserving the selection's tail position. + selectToBeginningOfNextParagraph: -> + @expandSelectionsForward (selection) => selection.selectToBeginningOfNextParagraph() + + # Public: Expand selections to the beginning of the next paragraph. + # + # Operates on all selections. Moves the cursor to the beginning of the next + # paragraph while preserving the selection's tail position. + selectToBeginningOfPreviousParagraph: -> + @expandSelectionsBackward (selection) => selection.selectToBeginningOfPreviousParagraph() + # Public: Select the range of the given marker if it is valid. # # marker - A {DisplayBufferMarker} diff --git a/src/selection.coffee b/src/selection.coffee index e3eeb15a3..bf6b06bdf 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -236,6 +236,16 @@ class Selection extends Model selectToNextWordBoundary: -> @modifySelection => @cursor.moveToNextWordBoundary() + # Public: Selects all the text from the current cursor position to the + # beginning of the next paragraph. + selectToBeginningOfNextParagraph: -> + @modifySelection => @cursor.moveToBeginningOfNextParagraph() + + # Public: Selects all the text from the current cursor position to the + # beginning of the previous paragraph. + selectToBeginningOfPreviousParagraph: -> + @modifySelection => @cursor.moveToBeginningOfPreviousParagraph() + # Public: Moves the selection down one row. addSelectionBelow: -> range = (@getGoalBufferRange() ? @getBufferRange()).copy() From 2f45685a0613eda369645e1938385f85a75bcb80 Mon Sep 17 00:00:00 2001 From: karlin Date: Fri, 6 Jun 2014 08:40:15 -0400 Subject: [PATCH 2/2] remove focused describes --- spec/editor-spec.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 16a231d9a..33f98fb05 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -863,7 +863,7 @@ describe "Editor", -> expect(selection1.getScreenRange()).toEqual [[3, 0], [4, 5]] expect(selection2.getScreenRange()).toEqual [[5, 6], [6, 2]] - fdescribe ".selectToBeginningOfNextParagraph()", -> + describe ".selectToBeginningOfNextParagraph()", -> it "selects from the cursor to first line of the next paragraph", -> editor.setSelectedBufferRange([[3, 0], [4, 5]]) editor.addCursorAtScreenPosition([5, 6]) @@ -875,7 +875,7 @@ describe "Editor", -> expect(selections.length).toBe 1 expect(selections[0].getScreenRange()).toEqual [[3, 0], [10, 0]] - fdescribe ".selectToBeginningOfPreviousParagraph()", -> + describe ".selectToBeginningOfPreviousParagraph()", -> it "selects from the cursor to the first line of the pevious paragraph", -> editor.setSelectedBufferRange([[3, 0], [4, 5]]) editor.addCursorAtScreenPosition([5, 6])