mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 23:48:05 +03:00
Implement backspace on Buffer
This commit is contained in:
parent
045c3c39bf
commit
3a423e2a16
@ -69,6 +69,31 @@ describe 'Buffer', ->
|
|||||||
expect(buffer.getLine(3)).toBe originalLine.substring(27)
|
expect(buffer.getLine(3)).toBe originalLine.substring(27)
|
||||||
expect(buffer.getLine(4)).toBe lineBelowOriginalLine
|
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 ".save()", ->
|
||||||
describe "when the buffer has a path", ->
|
describe "when the buffer has a path", ->
|
||||||
filePath = null
|
filePath = null
|
||||||
|
@ -218,7 +218,7 @@ describe "Editor", ->
|
|||||||
expect(editor).not.toMatchSelector ':focus'
|
expect(editor).not.toMatchSelector ':focus'
|
||||||
expect(editor.hiddenInput).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", ->
|
it "inserts the typed character at the cursor position, both in the buffer and the pre element", ->
|
||||||
editor.setPosition(row: 1, col: 6)
|
editor.setPosition(row: 1, col: 6)
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ describe "Editor", ->
|
|||||||
expect(editor.getPosition()).toEqual(row: 1, col: 7)
|
expect(editor.getPosition()).toEqual(row: 1, col: 7)
|
||||||
expect(editor.lines.find('pre:eq(1)')).toHaveText editor.getCurrentLine()
|
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", ->
|
describe "when the cursor is at the beginning of a line", ->
|
||||||
it "inserts an empty line before it", ->
|
it "inserts an empty line before it", ->
|
||||||
editor.setPosition(row: 1, col: 0)
|
editor.setPosition(row: 1, col: 0)
|
||||||
|
@ -41,6 +41,13 @@ class Buffer
|
|||||||
start: {row, col}
|
start: {row, col}
|
||||||
end: {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: ->
|
numLines: ->
|
||||||
@getLines().length
|
@getLines().length
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user