From 722b685b2ede98e685f8eedbcb732b5c804c2875 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 29 Mar 2012 11:33:15 -0700 Subject: [PATCH] Editor handles backspace-to-beginning-of-word --- spec/atom/editor-spec.coffee | 23 +++++++++++++++++++++++ src/atom/composite-selection.coffee | 3 +++ src/atom/editor.coffee | 9 ++++----- src/atom/selection.coffee | 4 ++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 932be1fd7..034bcf3af 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -1472,6 +1472,29 @@ describe "Editor", -> editor.trigger keydownEvent('backspace') expect(editor.buffer.lineForRow(0)).toBe 'var qsort = function () {' + describe "backspace-to-beginning-of-word", -> + it "deletes all text between the cursor and the beginning of the word", -> + editor.setCursorBufferPosition([1, 24]) + editor.addCursorAtBufferPosition([2, 5]) + [cursor1, cursor2] = editor.getCursors() + + editor.trigger 'backspace-to-beginning-of-word' + expect(buffer.lineForRow(1)).toBe ' var sort = function(ems) {' + expect(buffer.lineForRow(2)).toBe ' f (items.length <= 1) return items;' + expect(cursor1.getBufferPosition()).toEqual [1, 22] + expect(cursor2.getBufferPosition()).toEqual [2, 4] + + editor.trigger 'backspace-to-beginning-of-word' + expect(buffer.lineForRow(1)).toBe ' var sort = functionems) f (items.length <= 1) return items;' + expect(cursor1.getBufferPosition()).toEqual [1, 21] + expect(cursor2.getBufferPosition()).toEqual [1, 26] + + describe "when text is selected", -> + it "deletes only selected text", -> + editor.setSelectionBufferRange([[1, 24], [1, 27]]) + editor.trigger 'backspace-to-beginning-of-word' + expect(buffer.lineForRow(1)).toBe ' var sort = function(it) {' + describe "when delete is pressed", -> describe "when the cursor is on the middle of a line", -> it "deletes the character following the cursor", -> diff --git a/src/atom/composite-selection.coffee b/src/atom/composite-selection.coffee index 4e0e4e222..938c1c0ef 100644 --- a/src/atom/composite-selection.coffee +++ b/src/atom/composite-selection.coffee @@ -57,6 +57,9 @@ class CompositeSeleciton backspace: -> @modifySelectedText (selection) -> selection.backspace() + backspaceToBeginningOfWord: -> + @modifySelectedText (selection) -> selection.backspaceToBeginningOfWord() + delete: -> @modifySelectedText (selection) -> selection.delete() diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 9b84cc2a4..6d113398b 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -91,6 +91,7 @@ class Editor extends View @on 'select-down', => @selectDown() @on 'newline', => @insertText("\n") @on 'backspace', => @backspace() + @on 'backspace-to-beginning-of-word', => @backspaceToBeginningOfWord() @on 'delete', => @delete() @on 'cut', => @cutSelection() @on 'copy', => @copySelection() @@ -403,6 +404,9 @@ class Editor extends View selectToEndOfWord: -> @compositeSelection.selectToEndOfWord() selectToScreenPosition: (position) -> @compositeSelection.selectToScreenPosition(position) clearSelections: -> @compositeSelection.clearSelections() + backspace: -> @compositeSelection.backspace() + backspaceToBeginningOfWord: -> @compositeSelection.backspaceToBeginningOfWord() + delete: -> @compositeSelection.delete() setText: (text) -> @buffer.setText(text) getText: -> @buffer.getText() @@ -424,11 +428,6 @@ class Editor extends View foldSelection: -> @getSelection().fold() - backspace: -> - @compositeSelection.backspace() - - delete: -> - @compositeSelection.delete() undo: -> @buffer.undo() diff --git a/src/atom/selection.coffee b/src/atom/selection.coffee index e378cef99..f26a0666f 100644 --- a/src/atom/selection.coffee +++ b/src/atom/selection.coffee @@ -129,6 +129,10 @@ class Selection extends View @selectLeft() if @isEmpty() @deleteSelectedText() + backspaceToBeginningOfWord: -> + @selectToBeginningOfWord() if @isEmpty() + @deleteSelectedText() + delete: -> @selectRight() if @isEmpty() @deleteSelectedText()