mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Rename Buffer.getLine to lineForRow
This commit is contained in:
@@ -52,9 +52,9 @@ describe 'Buffer', ->
|
||||
|
||||
buffer.change range, "foo"
|
||||
|
||||
expect(buffer.getLine(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.getLine(3)).toBe " foovar pivot = items.shift(), current, left = [], right = [];"
|
||||
expect(buffer.getLine(4)).toBe " while(items.length > 0) {"
|
||||
expect(buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.lineForRow(3)).toBe " foovar pivot = items.shift(), current, left = [], right = [];"
|
||||
expect(buffer.lineForRow(4)).toBe " while(items.length > 0) {"
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -71,12 +71,12 @@ describe 'Buffer', ->
|
||||
|
||||
buffer.change range, "foo\n\nbar\nbaz"
|
||||
|
||||
expect(buffer.getLine(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.getLine(3)).toBe " foo"
|
||||
expect(buffer.getLine(4)).toBe ""
|
||||
expect(buffer.getLine(5)).toBe "bar"
|
||||
expect(buffer.getLine(6)).toBe "bazvar pivot = items.shift(), current, left = [], right = [];"
|
||||
expect(buffer.getLine(7)).toBe " while(items.length > 0) {"
|
||||
expect(buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.lineForRow(3)).toBe " foo"
|
||||
expect(buffer.lineForRow(4)).toBe ""
|
||||
expect(buffer.lineForRow(5)).toBe "bar"
|
||||
expect(buffer.lineForRow(6)).toBe "bazvar pivot = items.shift(), current, left = [], right = [];"
|
||||
expect(buffer.lineForRow(7)).toBe " while(items.length > 0) {"
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -94,9 +94,9 @@ describe 'Buffer', ->
|
||||
|
||||
buffer.change range, ""
|
||||
|
||||
expect(buffer.getLine(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.getLine(3)).toBe " pivot = items.shift(), current, left = [], right = [];"
|
||||
expect(buffer.getLine(4)).toBe " while(items.length > 0) {"
|
||||
expect(buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.lineForRow(3)).toBe " pivot = items.shift(), current, left = [], right = [];"
|
||||
expect(buffer.lineForRow(4)).toBe " while(items.length > 0) {"
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -113,9 +113,9 @@ describe 'Buffer', ->
|
||||
|
||||
buffer.change range, ""
|
||||
|
||||
expect(buffer.getLine(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.getLine(3)).toBe " var pivot = while(items.length > 0) {"
|
||||
expect(buffer.getLine(4)).toBe " current = items.shift();"
|
||||
expect(buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.lineForRow(3)).toBe " var pivot = while(items.length > 0) {"
|
||||
expect(buffer.lineForRow(4)).toBe " current = items.shift();"
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -132,9 +132,9 @@ describe 'Buffer', ->
|
||||
|
||||
buffer.change range, ""
|
||||
|
||||
expect(buffer.getLine(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.getLine(3)).toBe " var pivot = sort(Array.apply(this, arguments));"
|
||||
expect(buffer.getLine(4)).toBe "};"
|
||||
expect(buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.lineForRow(3)).toBe " var pivot = sort(Array.apply(this, arguments));"
|
||||
expect(buffer.lineForRow(4)).toBe "};"
|
||||
|
||||
describe "when used to replace text with other text (called with non-empty range and non-empty string)", ->
|
||||
it "replaces the old text with the new text", ->
|
||||
@@ -145,10 +145,10 @@ describe 'Buffer', ->
|
||||
|
||||
buffer.change range, "foo\nbar"
|
||||
|
||||
expect(buffer.getLine(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.getLine(3)).toBe " var pivot = foo"
|
||||
expect(buffer.getLine(4)).toBe "barsort(Array.apply(this, arguments));"
|
||||
expect(buffer.getLine(5)).toBe "};"
|
||||
expect(buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(buffer.lineForRow(3)).toBe " var pivot = foo"
|
||||
expect(buffer.lineForRow(4)).toBe "barsort(Array.apply(this, arguments));"
|
||||
expect(buffer.lineForRow(5)).toBe "};"
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -160,7 +160,7 @@ describe 'Buffer', ->
|
||||
describe ".setText(text)", ->
|
||||
it "changes the entire contents of the buffer and emits a change event", ->
|
||||
lastRow = buffer.lastRow()
|
||||
expectedPreRange = new Range([0,0], [lastRow, buffer.getLine(lastRow).length])
|
||||
expectedPreRange = new Range([0,0], [lastRow, buffer.lineForRow(lastRow).length])
|
||||
changeHandler = jasmine.createSpy('changeHandler')
|
||||
buffer.on 'change', changeHandler
|
||||
|
||||
@@ -208,16 +208,16 @@ describe 'Buffer', ->
|
||||
range = new Range([2,8], [2,13])
|
||||
expect(buffer.getTextInRange(range)).toBe "items"
|
||||
|
||||
lineLength = buffer.getLine(2).length
|
||||
lineLength = buffer.lineForRow(2).length
|
||||
range = new Range([2,0], [2,lineLength])
|
||||
expect(buffer.getTextInRange(range)).toBe " if (items.length <= 1) return items;"
|
||||
|
||||
describe "when range spans multiple lines", ->
|
||||
it "returns characters in range (including newlines)", ->
|
||||
lineLength = buffer.getLine(2).length
|
||||
lineLength = buffer.lineForRow(2).length
|
||||
range = new Range([2,0], [3,0])
|
||||
expect(buffer.getTextInRange(range)).toBe " if (items.length <= 1) return items;\n"
|
||||
|
||||
lineLength = buffer.getLine(2).length
|
||||
lineLength = buffer.lineForRow(2).length
|
||||
range = new Range([2,10], [4,10])
|
||||
expect(buffer.getTextInRange(range)).toBe "ems.length <= 1) return items;\n var pivot = items.shift(), current, left = [], right = [];\n while("
|
||||
|
||||
@@ -18,11 +18,11 @@ describe "Editor", ->
|
||||
describe "text rendering", ->
|
||||
it "creates a line element for each line in the buffer with the html-escaped text of the line", ->
|
||||
expect(editor.lines.find('.line').length).toEqual(buffer.numLines())
|
||||
expect(buffer.getLine(2)).toContain('<')
|
||||
expect(buffer.lineForRow(2)).toContain('<')
|
||||
expect(editor.lines.find('.line:eq(2)').html()).toContain '<'
|
||||
|
||||
# renders empty lines with a non breaking space
|
||||
expect(buffer.getLine(10)).toBe ''
|
||||
expect(buffer.lineForRow(10)).toBe ''
|
||||
expect(editor.lines.find('.line:eq(10)').html()).toBe ' '
|
||||
|
||||
it "syntax highlights code based on the file type", ->
|
||||
@@ -273,7 +273,7 @@ describe "Editor", ->
|
||||
describe "when down is pressed on the last line", ->
|
||||
it "moves the cursor to the end of line, but retains the goal column", ->
|
||||
lastLineIndex = buffer.getLines().length - 1
|
||||
lastLine = buffer.getLine(lastLineIndex)
|
||||
lastLine = buffer.lineForRow(lastLineIndex)
|
||||
expect(lastLine.length).toBeGreaterThan(0)
|
||||
|
||||
editor.setCursorScreenPosition(row: lastLineIndex, column: 1)
|
||||
@@ -285,7 +285,7 @@ describe "Editor", ->
|
||||
|
||||
it "retains a goal column of 0", ->
|
||||
lastLineIndex = buffer.getLines().length - 1
|
||||
lastLine = buffer.getLine(lastLineIndex)
|
||||
lastLine = buffer.lineForRow(lastLineIndex)
|
||||
expect(lastLine.length).toBeGreaterThan(0)
|
||||
|
||||
editor.setCursorScreenPosition(row: lastLineIndex, column: 0)
|
||||
@@ -342,7 +342,7 @@ describe "Editor", ->
|
||||
it "wraps to the end of the previous line", ->
|
||||
editor.setCursorScreenPosition(row: 1, column: 0)
|
||||
editor.moveCursorLeft()
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: buffer.getLine(0).length)
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: buffer.lineForRow(0).length)
|
||||
|
||||
describe "when the cursor is on the first line", ->
|
||||
it "remains in the same position (0,0)", ->
|
||||
@@ -353,14 +353,14 @@ describe "Editor", ->
|
||||
describe "when right is pressed on the last column", ->
|
||||
describe "when there is a subsequent line", ->
|
||||
it "wraps to the beginning of the next line", ->
|
||||
editor.setCursorScreenPosition(row: 0, column: buffer.getLine(0).length)
|
||||
editor.setCursorScreenPosition(row: 0, column: buffer.lineForRow(0).length)
|
||||
editor.moveCursorRight()
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 1, column: 0)
|
||||
|
||||
describe "when the cursor is on the last line", ->
|
||||
it "remains in the same position", ->
|
||||
lastLineIndex = buffer.getLines().length - 1
|
||||
lastLine = buffer.getLine(lastLineIndex)
|
||||
lastLine = buffer.lineForRow(lastLineIndex)
|
||||
expect(lastLine.length).toBeGreaterThan(0)
|
||||
|
||||
lastPosition = { row: lastLineIndex, column: lastLine.length }
|
||||
@@ -625,7 +625,7 @@ describe "Editor", ->
|
||||
it "replaces the selected text with the typed text", ->
|
||||
editor.selection.setBufferRange(new Range([1, 6], [2, 4]))
|
||||
editor.hiddenInput.textInput 'q'
|
||||
expect(buffer.getLine(1)).toBe ' var qif (items.length <= 1) return items;'
|
||||
expect(buffer.lineForRow(1)).toBe ' var qif (items.length <= 1) return items;'
|
||||
|
||||
describe "when return is pressed", ->
|
||||
describe "when the cursor is at the beginning of a line", ->
|
||||
@@ -652,7 +652,7 @@ describe "Editor", ->
|
||||
|
||||
describe "when the cursor is on the end of a line", ->
|
||||
it "inserts an empty line after it", ->
|
||||
editor.setCursorScreenPosition(row: 1, column: buffer.getLine(1).length)
|
||||
editor.setCursorScreenPosition(row: 1, column: buffer.lineForRow(1).length)
|
||||
|
||||
editor.trigger keydownEvent('enter')
|
||||
|
||||
@@ -663,26 +663,26 @@ describe "Editor", ->
|
||||
describe "when the cursor is on the middle of the line", ->
|
||||
it "removes the character before the cursor", ->
|
||||
editor.setCursorScreenPosition(row: 1, column: 7)
|
||||
expect(buffer.getLine(1)).toBe " var sort = function(items) {"
|
||||
expect(buffer.lineForRow(1)).toBe " var sort = function(items) {"
|
||||
|
||||
editor.trigger keydownEvent('backspace')
|
||||
|
||||
line = buffer.getLine(1)
|
||||
line = buffer.lineForRow(1)
|
||||
expect(line).toBe " var ort = function(items) {"
|
||||
expect(editor.lines.find('.line:eq(1)')).toHaveText line
|
||||
expect(editor.getCursorScreenPosition()).toEqual {row: 1, column: 6}
|
||||
|
||||
describe "when the cursor is at the beginning of a line", ->
|
||||
it "joins it with the line above", ->
|
||||
originalLine0 = buffer.getLine(0)
|
||||
originalLine0 = buffer.lineForRow(0)
|
||||
expect(originalLine0).toBe "var quicksort = function () {"
|
||||
expect(buffer.getLine(1)).toBe " var sort = function(items) {"
|
||||
expect(buffer.lineForRow(1)).toBe " var sort = function(items) {"
|
||||
|
||||
editor.setCursorScreenPosition(row: 1, column: 0)
|
||||
editor.trigger keydownEvent('backspace')
|
||||
|
||||
line0 = buffer.getLine(0)
|
||||
line1 = buffer.getLine(1)
|
||||
line0 = buffer.lineForRow(0)
|
||||
line1 = buffer.lineForRow(1)
|
||||
expect(line0).toBe "var quicksort = function () { var sort = function(items) {"
|
||||
expect(line1).toBe " if (items.length <= 1) return items;"
|
||||
|
||||
@@ -699,47 +699,47 @@ describe "Editor", ->
|
||||
it "deletes the selection, but not the character before it", ->
|
||||
editor.selection.setBufferRange(new Range([0,5], [0,9]))
|
||||
editor.trigger keydownEvent('backspace')
|
||||
expect(editor.buffer.getLine(0)).toBe 'var qsort = function () {'
|
||||
expect(editor.buffer.lineForRow(0)).toBe 'var qsort = function () {'
|
||||
|
||||
describe "when delete is pressed", ->
|
||||
describe "when the cursor is on the middle of a line", ->
|
||||
it "deletes the character following the cursor", ->
|
||||
editor.setCursorScreenPosition([1, 6])
|
||||
editor.trigger keydownEvent('delete')
|
||||
expect(buffer.getLine(1)).toBe ' var ort = function(items) {'
|
||||
expect(buffer.lineForRow(1)).toBe ' var ort = function(items) {'
|
||||
|
||||
describe "when the cursor is on the end of a line", ->
|
||||
it "joins the line with the following line", ->
|
||||
editor.setCursorScreenPosition([1, buffer.getLine(1).length])
|
||||
editor.setCursorScreenPosition([1, buffer.lineForRow(1).length])
|
||||
editor.trigger keydownEvent('delete')
|
||||
expect(buffer.getLine(1)).toBe ' var sort = function(items) { if (items.length <= 1) return items;'
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = function(items) { if (items.length <= 1) return items;'
|
||||
|
||||
describe "when there is a selection", ->
|
||||
it "deletes the selection, but not the character following it", ->
|
||||
editor.selection.setBufferRange(new Range([1,6], [1,8]))
|
||||
editor.trigger keydownEvent 'delete'
|
||||
expect(buffer.getLine(1)).toBe ' var rt = function(items) {'
|
||||
expect(buffer.lineForRow(1)).toBe ' var rt = function(items) {'
|
||||
|
||||
describe "when the cursor is on the last column of the last line", ->
|
||||
it "does nothing, but doesn't raise an error", ->
|
||||
editor.setCursorScreenPosition([12, buffer.getLine(12).length])
|
||||
editor.setCursorScreenPosition([12, buffer.lineForRow(12).length])
|
||||
editor.trigger keydownEvent('delete')
|
||||
expect(buffer.getLine(12)).toBe '};'
|
||||
expect(buffer.lineForRow(12)).toBe '};'
|
||||
|
||||
describe "when undo/redo events are triggered on the editor", ->
|
||||
it "undoes/redoes the last change", ->
|
||||
buffer.insert [0, 0], "foo"
|
||||
editor.trigger 'undo'
|
||||
expect(buffer.getLine(0)).not.toContain "foo"
|
||||
expect(buffer.lineForRow(0)).not.toContain "foo"
|
||||
|
||||
editor.trigger 'redo'
|
||||
expect(buffer.getLine(0)).toContain "foo"
|
||||
expect(buffer.lineForRow(0)).toContain "foo"
|
||||
|
||||
describe "when multiple lines are removed from the buffer (regression)", ->
|
||||
it "removes all of them from the dom", ->
|
||||
buffer.change(new Range([6, 24], [12, 0]), '')
|
||||
expect(editor.find('.line').length).toBe 7
|
||||
expect(editor.find('.line:eq(6)').text()).toBe(buffer.getLine(6))
|
||||
expect(editor.find('.line:eq(6)').text()).toBe(buffer.lineForRow(6))
|
||||
|
||||
describe "when the editor is attached to the dom", ->
|
||||
it "calculates line height and char width and updates the pixel position of the cursor", ->
|
||||
@@ -770,9 +770,9 @@ describe "Editor", ->
|
||||
|
||||
describe ".clipScreenPosition(point)", ->
|
||||
it "selects the nearest valid position to the given point", ->
|
||||
expect(editor.clipScreenPosition(row: 1000, column: 0)).toEqual(row: buffer.lastRow(), column: buffer.getLine(buffer.lastRow()).length)
|
||||
expect(editor.clipScreenPosition(row: 1000, column: 0)).toEqual(row: buffer.lastRow(), column: buffer.lineForRow(buffer.lastRow()).length)
|
||||
expect(editor.clipScreenPosition(row: -5, column: 0)).toEqual(row: 0, column: 0)
|
||||
expect(editor.clipScreenPosition(row: 1, column: 10000)).toEqual(row: 1, column: buffer.getLine(1).length)
|
||||
expect(editor.clipScreenPosition(row: 1, column: 10000)).toEqual(row: 1, column: buffer.lineForRow(1).length)
|
||||
expect(editor.clipScreenPosition(row: 1, column: -5)).toEqual(row: 1, column: 0)
|
||||
|
||||
describe "cut, copy & paste", ->
|
||||
@@ -784,7 +784,7 @@ describe "Editor", ->
|
||||
it "removes the selected text from the buffer and places it on the pasteboard", ->
|
||||
editor.getSelection().setBufferRange new Range([0,4], [0,9])
|
||||
editor.trigger "cut"
|
||||
expect(editor.buffer.getLine(0)).toBe "var sort = function () {"
|
||||
expect(editor.buffer.lineForRow(0)).toBe "var sort = function () {"
|
||||
expect($native.readFromPasteboard()).toBe 'quick'
|
||||
|
||||
describe "when a copy event is triggered", ->
|
||||
@@ -797,12 +797,12 @@ describe "Editor", ->
|
||||
it "pastes text into the buffer", ->
|
||||
editor.setCursorScreenPosition [0, 4]
|
||||
editor.trigger "paste"
|
||||
expect(editor.buffer.getLine(0)).toBe "var firstquicksort = function () {"
|
||||
expect(editor.buffer.lineForRow(0)).toBe "var firstquicksort = function () {"
|
||||
|
||||
expect(editor.buffer.getLine(1)).toBe " var sort = function(items) {"
|
||||
expect(editor.buffer.lineForRow(1)).toBe " var sort = function(items) {"
|
||||
editor.getSelection().setBufferRange new Range([1,6], [1,10])
|
||||
editor.trigger "paste"
|
||||
expect(editor.buffer.getLine(1)).toBe " var first = function(items) {"
|
||||
expect(editor.buffer.lineForRow(1)).toBe " var first = function(items) {"
|
||||
|
||||
describe "folding", ->
|
||||
describe "when a fold-selection event is triggered", ->
|
||||
|
||||
@@ -49,8 +49,8 @@ describe "Highlighter", ->
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
expect(event.oldRange).toEqual new Range([2, 0], [5, buffer.getLine(5).length])
|
||||
expect(event.newRange).toEqual new Range([2, 0], [5, buffer.getLine(5).length])
|
||||
expect(event.oldRange).toEqual new Range([2, 0], [5, buffer.lineForRow(5).length])
|
||||
expect(event.newRange).toEqual new Range([2, 0], [5, buffer.lineForRow(5).length])
|
||||
|
||||
it "resumes highlighting with the state of the previous line", ->
|
||||
buffer.insert([0, 0], '/*')
|
||||
@@ -92,8 +92,8 @@ describe "Highlighter", ->
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
expect(event.oldRange).toEqual new Range([2, 0], [5, buffer.getLine(4).length])
|
||||
expect(event.newRange).toEqual new Range([2, 0], [4, buffer.getLine(4).length])
|
||||
expect(event.oldRange).toEqual new Range([2, 0], [5, buffer.lineForRow(4).length])
|
||||
expect(event.newRange).toEqual new Range([2, 0], [4, buffer.lineForRow(4).length])
|
||||
|
||||
describe "when lines are both updated and inserted", ->
|
||||
it "updates tokens to reflect the inserted lines", ->
|
||||
@@ -135,5 +135,5 @@ describe "Highlighter", ->
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
expect(event.oldRange).toEqual new Range([2, 0], [5, buffer.getLine(7).length])
|
||||
expect(event.newRange).toEqual new Range([2, 0], [7, buffer.getLine(7).length])
|
||||
expect(event.oldRange).toEqual new Range([2, 0], [5, buffer.lineForRow(7).length])
|
||||
expect(event.newRange).toEqual new Range([2, 0], [7, buffer.lineForRow(7).length])
|
||||
|
||||
@@ -24,24 +24,24 @@ describe "Selection", ->
|
||||
it "deletes nothing", ->
|
||||
selection.setBufferRange new Range([0,3], [0,3])
|
||||
selection.delete()
|
||||
expect(editor.buffer.getLine(0)).toBe "var quicksort = function () {"
|
||||
expect(editor.buffer.lineForRow(0)).toBe "var quicksort = function () {"
|
||||
|
||||
describe "when one line is selected", ->
|
||||
it "deletes selected text", ->
|
||||
selection.setBufferRange new Range([0,4], [0,14])
|
||||
selection.delete()
|
||||
expect(editor.buffer.getLine(0)).toBe "var = function () {"
|
||||
expect(editor.buffer.lineForRow(0)).toBe "var = function () {"
|
||||
|
||||
endOfLine = editor.buffer.getLine(0).length
|
||||
endOfLine = editor.buffer.lineForRow(0).length
|
||||
selection.setBufferRange new Range([0,0], [0, endOfLine])
|
||||
selection.delete()
|
||||
expect(editor.buffer.getLine(0)).toBe ""
|
||||
expect(editor.buffer.lineForRow(0)).toBe ""
|
||||
|
||||
describe "when multiple lines are selected", ->
|
||||
it "deletes selected text", ->
|
||||
selection.setBufferRange new Range([0,1], [2,39])
|
||||
selection.delete()
|
||||
expect(editor.buffer.getLine(0)).toBe "v;"
|
||||
expect(editor.buffer.lineForRow(0)).toBe "v;"
|
||||
|
||||
describe ".updateAppearence()", ->
|
||||
[charWidth, lineHeight] = []
|
||||
@@ -127,13 +127,13 @@ describe "Selection", ->
|
||||
selection.setBufferRange new Range([0,4], [0,13])
|
||||
selection.cut()
|
||||
expect($native.readFromPasteboard()).toBe 'quicksort'
|
||||
expect(editor.buffer.getLine(0)).toBe "var = function () {"
|
||||
expect(editor.buffer.lineForRow(0)).toBe "var = function () {"
|
||||
expect(selection.isEmpty()).toBeTruthy()
|
||||
|
||||
selection.setBufferRange new Range([1,6], [3,8])
|
||||
selection.cut()
|
||||
expect($native.readFromPasteboard()).toBe "sort = function(items) {\n if (items.length <= 1) return items;\n var "
|
||||
expect(editor.buffer.getLine(1)).toBe " var pivot = items.shift(), current, left = [], right = [];"
|
||||
expect(editor.buffer.lineForRow(1)).toBe " var pivot = items.shift(), current, left = [], right = [];"
|
||||
|
||||
it "places nothing on the clipboard when there is no selection", ->
|
||||
selection.setBufferRange new Range([0,4], [0,4])
|
||||
|
||||
@@ -14,17 +14,17 @@ describe "UndoManager", ->
|
||||
buffer.change(new Range([0, 5], [0, 9]), '')
|
||||
buffer.insert([0, 6], 'h')
|
||||
buffer.insert([0, 10], 'y')
|
||||
expect(buffer.getLine(0)).toContain 'qshorty'
|
||||
expect(buffer.lineForRow(0)).toContain 'qshorty'
|
||||
|
||||
undoManager.undo()
|
||||
expect(buffer.getLine(0)).toContain 'qshort'
|
||||
expect(buffer.getLine(0)).not.toContain 'qshorty'
|
||||
expect(buffer.lineForRow(0)).toContain 'qshort'
|
||||
expect(buffer.lineForRow(0)).not.toContain 'qshorty'
|
||||
|
||||
undoManager.undo()
|
||||
expect(buffer.getLine(0)).toContain 'qsort'
|
||||
expect(buffer.lineForRow(0)).toContain 'qsort'
|
||||
|
||||
undoManager.undo()
|
||||
expect(buffer.getLine(0)).toContain 'quicksort'
|
||||
expect(buffer.lineForRow(0)).toContain 'quicksort'
|
||||
|
||||
it "does not throw an exception when there is nothing to undo", ->
|
||||
undoManager.undo()
|
||||
@@ -36,17 +36,17 @@ describe "UndoManager", ->
|
||||
buffer.insert([0, 10], 'y')
|
||||
undoManager.undo()
|
||||
undoManager.undo()
|
||||
expect(buffer.getLine(0)).toContain 'qsort'
|
||||
expect(buffer.lineForRow(0)).toContain 'qsort'
|
||||
|
||||
it "redoes the last undone change", ->
|
||||
undoManager.redo()
|
||||
expect(buffer.getLine(0)).toContain 'qshort'
|
||||
expect(buffer.lineForRow(0)).toContain 'qshort'
|
||||
|
||||
undoManager.redo()
|
||||
expect(buffer.getLine(0)).toContain 'qshorty'
|
||||
expect(buffer.lineForRow(0)).toContain 'qshorty'
|
||||
|
||||
undoManager.undo()
|
||||
expect(buffer.getLine(0)).toContain 'qshort'
|
||||
expect(buffer.lineForRow(0)).toContain 'qshort'
|
||||
|
||||
it "does not throw an exception when there is nothing to redo", ->
|
||||
undoManager.redo()
|
||||
|
||||
@@ -27,4 +27,4 @@ class App
|
||||
|
||||
windowClosed: (window) ->
|
||||
index = @windows.indexOf(window)
|
||||
@windows.splice(index, 1) if index >= 0
|
||||
@windows.splice(index, 1) if index >= 0
|
||||
|
||||
@@ -39,7 +39,7 @@ class Buffer
|
||||
getLines: ->
|
||||
@lines
|
||||
|
||||
getLine: (row) ->
|
||||
lineForRow: (row) ->
|
||||
@lines[row]
|
||||
|
||||
getLineLength: (row) ->
|
||||
@@ -52,7 +52,7 @@ class Buffer
|
||||
@getLines().length - 1
|
||||
|
||||
lastLine: ->
|
||||
@getLine(@lastRow())
|
||||
@lineForRow(@lastRow())
|
||||
|
||||
deleteRow: (row) ->
|
||||
range = null
|
||||
@@ -67,6 +67,7 @@ class Buffer
|
||||
@change(new Range(point, point), text)
|
||||
|
||||
change: (oldRange, newText) ->
|
||||
oldRange = Range.fromObject(oldRange)
|
||||
newRange = new Range(_.clone(oldRange.start), _.clone(oldRange.start))
|
||||
prefix = @lines[oldRange.start.row][0...oldRange.start.column]
|
||||
suffix = @lines[oldRange.end.row][oldRange.end.column..]
|
||||
|
||||
@@ -65,7 +65,7 @@ class Cursor extends View
|
||||
|
||||
moveToLineEnd: ->
|
||||
{ row } = @getScreenPosition()
|
||||
@setScreenPosition({ row, column: @editor.buffer.getLine(row).length })
|
||||
@setScreenPosition({ row, column: @editor.buffer.lineForRow(row).length })
|
||||
|
||||
moveToLineStart: ->
|
||||
{ row } = @getScreenPosition()
|
||||
@@ -92,7 +92,7 @@ class Cursor extends View
|
||||
offset = 0
|
||||
|
||||
matchBackwards = =>
|
||||
line = @editor.buffer.getLine(row)
|
||||
line = @editor.buffer.lineForRow(row)
|
||||
reversedLine = line[0...column].split('').reverse().join('')
|
||||
regex.exec reversedLine
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ class Editor extends View
|
||||
getCursor: -> @cursor
|
||||
getSelection: -> @selection
|
||||
|
||||
getCurrentLine: -> @buffer.getLine(@getCursorRow())
|
||||
getCurrentLine: -> @buffer.lineForRow(@getCursorRow())
|
||||
getSelectedText: -> @selection.getText()
|
||||
moveCursorUp: -> @cursor.moveUp()
|
||||
moveCursorDown: -> @cursor.moveDown()
|
||||
|
||||
@@ -42,7 +42,7 @@ class Highlighter
|
||||
if nextRow > newRange.end.row
|
||||
oldRange.end.row += (nextRow - newRange.end.row)
|
||||
newRange.end.row = nextRow
|
||||
endColumn = @buffer.getLine(nextRow).length
|
||||
endColumn = @buffer.lineForRow(nextRow).length
|
||||
newRange.end.column = endColumn
|
||||
oldRange.end.column = endColumn
|
||||
|
||||
@@ -56,13 +56,16 @@ class Highlighter
|
||||
screenLine
|
||||
|
||||
buildLineForScreenRow: (state, row) ->
|
||||
line = @buffer.getLine(row)
|
||||
line = @buffer.lineForRow(row)
|
||||
{tokens, state} = @tokenizer.getLineTokens(line, state)
|
||||
new ScreenLineFragment(tokens, line, [1, 0], [1, 0], { state })
|
||||
|
||||
lineForScreenRow: (row) ->
|
||||
@screenLines[row]
|
||||
|
||||
lineForRow: (row) ->
|
||||
@lineForScreenRow(row)
|
||||
|
||||
linesForScreenRows: (startRow, endRow) ->
|
||||
@screenLines[startRow..endRow]
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ class Selection extends View
|
||||
|
||||
{ row, column } = @cursor.getBufferPosition()
|
||||
|
||||
line = @editor.buffer.getLine(row)
|
||||
line = @editor.buffer.lineForRow(row)
|
||||
leftSide = line[0...column].split('').reverse().join('') # reverse left side
|
||||
rightSide = line[column..]
|
||||
|
||||
@@ -120,7 +120,7 @@ class Selection extends View
|
||||
@setBufferRange range
|
||||
|
||||
selectLine: (row=@cursor.getBufferPosition().row) ->
|
||||
rowLength = @editor.buffer.getLine(row).length
|
||||
rowLength = @editor.buffer.lineForRow(row).length
|
||||
@setBufferRange new Range([row, 0], [row, rowLength])
|
||||
|
||||
selectRight: ->
|
||||
|
||||
@@ -47,7 +47,7 @@ class MoveToNextWord extends Motion
|
||||
nextWordPosition: ->
|
||||
regex = getWordRegex()
|
||||
{ row, column } = @editor.getCursorScreenPosition()
|
||||
rightOfCursor = @editor.buffer.getLine(row).substring(column)
|
||||
rightOfCursor = @editor.buffer.lineForRow(row).substring(column)
|
||||
|
||||
match = regex.exec(rightOfCursor)
|
||||
# If we're on top of part of a word, match the next one.
|
||||
@@ -56,9 +56,9 @@ class MoveToNextWord extends Motion
|
||||
if match
|
||||
column += match.index
|
||||
else if row + 1 == @editor.buffer.numLines()
|
||||
column = @editor.buffer.getLine(row).length
|
||||
column = @editor.buffer.lineForRow(row).length
|
||||
else
|
||||
nextLineMatch = regex.exec(@editor.buffer.getLine(++row))
|
||||
nextLineMatch = regex.exec(@editor.buffer.lineForRow(++row))
|
||||
column = nextLineMatch?.index or 0
|
||||
{ row, column }
|
||||
|
||||
@@ -76,7 +76,7 @@ class MoveToNextParagraph extends Motion
|
||||
|
||||
startRow = @editor.getCursorRow() + 1
|
||||
for r in [startRow..@editor.buffer.lastRow()]
|
||||
if @editor.buffer.getLine(r).length == 0
|
||||
if @editor.buffer.lineForRow(r).length == 0
|
||||
row = r
|
||||
break
|
||||
|
||||
|
||||
@@ -10,4 +10,4 @@ $.fn.scrollRight = (newValue) ->
|
||||
if newValue?
|
||||
@scrollLeft(newValue - @width())
|
||||
else
|
||||
@scrollLeft() + @width()
|
||||
@scrollLeft() + @width()
|
||||
|
||||
Reference in New Issue
Block a user