lineForBufferRow -> lineTextForBufferRow

This commit is contained in:
Ben Ogle
2014-09-03 13:51:57 -07:00
parent e3a0339fe3
commit c0c941b8db
5 changed files with 119 additions and 121 deletions

View File

@@ -1783,28 +1783,28 @@ describe "EditorComponent", ->
it "inserts the newest character in the input's value into the buffer", ->
componentNode.dispatchEvent(buildTextInputEvent(data: 'x', target: inputNode))
nextAnimationFrame()
expect(editor.lineForBufferRow(0)).toBe 'xvar quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'xvar quicksort = function () {'
componentNode.dispatchEvent(buildTextInputEvent(data: 'y', target: inputNode))
nextAnimationFrame()
expect(editor.lineForBufferRow(0)).toBe 'xyvar quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'xyvar quicksort = function () {'
it "replaces the last character if the length of the input's value doesn't increase, as occurs with the accented character menu", ->
componentNode.dispatchEvent(buildTextInputEvent(data: 'u', target: inputNode))
nextAnimationFrame()
expect(editor.lineForBufferRow(0)).toBe 'uvar quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'uvar quicksort = function () {'
# simulate the accented character suggestion's selection of the previous character
inputNode.setSelectionRange(0, 1)
componentNode.dispatchEvent(buildTextInputEvent(data: 'ü', target: inputNode))
nextAnimationFrame()
expect(editor.lineForBufferRow(0)).toBe 'üvar quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'üvar quicksort = function () {'
it "does not handle input events when input is disabled", ->
component.setInputEnabled(false)
componentNode.dispatchEvent(buildTextInputEvent(data: 'x', target: inputNode))
expect(nextAnimationFrame).toBe noAnimationFrame
expect(editor.lineForBufferRow(0)).toBe 'var quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'var quicksort = function () {'
describe "when IME composition is used to insert international characters", ->
inputNode = null
@@ -1822,46 +1822,46 @@ describe "EditorComponent", ->
it "inserts the chosen completion", ->
componentNode.dispatchEvent(buildIMECompositionEvent('compositionstart', target: inputNode))
componentNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: 's', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe 'svar quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'svar quicksort = function () {'
componentNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: 'sd', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe 'sdvar quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'sdvar quicksort = function () {'
componentNode.dispatchEvent(buildIMECompositionEvent('compositionend', target: inputNode))
componentNode.dispatchEvent(buildTextInputEvent(data: '速度', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe '速度var quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe '速度var quicksort = function () {'
it "reverts back to the original text when the completion helper is dismissed", ->
componentNode.dispatchEvent(buildIMECompositionEvent('compositionstart', target: inputNode))
componentNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: 's', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe 'svar quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'svar quicksort = function () {'
componentNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: 'sd', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe 'sdvar quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'sdvar quicksort = function () {'
componentNode.dispatchEvent(buildIMECompositionEvent('compositionend', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe 'var quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'var quicksort = function () {'
it "allows multiple accented character to be inserted with the ' on a US international layout", ->
inputNode.value = "'"
inputNode.setSelectionRange(0, 1)
componentNode.dispatchEvent(buildIMECompositionEvent('compositionstart', target: inputNode))
componentNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: "'", target: inputNode))
expect(editor.lineForBufferRow(0)).toBe "'var quicksort = function () {"
expect(editor.lineTextForBufferRow(0)).toBe "'var quicksort = function () {"
componentNode.dispatchEvent(buildIMECompositionEvent('compositionend', target: inputNode))
componentNode.dispatchEvent(buildTextInputEvent(data: 'á', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe "ávar quicksort = function () {"
expect(editor.lineTextForBufferRow(0)).toBe "ávar quicksort = function () {"
inputNode.value = "'"
inputNode.setSelectionRange(0, 1)
componentNode.dispatchEvent(buildIMECompositionEvent('compositionstart', target: inputNode))
componentNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: "'", target: inputNode))
expect(editor.lineForBufferRow(0)).toBe "á'var quicksort = function () {"
expect(editor.lineTextForBufferRow(0)).toBe "á'var quicksort = function () {"
componentNode.dispatchEvent(buildIMECompositionEvent('compositionend', target: inputNode))
componentNode.dispatchEvent(buildTextInputEvent(data: 'á', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe "áávar quicksort = function () {"
expect(editor.lineTextForBufferRow(0)).toBe "áávar quicksort = function () {"
describe "when a string is selected", ->
beforeEach ->
@@ -1870,25 +1870,25 @@ describe "EditorComponent", ->
it "inserts the chosen completion", ->
componentNode.dispatchEvent(buildIMECompositionEvent('compositionstart', target: inputNode))
componentNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: 's', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe 'var ssort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'var ssort = function () {'
componentNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: 'sd', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe 'var sdsort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'var sdsort = function () {'
componentNode.dispatchEvent(buildIMECompositionEvent('compositionend', target: inputNode))
componentNode.dispatchEvent(buildTextInputEvent(data: '速度', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe 'var 速度sort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'var 速度sort = function () {'
it "reverts back to the original text when the completion helper is dismissed", ->
componentNode.dispatchEvent(buildIMECompositionEvent('compositionstart', target: inputNode))
componentNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: 's', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe 'var ssort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'var ssort = function () {'
componentNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: 'sd', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe 'var sdsort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'var sdsort = function () {'
componentNode.dispatchEvent(buildIMECompositionEvent('compositionend', target: inputNode))
expect(editor.lineForBufferRow(0)).toBe 'var quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe 'var quicksort = function () {'
describe "commands", ->
describe "editor:consolidate-selections", ->

View File

@@ -1631,7 +1631,7 @@ describe "Editor", ->
expect(selection1.isEmpty()).toBeTruthy()
expect(selection2.isEmpty()).toBeTruthy()
expect(editor.lineForBufferRow(0)).toBe "var x = functix () {"
expect(editor.lineTextForBufferRow(0)).toBe "var x = functix () {"
describe "when the selections are on different lines", ->
it "replaces each selection with the given text, clears the selections, and places the cursor at the end of each selection's inserted text", ->
@@ -1738,10 +1738,10 @@ describe "Editor", ->
editor.insertNewline()
expect(editor.lineForBufferRow(3)).toBe " var pivot"
expect(editor.lineForBufferRow(4)).toBe " = items.shift(), current"
expect(editor.lineForBufferRow(5)).toBe ", left = [], right = [];"
expect(editor.lineForBufferRow(6)).toBe " while(items.length > 0) {"
expect(editor.lineTextForBufferRow(3)).toBe " var pivot"
expect(editor.lineTextForBufferRow(4)).toBe " = items.shift(), current"
expect(editor.lineTextForBufferRow(5)).toBe ", left = [], right = [];"
expect(editor.lineTextForBufferRow(6)).toBe " while(items.length > 0) {"
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [4, 0]
@@ -1753,13 +1753,13 @@ describe "Editor", ->
editor.addCursorAtScreenPosition([6, 0])
editor.insertText("\n")
expect(editor.lineForBufferRow(3)).toBe ""
expect(editor.lineForBufferRow(4)).toBe " var pivot = items.shift(), current, left = [], right = [];"
expect(editor.lineForBufferRow(5)).toBe " while(items.length > 0) {"
expect(editor.lineForBufferRow(6)).toBe " current = items.shift();"
expect(editor.lineForBufferRow(7)).toBe ""
expect(editor.lineForBufferRow(8)).toBe " current < pivot ? left.push(current) : right.push(current);"
expect(editor.lineForBufferRow(9)).toBe " }"
expect(editor.lineTextForBufferRow(3)).toBe ""
expect(editor.lineTextForBufferRow(4)).toBe " var pivot = items.shift(), current, left = [], right = [];"
expect(editor.lineTextForBufferRow(5)).toBe " while(items.length > 0) {"
expect(editor.lineTextForBufferRow(6)).toBe " current = items.shift();"
expect(editor.lineTextForBufferRow(7)).toBe ""
expect(editor.lineTextForBufferRow(8)).toBe " current < pivot ? left.push(current) : right.push(current);"
expect(editor.lineTextForBufferRow(9)).toBe " }"
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [4,0]
@@ -1787,8 +1787,8 @@ describe "Editor", ->
editor.setCursorBufferPosition([0])
editor.insertNewlineAbove()
expect(editor.getCursorBufferPosition()).toEqual [0,0]
expect(editor.lineForBufferRow(0)).toBe ''
expect(editor.lineForBufferRow(1)).toBe 'var quicksort = function () {'
expect(editor.lineTextForBufferRow(0)).toBe ''
expect(editor.lineTextForBufferRow(1)).toBe 'var quicksort = function () {'
expect(editor.buffer.getLineCount()).toBe 14
describe "when the cursor is not on the first line", ->
@@ -1796,8 +1796,8 @@ describe "Editor", ->
editor.setCursorBufferPosition([3,4])
editor.insertNewlineAbove()
expect(editor.getCursorBufferPosition()).toEqual [3,0]
expect(editor.lineForBufferRow(3)).toBe ''
expect(editor.lineForBufferRow(4)).toBe ' var pivot = items.shift(), current, left = [], right = [];'
expect(editor.lineTextForBufferRow(3)).toBe ''
expect(editor.lineTextForBufferRow(4)).toBe ' var pivot = items.shift(), current, left = [], right = [];'
expect(editor.buffer.getLineCount()).toBe 14
editor.undo()
@@ -1811,33 +1811,33 @@ describe "Editor", ->
editor.insertNewlineAbove()
expect(editor.getCursorBufferPosition()).toEqual [0,2]
expect(editor.lineForBufferRow(0)).toBe ' '
expect(editor.lineForBufferRow(1)).toBe ' var test'
expect(editor.lineTextForBufferRow(0)).toBe ' '
expect(editor.lineTextForBufferRow(1)).toBe ' var test'
editor.setText('\n var test')
editor.setCursorBufferPosition([1,2])
editor.insertNewlineAbove()
expect(editor.getCursorBufferPosition()).toEqual [1,2]
expect(editor.lineForBufferRow(0)).toBe ''
expect(editor.lineForBufferRow(1)).toBe ' '
expect(editor.lineForBufferRow(2)).toBe ' var test'
expect(editor.lineTextForBufferRow(0)).toBe ''
expect(editor.lineTextForBufferRow(1)).toBe ' '
expect(editor.lineTextForBufferRow(2)).toBe ' var test'
editor.setText('function() {\n}')
editor.setCursorBufferPosition([1,1])
editor.insertNewlineAbove()
expect(editor.getCursorBufferPosition()).toEqual [1,2]
expect(editor.lineForBufferRow(0)).toBe 'function() {'
expect(editor.lineForBufferRow(1)).toBe ' '
expect(editor.lineForBufferRow(2)).toBe '}'
expect(editor.lineTextForBufferRow(0)).toBe 'function() {'
expect(editor.lineTextForBufferRow(1)).toBe ' '
expect(editor.lineTextForBufferRow(2)).toBe '}'
describe "when a new line is appended before a closing tag (e.g. by pressing enter before a selection)", ->
it "moves the line down and keeps the indentation level the same when editor.autoIndent is true", ->
atom.config.set('editor.autoIndent', true)
editor.setCursorBufferPosition([9,2])
editor.insertNewline()
expect(editor.lineForBufferRow(10)).toBe ' };'
expect(editor.lineTextForBufferRow(10)).toBe ' };'
describe ".backspace()", ->
describe "when there is a single cursor", ->
@@ -1921,7 +1921,7 @@ describe "Editor", ->
editor.backspace()
expect(editor.lineForBufferRow(3)).toBe " var pivo = items.shift(), curren, left = [], right = [];"
expect(editor.lineTextForBufferRow(3)).toBe " var pivo = items.shift(), curren, left = [], right = [];"
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [3, 12]
@@ -1939,8 +1939,8 @@ describe "Editor", ->
editor.backspace()
expect(editor.lineForBufferRow(3)).toBe " var pivo = items.shift(), current, left = [], right = [];"
expect(editor.lineForBufferRow(4)).toBe " whileitems.length > 0) {"
expect(editor.lineTextForBufferRow(3)).toBe " var pivo = items.shift(), current, left = [], right = [];"
expect(editor.lineTextForBufferRow(4)).toBe " whileitems.length > 0) {"
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [3, 12]
@@ -1956,10 +1956,10 @@ describe "Editor", ->
editor.addCursorAtScreenPosition([6, 0])
editor.backspace()
expect(editor.lineForBufferRow(2)).toBe " if (items.length <= 1) return items; var pivot = items.shift(), current, left = [], right = [];"
expect(editor.lineForBufferRow(3)).toBe " while(items.length > 0) {"
expect(editor.lineForBufferRow(4)).toBe " current = items.shift(); current < pivot ? left.push(current) : right.push(current);"
expect(editor.lineForBufferRow(5)).toBe " }"
expect(editor.lineTextForBufferRow(2)).toBe " if (items.length <= 1) return items; var pivot = items.shift(), current, left = [], right = [];"
expect(editor.lineTextForBufferRow(3)).toBe " while(items.length > 0) {"
expect(editor.lineTextForBufferRow(4)).toBe " current = items.shift(); current < pivot ? left.push(current) : right.push(current);"
expect(editor.lineTextForBufferRow(5)).toBe " }"
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [2,40]
@@ -1984,7 +1984,7 @@ describe "Editor", ->
it "removes all selected text", ->
editor.setSelectedBufferRanges([[[0,4], [0,13]], [[0,16], [0,24]]])
editor.backspace()
expect(editor.lineForBufferRow(0)).toBe 'var = () {'
expect(editor.lineTextForBufferRow(0)).toBe 'var = () {'
describe ".deleteToBeginningOfWord()", ->
describe "when no text is selected", ->
@@ -2139,7 +2139,7 @@ describe "Editor", ->
editor.delete()
expect(editor.lineForBufferRow(3)).toBe " var pivot= items.shift(), current left = [], right = [];"
expect(editor.lineTextForBufferRow(3)).toBe " var pivot= items.shift(), current left = [], right = [];"
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [3, 13]
@@ -2157,8 +2157,8 @@ describe "Editor", ->
editor.delete()
expect(editor.lineForBufferRow(3)).toBe " var pivot= items.shift(), current, left = [], right = [];"
expect(editor.lineForBufferRow(4)).toBe " while(tems.length > 0) {"
expect(editor.lineTextForBufferRow(3)).toBe " var pivot= items.shift(), current, left = [], right = [];"
expect(editor.lineTextForBufferRow(4)).toBe " while(tems.length > 0) {"
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [3, 13]
@@ -2175,7 +2175,7 @@ describe "Editor", ->
editor.delete()
expect(editor.lineForBufferRow(0)).toBe "var quicksort = function () { var sort = function(items) { if (items.length <= 1) return items;"
expect(editor.lineTextForBufferRow(0)).toBe "var quicksort = function () { var sort = function(items) { if (items.length <= 1) return items;"
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [0,29]
@@ -2194,7 +2194,7 @@ describe "Editor", ->
it "removes all selected text", ->
editor.setSelectedBufferRanges([[[0,4], [0,13]], [[0,16], [0,24]]])
editor.delete()
expect(editor.lineForBufferRow(0)).toBe 'var = () {'
expect(editor.lineTextForBufferRow(0)).toBe 'var = () {'
describe ".deleteToEndOfWord()", ->
describe "when no text is selected", ->
@@ -2389,27 +2389,27 @@ describe "Editor", ->
it "pastes text into the buffer", ->
atom.clipboard.write('first')
editor.pasteText()
expect(editor.lineForBufferRow(0)).toBe "var first = function () {"
expect(editor.lineForBufferRow(1)).toBe " var first = function(items) {"
expect(editor.lineTextForBufferRow(0)).toBe "var first = function () {"
expect(editor.lineTextForBufferRow(1)).toBe " var first = function(items) {"
describe 'when the clipboard has many selections', ->
it "pastes each selection separately into the buffer", ->
atom.clipboard.write('first\nsecond', {selections: ['first', 'second'] })
editor.pasteText()
expect(editor.lineForBufferRow(0)).toBe "var first = function () {"
expect(editor.lineForBufferRow(1)).toBe " var second = function(items) {"
expect(editor.lineTextForBufferRow(0)).toBe "var first = function () {"
expect(editor.lineTextForBufferRow(1)).toBe " var second = function(items) {"
describe 'and the selections count does not match', ->
it "pastes the whole text into the buffer", ->
atom.clipboard.write('first\nsecond\nthird', {selections: ['first', 'second', 'third'] })
editor.pasteText()
expect(editor.lineForBufferRow(0)).toBe "var first"
expect(editor.lineForBufferRow(1)).toBe "second"
expect(editor.lineForBufferRow(2)).toBe "third = function () {"
expect(editor.lineTextForBufferRow(0)).toBe "var first"
expect(editor.lineTextForBufferRow(1)).toBe "second"
expect(editor.lineTextForBufferRow(2)).toBe "third = function () {"
expect(editor.lineForBufferRow(3)).toBe " var first"
expect(editor.lineForBufferRow(4)).toBe "second"
expect(editor.lineForBufferRow(5)).toBe "third = function(items) {"
expect(editor.lineTextForBufferRow(3)).toBe " var first"
expect(editor.lineTextForBufferRow(4)).toBe "second"
expect(editor.lineTextForBufferRow(5)).toBe "third = function(items) {"
describe ".indentSelectedRows()", ->
describe "when nothing is selected", ->
@@ -2889,13 +2889,13 @@ describe "Editor", ->
editor.buffer.setText("abc")
editor.setCursorScreenPosition([0, 1])
editor.transpose()
expect(editor.lineForBufferRow(0)).toBe 'bac'
expect(editor.lineTextForBufferRow(0)).toBe 'bac'
it "reverses a selection", ->
editor.buffer.setText("xabcz")
editor.setSelectedBufferRange([[0, 1], [0, 4]])
editor.transpose()
expect(editor.lineForBufferRow(0)).toBe 'xcbaz'
expect(editor.lineTextForBufferRow(0)).toBe 'xcbaz'
describe ".upperCase()", ->
describe "when there is no selection", ->
@@ -2903,7 +2903,7 @@ describe "Editor", ->
editor.buffer.setText("aBc")
editor.setCursorScreenPosition([0, 1])
editor.upperCase()
expect(editor.lineForBufferRow(0)).toBe 'ABC'
expect(editor.lineTextForBufferRow(0)).toBe 'ABC'
expect(editor.getSelectedBufferRange()).toEqual [[0, 1], [0, 1]]
describe "when there is a selection", ->
@@ -2911,7 +2911,7 @@ describe "Editor", ->
editor.buffer.setText("abc")
editor.setSelectedBufferRange([[0,0], [0,2]])
editor.upperCase()
expect(editor.lineForBufferRow(0)).toBe 'ABc'
expect(editor.lineTextForBufferRow(0)).toBe 'ABc'
expect(editor.getSelectedBufferRange()).toEqual [[0, 0], [0, 2]]
describe ".lowerCase()", ->
@@ -2920,7 +2920,7 @@ describe "Editor", ->
editor.buffer.setText("aBC")
editor.setCursorScreenPosition([0, 1])
editor.lowerCase()
expect(editor.lineForBufferRow(0)).toBe 'abc'
expect(editor.lineTextForBufferRow(0)).toBe 'abc'
expect(editor.getSelectedBufferRange()).toEqual [[0, 1], [0, 1]]
describe "when there is a selection", ->
@@ -2928,7 +2928,7 @@ describe "Editor", ->
editor.buffer.setText("ABC")
editor.setSelectedBufferRange([[0,0], [0,2]])
editor.lowerCase()
expect(editor.lineForBufferRow(0)).toBe 'abC'
expect(editor.lineTextForBufferRow(0)).toBe 'abC'
expect(editor.getSelectedBufferRange()).toEqual [[0, 0], [0, 2]]
describe "soft-tabs detection", ->
@@ -3003,11 +3003,11 @@ describe "Editor", ->
it "does not auto-indent the line", ->
editor.setCursorBufferPosition([1, 30])
editor.insertText("\n ")
expect(editor.lineForBufferRow(2)).toBe " "
expect(editor.lineTextForBufferRow(2)).toBe " "
atom.config.set("editor.autoIndent", false)
editor.indent()
expect(editor.lineForBufferRow(2)).toBe " "
expect(editor.lineTextForBufferRow(2)).toBe " "
describe "when editor.autoIndent is true", ->
beforeEach ->
@@ -3017,11 +3017,11 @@ describe "Editor", ->
it "auto-indents the line", ->
editor.setCursorBufferPosition([1, 30])
editor.insertText("\n ")
expect(editor.lineForBufferRow(2)).toBe " "
expect(editor.lineTextForBufferRow(2)).toBe " "
atom.config.set("editor.autoIndent", true)
editor.indent()
expect(editor.lineForBufferRow(2)).toBe " "
expect(editor.lineTextForBufferRow(2)).toBe " "
describe "when a newline is added", ->
describe "when the line preceding the newline adds a new level of indentation", ->
@@ -3085,15 +3085,15 @@ describe "Editor", ->
it "doesn't break when decreasing the indentation on a row that has no indentation", ->
editor.setCursorBufferPosition([12, Infinity])
editor.insertText("\n}; # too many closing brackets!")
expect(editor.lineForBufferRow(13)).toBe "}; # too many closing brackets!"
expect(editor.lineTextForBufferRow(13)).toBe "}; # too many closing brackets!"
describe "when inserted text does not match a decrease indent pattern", ->
it "does not decrease the indentation", ->
editor.setCursorBufferPosition([12, 0])
editor.insertText(' ')
expect(editor.lineForBufferRow(12)).toBe ' };'
expect(editor.lineTextForBufferRow(12)).toBe ' };'
editor.insertText('\t\t')
expect(editor.lineForBufferRow(12)).toBe ' \t\t};'
expect(editor.lineTextForBufferRow(12)).toBe ' \t\t};'
describe "when the current line does not match a decrease indent pattern", ->
it "leaves the line unchanged", ->
@@ -3111,22 +3111,22 @@ describe "Editor", ->
atom.config.set('editor.normalizeIndentOnPaste', false)
editor.setCursorBufferPosition([5, 2])
editor.pasteText()
expect(editor.lineForBufferRow(5)).toBe " function() {"
expect(editor.lineForBufferRow(6)).toBe "var cool = 1;"
expect(editor.lineForBufferRow(7)).toBe " }"
expect(editor.lineTextForBufferRow(5)).toBe " function() {"
expect(editor.lineTextForBufferRow(6)).toBe "var cool = 1;"
expect(editor.lineTextForBufferRow(7)).toBe " }"
describe "when the inserted text contains no newlines", ->
it "does not adjust the indentation level of the text", ->
editor.setCursorBufferPosition([5, 2])
editor.insertText("foo", indentBasis: 5)
expect(editor.lineForBufferRow(5)).toBe " foo current = items.shift();"
expect(editor.lineTextForBufferRow(5)).toBe " foo current = items.shift();"
it "does not adjust the whitespace if there are preceding characters", ->
copyText(" foo")
editor.setCursorBufferPosition([5, 30])
editor.pasteText()
expect(editor.lineForBufferRow(5)).toBe " current = items.shift(); foo"
expect(editor.lineTextForBufferRow(5)).toBe " current = items.shift(); foo"
describe "when the inserted text contains newlines", ->
describe "when the cursor is preceded only by whitespace characters", ->
@@ -3135,10 +3135,10 @@ describe "Editor", ->
editor.setCursorBufferPosition([3, 4])
editor.pasteText()
expect(editor.lineForBufferRow(3)).toBe " while (true) {"
expect(editor.lineForBufferRow(4)).toBe " foo();"
expect(editor.lineForBufferRow(5)).toBe " }"
expect(editor.lineForBufferRow(6)).toBe "var pivot = items.shift(), current, left = [], right = [];"
expect(editor.lineTextForBufferRow(3)).toBe " while (true) {"
expect(editor.lineTextForBufferRow(4)).toBe " foo();"
expect(editor.lineTextForBufferRow(5)).toBe " }"
expect(editor.lineTextForBufferRow(6)).toBe "var pivot = items.shift(), current, left = [], right = [];"
describe "when the cursor is preceded by non-whitespace characters", ->
it "normalizes the indentation level of all lines based on the level of the existing first line", ->
@@ -3146,10 +3146,10 @@ describe "Editor", ->
editor.setCursorBufferPosition([1, Infinity])
editor.pasteText()
expect(editor.lineForBufferRow(1)).toBe " var sort = function(items) {while (true) {"
expect(editor.lineForBufferRow(2)).toBe " foo();"
expect(editor.lineForBufferRow(3)).toBe " }"
expect(editor.lineForBufferRow(4)).toBe ""
expect(editor.lineTextForBufferRow(1)).toBe " var sort = function(items) {while (true) {"
expect(editor.lineTextForBufferRow(2)).toBe " foo();"
expect(editor.lineTextForBufferRow(3)).toBe " }"
expect(editor.lineTextForBufferRow(4)).toBe ""
it "autoIndentSelectedRows auto-indents the selection", ->
editor.setCursorBufferPosition([2, 0])
@@ -3157,10 +3157,10 @@ describe "Editor", ->
editor.getLastSelection().setBufferRange([[2,0], [6,0]])
editor.autoIndentSelectedRows()
expect(editor.lineForBufferRow(2)).toBe " function() {"
expect(editor.lineForBufferRow(3)).toBe " inside=true"
expect(editor.lineForBufferRow(4)).toBe " }"
expect(editor.lineForBufferRow(5)).toBe " i=1"
expect(editor.lineTextForBufferRow(2)).toBe " function() {"
expect(editor.lineTextForBufferRow(3)).toBe " inside=true"
expect(editor.lineTextForBufferRow(4)).toBe " }"
expect(editor.lineTextForBufferRow(5)).toBe " i=1"
describe "soft and hard tabs", ->
it "resets the tab style when tokenization is complete", ->
@@ -3185,36 +3185,36 @@ describe "Editor", ->
describe "when the line below isn't empty", ->
it "joins the line below with the current line separated by a space and moves the cursor to the start of line that was moved up", ->
editor.joinLines()
expect(editor.lineForBufferRow(0)).toBe 'var quicksort = function () { var sort = function(items) {'
expect(editor.lineTextForBufferRow(0)).toBe 'var quicksort = function () { var sort = function(items) {'
expect(editor.getCursorBufferPosition()).toEqual [0, 30]
describe "when the line below is empty", ->
it "deletes the line below and moves the cursor to the end of the line", ->
editor.setCursorBufferPosition([9])
editor.joinLines()
expect(editor.lineForBufferRow(9)).toBe ' };'
expect(editor.lineForBufferRow(10)).toBe ' return sort(Array.apply(this, arguments));'
expect(editor.lineTextForBufferRow(9)).toBe ' };'
expect(editor.lineTextForBufferRow(10)).toBe ' return sort(Array.apply(this, arguments));'
expect(editor.getCursorBufferPosition()).toEqual [9, 4]
describe "when the cursor is on the last row", ->
it "does nothing", ->
editor.setCursorBufferPosition([Infinity, Infinity])
editor.joinLines()
expect(editor.lineForBufferRow(12)).toBe '};'
expect(editor.lineTextForBufferRow(12)).toBe '};'
describe "when text is selected", ->
describe "when the selection does not span multiple lines", ->
it "joins the line below with the current line separated by a space and retains the selected text", ->
editor.setSelectedBufferRange([[0, 1], [0, 3]])
editor.joinLines()
expect(editor.lineForBufferRow(0)).toBe 'var quicksort = function () { var sort = function(items) {'
expect(editor.lineTextForBufferRow(0)).toBe 'var quicksort = function () { var sort = function(items) {'
expect(editor.getSelectedBufferRange()).toEqual [[0, 1], [0, 3]]
describe "when the selection spans multiple lines", ->
it "joins all selected lines separated by a space and retains the selected text", ->
editor.setSelectedBufferRange([[9, 3], [12, 1]])
editor.joinLines()
expect(editor.lineForBufferRow(9)).toBe ' }; return sort(Array.apply(this, arguments)); };'
expect(editor.lineTextForBufferRow(9)).toBe ' }; return sort(Array.apply(this, arguments)); };'
expect(editor.getSelectedBufferRange()).toEqual [[9, 3], [9, 49]]
describe ".duplicateLines()", ->

View File

@@ -222,7 +222,7 @@ class Cursor extends Model
# Public: Returns the cursor's current buffer row of text excluding its line
# ending.
getCurrentBufferLine: ->
@editor.lineForBufferRow(@getBufferRow())
@editor.lineTextForBufferRow(@getBufferRow())
# Public: Moves the cursor up one screen row.
moveUp: (rowCount=1, {moveToEndOfSelection}={}) ->
@@ -562,7 +562,7 @@ class Cursor extends Model
# its current position.
hasPrecedingCharactersOnLine: ->
bufferPosition = @getBufferPosition()
line = @editor.lineForBufferRow(bufferPosition.row)
line = @editor.lineTextForBufferRow(bufferPosition.row)
firstCharacterColumn = line.search(/\S/)
if firstCharacterColumn is -1

View File

@@ -412,14 +412,12 @@ class Editor extends Model
# Public: Returns a {String} representing the contents of the line at the
# given buffer row.
#
# * `row` A {Number} representing a zero-indexed buffer row.
lineTextForBufferRow: (row) -> @buffer.lineForRow(row)
lineForBufferRow: (row) ->
deprecate 'Use Editor::lineTextForBufferRow(row) instead'
@lineTextForBufferRow(row)
# * `bufferRow` A {Number} representing a zero-indexed buffer row.
lineTextForBufferRow: (bufferRow) -> @buffer.lineForRow(bufferRow)
lineForBufferRow: (bufferRow) ->
deprecate 'Use Editor::lineTextForBufferRow(bufferRow) instead'
@lineTextForBufferRow(bufferRow)
# {Delegates to: DisplayBuffer.lineForRow}
lineForScreenRow: (row) -> @displayBuffer.lineForRow(row)
# Gets the screen line for the given screen row.
#
# * `screenRow` - A {Number} indicating the screen row.
@@ -923,7 +921,7 @@ class Editor extends Model
#
# Returns a {Number}.
indentationForBufferRow: (bufferRow) ->
@indentLevelForLine(@lineForBufferRow(bufferRow))
@indentLevelForLine(@lineTextForBufferRow(bufferRow))
# Public: Set the indentation level for the given buffer row.
#
@@ -941,7 +939,7 @@ class Editor extends Model
if preserveLeadingWhitespace
endColumn = 0
else
endColumn = @lineForBufferRow(bufferRow).match(/^\s*/)[0].length
endColumn = @lineTextForBufferRow(bufferRow).match(/^\s*/)[0].length
newIndentString = @buildIndentString(newLevel)
@buffer.setTextInRange([[bufferRow, 0], [bufferRow, endColumn]], newIndentString)
@@ -1188,7 +1186,7 @@ class Editor extends Model
# Public: Determine if the given row is entirely a comment
isBufferRowCommented: (bufferRow) ->
if match = @lineForBufferRow(bufferRow).match(/\S/)
if match = @lineTextForBufferRow(bufferRow).match(/\S/)
scopes = @tokenForBufferPosition([bufferRow, match.index]).scopes
new TextMateScopeSelector('comment.*').matches(scopes)

View File

@@ -168,7 +168,7 @@ class LanguageMode
continue if @editor.isBufferRowBlank(row)
indentation = @editor.indentationForBufferRow(row)
if indentation <= startIndentLevel
includeRowInFold = indentation == startIndentLevel and @foldEndRegexForScopes(scopes)?.searchSync(@editor.lineForBufferRow(row))
includeRowInFold = indentation == startIndentLevel and @foldEndRegexForScopes(scopes)?.searchSync(@editor.lineTextForBufferRow(row))
foldEndRow = row if includeRowInFold
break
@@ -207,7 +207,7 @@ class LanguageMode
# Right now, a paragraph is a block of text bounded by and empty line or a
# block of text that is not the same type (comments next to source code).
rowRangeForParagraphAtBufferRow: (bufferRow) ->
return unless /\w/.test(@editor.lineForBufferRow(bufferRow))
return unless /\w/.test(@editor.lineTextForBufferRow(bufferRow))
if @isLineCommentedAtBufferRow(bufferRow)
isOriginalRowComment = true
@@ -220,14 +220,14 @@ class LanguageMode
startRow = bufferRow
while startRow > firstRow
break if @isLineCommentedAtBufferRow(startRow - 1) != isOriginalRowComment
break unless /\w/.test(@editor.lineForBufferRow(startRow - 1))
break unless /\w/.test(@editor.lineTextForBufferRow(startRow - 1))
startRow--
endRow = bufferRow
lastRow = @editor.getLastBufferRow()
while endRow < lastRow
break if @isLineCommentedAtBufferRow(endRow + 1) != isOriginalRowComment
break unless /\w/.test(@editor.lineForBufferRow(endRow + 1))
break unless /\w/.test(@editor.lineTextForBufferRow(endRow + 1))
endRow++
new Range([startRow, 0], [endRow, @editor.lineLengthForBufferRow(endRow)])