diff --git a/spec/atom/buffer-spec.coffee b/spec/atom/buffer-spec.coffee index 431ee85af..09ba63022 100644 --- a/spec/atom/buffer-spec.coffee +++ b/spec/atom/buffer-spec.coffee @@ -69,6 +69,31 @@ describe 'Buffer', -> expect(buffer.getLine(3)).toBe originalLine.substring(27) expect(buffer.getLine(4)).toBe lineBelowOriginalLine + describe ".backspace(position)", -> + it "can remove a character from middle of line", -> + originalLineLength = buffer.getLine(1).length + expect(buffer.getLine(1).charAt(6)).toBe 's' + buffer.backspace({row: 1, col: 7}) + expect(buffer.getLine(1).charAt(6)).toBe 'o' + expect(buffer.getLine(1).length).toBe originalLineLength - 1 + + it "can remove a character from the end of the line", -> + originalLineLength = buffer.getLine(1).length + expect(buffer.getLine(1).charAt(originalLineLength - 1)).toBe '{' + buffer.backspace({row: 1, col: originalLineLength}) + expect(buffer.getLine(1).length).toBe originalLineLength - 1 + expect(buffer.getLine(1).charAt(originalLineLength - 2)).toBe '{' + + it "can remove a character from the begining of the line", -> + originalLineCount = buffer.getLines().length + originalLineLengthFromAbove = buffer.getLine(11).length + originalLineLength = buffer.getLine(12).length + expect(buffer.getLine(12).charAt(0)).toBe '}' + buffer.backspace({row: 12, col: 0}) + expect(buffer.getLines().length).toBe originalLineCount - 1 + expect(buffer.getLine(11).charAt(originalLineLengthFromAbove)).toBe '}' + expect(buffer.getLine(11).length).toBe originalLineLengthFromAbove + originalLineLength + describe ".save()", -> describe "when the buffer has a path", -> filePath = null diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 40bd8dc0f..8bf439241 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -218,7 +218,7 @@ describe "Editor", -> expect(editor).not.toMatchSelector ':focus' expect(editor.hiddenInput).toMatchSelector ':focus' - fdescribe "when text input events are triggered on the hidden input element", -> + describe "when text input events are triggered on the hidden input element", -> it "inserts the typed character at the cursor position, both in the buffer and the pre element", -> editor.setPosition(row: 1, col: 6) @@ -230,7 +230,7 @@ describe "Editor", -> expect(editor.getPosition()).toEqual(row: 1, col: 7) expect(editor.lines.find('pre:eq(1)')).toHaveText editor.getCurrentLine() - fdescribe "when return is pressed", -> + describe "when return is pressed", -> describe "when the cursor is at the beginning of a line", -> it "inserts an empty line before it", -> editor.setPosition(row: 1, col: 0) diff --git a/src/atom/buffer.coffee b/src/atom/buffer.coffee index cbb7eaf55..6021647f4 100644 --- a/src/atom/buffer.coffee +++ b/src/atom/buffer.coffee @@ -41,6 +41,13 @@ class Buffer start: {row, col} end: {row, col} + backspace: ({row, col}) -> + line = @lines[row] + if col == 0 + @lines[row-1..row] = @lines[row - 1] + @lines[row] + else + @lines[row] = line[row..col] + line[col + 1..] + numLines: -> @getLines().length