From fc7a13ce050c45d89a41cc15c2896a7ccc7eeab2 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 5 Mar 2012 16:06:27 -0700 Subject: [PATCH] Rename Buffer.getLine to lineForRow --- spec/atom/buffer-spec.coffee | 52 ++++++++++++------------ spec/atom/editor-spec.coffee | 62 ++++++++++++++--------------- spec/atom/highlighter-spec.coffee | 12 +++--- spec/atom/selection-spec.coffee | 14 +++---- spec/atom/undo-manager-spec.coffee | 18 ++++----- src/atom/app.coffee | 2 +- src/atom/buffer.coffee | 5 ++- src/atom/cursor.coffee | 4 +- src/atom/editor.coffee | 2 +- src/atom/highlighter.coffee | 7 +++- src/atom/selection.coffee | 4 +- src/atom/vim-mode/motions.coffee | 8 ++-- src/stdlib/jquery-extensions.coffee | 2 +- 13 files changed, 98 insertions(+), 94 deletions(-) diff --git a/spec/atom/buffer-spec.coffee b/spec/atom/buffer-spec.coffee index a8b942aa5..2d8c3b0c2 100644 --- a/spec/atom/buffer-spec.coffee +++ b/spec/atom/buffer-spec.coffee @@ -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(" diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index ece066325..fde0b4645 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -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", -> diff --git a/spec/atom/highlighter-spec.coffee b/spec/atom/highlighter-spec.coffee index 2bc783a26..dd2fc23e1 100644 --- a/spec/atom/highlighter-spec.coffee +++ b/spec/atom/highlighter-spec.coffee @@ -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]) diff --git a/spec/atom/selection-spec.coffee b/spec/atom/selection-spec.coffee index c234d7820..9d6efd9ce 100644 --- a/spec/atom/selection-spec.coffee +++ b/spec/atom/selection-spec.coffee @@ -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]) diff --git a/spec/atom/undo-manager-spec.coffee b/spec/atom/undo-manager-spec.coffee index 243ba0a1d..a1fb0f772 100644 --- a/spec/atom/undo-manager-spec.coffee +++ b/spec/atom/undo-manager-spec.coffee @@ -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() diff --git a/src/atom/app.coffee b/src/atom/app.coffee index ce79e4a83..f5e79057b 100644 --- a/src/atom/app.coffee +++ b/src/atom/app.coffee @@ -27,4 +27,4 @@ class App windowClosed: (window) -> index = @windows.indexOf(window) - @windows.splice(index, 1) if index >= 0 \ No newline at end of file + @windows.splice(index, 1) if index >= 0 diff --git a/src/atom/buffer.coffee b/src/atom/buffer.coffee index ecf6ecfa3..00cca469e 100644 --- a/src/atom/buffer.coffee +++ b/src/atom/buffer.coffee @@ -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..] diff --git a/src/atom/cursor.coffee b/src/atom/cursor.coffee index dd6902ca7..841698afb 100644 --- a/src/atom/cursor.coffee +++ b/src/atom/cursor.coffee @@ -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 diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index ec3df1e56..ccb771dc8 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -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() diff --git a/src/atom/highlighter.coffee b/src/atom/highlighter.coffee index 494d3391f..67dd3b8f1 100644 --- a/src/atom/highlighter.coffee +++ b/src/atom/highlighter.coffee @@ -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] diff --git a/src/atom/selection.coffee b/src/atom/selection.coffee index 77709be16..c8e6f51e6 100644 --- a/src/atom/selection.coffee +++ b/src/atom/selection.coffee @@ -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: -> diff --git a/src/atom/vim-mode/motions.coffee b/src/atom/vim-mode/motions.coffee index e2694c0b7..1ad4859ac 100644 --- a/src/atom/vim-mode/motions.coffee +++ b/src/atom/vim-mode/motions.coffee @@ -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 diff --git a/src/stdlib/jquery-extensions.coffee b/src/stdlib/jquery-extensions.coffee index b49a0fcd0..0441be3c7 100644 --- a/src/stdlib/jquery-extensions.coffee +++ b/src/stdlib/jquery-extensions.coffee @@ -10,4 +10,4 @@ $.fn.scrollRight = (newValue) -> if newValue? @scrollLeft(newValue - @width()) else - @scrollLeft() + @width() \ No newline at end of file + @scrollLeft() + @width()