diff --git a/spec/display-buffer-spec.coffee b/spec/display-buffer-spec.coffee index 8d9673ceb..d21b58536 100644 --- a/spec/display-buffer-spec.coffee +++ b/spec/display-buffer-spec.coffee @@ -82,7 +82,7 @@ describe "DisplayBuffer", -> describe "when there is no whitespace before the boundary", -> it "wraps the line exactly at the boundary since there's no more graceful place to wrap it", -> - buffer.change([[0, 0], [1, 0]], 'abcdefghijklmnopqrstuvwxyz\n') + buffer.setTextInRange([[0, 0], [1, 0]], 'abcdefghijklmnopqrstuvwxyz\n') displayBuffer.setEditorWidthInChars(10) expect(displayBuffer.lineForRow(0).text).toBe 'abcdefghij' expect(displayBuffer.lineForRow(1).text).toBe 'klmnopqrst' @@ -142,7 +142,7 @@ describe "DisplayBuffer", -> describe "when buffer lines are removed", -> it "removes lines and emits a change event", -> - buffer.change([[3, 21], [7, 5]], ';') + buffer.setTextInRange([[3, 21], [7, 5]], ';') expect(displayBuffer.lineForRow(3).text).toBe ' var pivot = items;' expect(displayBuffer.lineForRow(4).text).toBe ' return ' expect(displayBuffer.lineForRow(5).text).toBe 'sort(left).concat(pivot).concat(sort(right));' @@ -330,7 +330,7 @@ describe "DisplayBuffer", -> describe "when the old range surrounds a fold", -> beforeEach -> - buffer.change([[1, 0], [5, 1]], 'party!') + buffer.setTextInRange([[1, 0], [5, 1]], 'party!') it "removes the fold and replaces the selection with the new text", -> expect(displayBuffer.lineForRow(0).text).toBe "0" @@ -352,7 +352,7 @@ describe "DisplayBuffer", -> displayBuffer.createFold(2, 9) changeHandler.reset() - buffer.change([[1, 0], [10, 0]], 'goodbye') + buffer.setTextInRange([[1, 0], [10, 0]], 'goodbye') expect(displayBuffer.lineForRow(0).text).toBe "0" expect(displayBuffer.lineForRow(1).text).toBe "goodbye10" @@ -371,7 +371,7 @@ describe "DisplayBuffer", -> describe "when the old range precedes lines with a fold", -> describe "when the new range precedes lines with a fold", -> it "updates the buffer and re-positions subsequent folds", -> - buffer.change([[0, 0], [1, 1]], 'abc') + buffer.setTextInRange([[0, 0], [1, 1]], 'abc') expect(displayBuffer.lineForRow(0).text).toBe "abc" expect(displayBuffer.lineForRow(1).fold).toBe fold1 @@ -394,7 +394,7 @@ describe "DisplayBuffer", -> describe "when the old range straddles the beginning of a fold", -> it "destroys the fold", -> - buffer.change([[1, 1], [3, 0]], "a\nb\nc\nd\n") + buffer.setTextInRange([[1, 1], [3, 0]], "a\nb\nc\nd\n") expect(displayBuffer.lineForRow(1).text).toBe '1a' expect(displayBuffer.lineForRow(2).text).toBe 'b' expect(displayBuffer.lineForRow(2).fold).toBeUndefined() @@ -402,7 +402,7 @@ describe "DisplayBuffer", -> describe "when the old range follows a fold", -> it "re-positions the screen ranges for the change event based on the preceding fold", -> - buffer.change([[10, 0], [11, 0]], 'abc') + buffer.setTextInRange([[10, 0], [11, 0]], 'abc') expect(displayBuffer.lineForRow(1).text).toBe "1" expect(displayBuffer.lineForRow(2).fold).toBe fold1 @@ -430,7 +430,7 @@ describe "DisplayBuffer", -> describe "when the end of the new range exceeds the end of the fold", -> it "expands the fold to contain all the inserted lines", -> - buffer.change([[3, 0], [4, 0]], 'a\nb\nc\nd\n') + buffer.setTextInRange([[3, 0], [4, 0]], 'a\nb\nc\nd\n') expect(fold1.getStartRow()).toBe 2 expect(fold1.getEndRow()).toBe 7 @@ -447,7 +447,7 @@ describe "DisplayBuffer", -> describe "when the end of the new range precedes the end of the fold", -> it "destroys the fold", -> fold2.destroy() - buffer.change([[3, 0], [6, 0]], 'a\n') + buffer.setTextInRange([[3, 0], [6, 0]], 'a\n') expect(displayBuffer.lineForRow(2).text).toBe '2' expect(displayBuffer.lineForRow(2).fold).toBeUndefined() expect(displayBuffer.lineForRow(3).text).toBe 'a' @@ -831,7 +831,7 @@ describe "DisplayBuffer", -> expect(marker.getTailScreenPosition()).toEqual [5, 7] expect(marker2.isValid()).toBeFalsy() - buffer.change([[8, 0], [8, 2]], ".....") + buffer.setTextInRange([[8, 0], [8, 2]], ".....") expect(changeHandler).toHaveBeenCalled() expect(markerChangedHandler).toHaveBeenCalled() expect(marker2ChangedHandler).toHaveBeenCalled() diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index 615c17d68..9880e0d2c 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -1385,7 +1385,7 @@ describe "EditorView", -> expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(12) - buffer.change([[1,0], [3,0]], "1\n2\n3\n") + buffer.setTextInRange([[1,0], [3,0]], "1\n2\n3\n") expect(editorView.renderedLines.find(".line").length).toBe 7 expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(12) @@ -1398,21 +1398,21 @@ describe "EditorView", -> expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(12) - buffer.change([[2,0], [7,0]], "2\n3\n4\n5\n6\n7\n8\n9\n") + buffer.setTextInRange([[2,0], [7,0]], "2\n3\n4\n5\n6\n7\n8\n9\n") expect(editorView.renderedLines.find(".line").length).toBe 7 expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(12) describe "when the change straddles the last rendered row", -> it "doesn't render rows that were not previously rendered", -> - buffer.change([[2,0], [7,0]], "2\n3\n4\n5\n6\n7\n8\n") + buffer.setTextInRange([[2,0], [7,0]], "2\n3\n4\n5\n6\n7\n8\n") expect(editorView.renderedLines.find(".line").length).toBe 7 expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(0) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(6) describe "when the change the follows the last rendered row", -> it "does not change the rendered lines", -> - buffer.change([[12,0], [12,0]], "12\n13\n14\n") + buffer.setTextInRange([[12,0], [12,0]], "12\n13\n14\n") expect(editorView.renderedLines.find(".line").length).toBe 7 expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(0) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(6) @@ -1422,7 +1422,7 @@ describe "EditorView", -> setEditorWidthInChars(editorView, maxLineLength) widthBefore = editorView.renderedLines.width() expect(widthBefore).toBe editorView.scrollView.width() + 20 - buffer.change([[12,0], [12,0]], [1..maxLineLength*2].join('')) + buffer.setTextInRange([[12,0], [12,0]], [1..maxLineLength*2].join('')) expect(editorView.renderedLines.width()).toBeGreaterThan widthBefore describe "when lines are removed", -> @@ -1432,7 +1432,7 @@ describe "EditorView", -> it "sets the rendered screen line's width to either the max line length or the scollView's width (whichever is greater)", -> maxLineLength = editor.getMaxScreenLineLength() setEditorWidthInChars(editorView, maxLineLength) - buffer.change([[12,0], [12,0]], [1..maxLineLength*2].join('')) + buffer.setTextInRange([[12,0], [12,0]], [1..maxLineLength*2].join('')) expect(editorView.renderedLines.width()).toBeGreaterThan editorView.scrollView.width() widthBefore = editorView.renderedLines.width() buffer.delete([[12, 0], [12, Infinity]]) @@ -1445,7 +1445,7 @@ describe "EditorView", -> expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(12) - buffer.change([[1,0], [2,0]], "") + buffer.setTextInRange([[1,0], [2,0]], "") expect(editorView.renderedLines.find(".line").length).toBe 6 expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(11) @@ -1457,21 +1457,21 @@ describe "EditorView", -> expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(12) - buffer.change([[7,0], [11,0]], "1\n2\n") + buffer.setTextInRange([[7,0], [11,0]], "1\n2\n") expect(editorView.renderedLines.find(".line").length).toBe 5 expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(10) describe "when the change straddles the last rendered row", -> it "renders the correct rows", -> - buffer.change([[2,0], [7,0]], "") + buffer.setTextInRange([[2,0], [7,0]], "") expect(editorView.renderedLines.find(".line").length).toBe 7 expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(0) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(6) describe "when the change the follows the last rendered row", -> it "does not change the rendered lines", -> - buffer.change([[10,0], [12,0]], "") + buffer.setTextInRange([[10,0], [12,0]], "") expect(editorView.renderedLines.find(".line").length).toBe 7 expect(editorView.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(0) expect(editorView.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(6) diff --git a/spec/language-mode-spec.coffee b/spec/language-mode-spec.coffee index 4899663b8..16798c26f 100644 --- a/spec/language-mode-spec.coffee +++ b/spec/language-mode-spec.coffee @@ -188,17 +188,17 @@ describe "LanguageMode", -> expect(buffer.lineForRow(3)).toBe " font-weight: bold !important;" it "uncomments lines with leading whitespace", -> - buffer.change([[2, 0], [2, Infinity]], " /*width: 110%;*/") + buffer.setTextInRange([[2, 0], [2, Infinity]], " /*width: 110%;*/") languageMode.toggleLineCommentsForBufferRows(2, 2) expect(buffer.lineForRow(2)).toBe " width: 110%;" it "uncomments lines with trailing whitespace", -> - buffer.change([[2, 0], [2, Infinity]], "/*width: 110%;*/ ") + buffer.setTextInRange([[2, 0], [2, Infinity]], "/*width: 110%;*/ ") languageMode.toggleLineCommentsForBufferRows(2, 2) expect(buffer.lineForRow(2)).toBe "width: 110%; " it "uncomments lines with leading and trailing whitespace", -> - buffer.change([[2, 0], [2, Infinity]], " /*width: 110%;*/ ") + buffer.setTextInRange([[2, 0], [2, Infinity]], " /*width: 110%;*/ ") languageMode.toggleLineCommentsForBufferRows(2, 2) expect(buffer.lineForRow(2)).toBe " width: 110%; " diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index 0abd31d05..ead84fe75 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -270,7 +270,7 @@ describe "Project", -> it "does NOT save when modified", -> editor = atom.project.openSync('sample.js') - editor.buffer.change([[0,0],[0,0]], 'omg') + editor.buffer.setTextInRange([[0,0],[0,0]], 'omg') expect(editor.isModified()).toBeTruthy() results = [] diff --git a/spec/tokenized-buffer-spec.coffee b/spec/tokenized-buffer-spec.coffee index 8fc8fa90a..f45dfa8d5 100644 --- a/spec/tokenized-buffer-spec.coffee +++ b/spec/tokenized-buffer-spec.coffee @@ -119,7 +119,7 @@ describe "TokenizedBuffer", -> describe "when there is a buffer change surrounding an invalid row", -> it "pushes the invalid row to the end of the change", -> - buffer.change([[4, 0], [6, 0]], "\n\n\n") + buffer.setTextInRange([[4, 0], [6, 0]], "\n\n\n") changeHandler.reset() expect(tokenizedBuffer.firstInvalidRow()).toBe 8 @@ -128,7 +128,7 @@ describe "TokenizedBuffer", -> describe "when there is a buffer change inside an invalid region", -> it "does not attempt to tokenize the lines in the change, and preserves the existing invalid row", -> expect(tokenizedBuffer.firstInvalidRow()).toBe 5 - buffer.change([[6, 0], [7, 0]], "\n\n\n") + buffer.setTextInRange([[6, 0], [7, 0]], "\n\n\n") expect(tokenizedBuffer.lineForScreenRow(6).ruleStack?).toBeFalsy() expect(tokenizedBuffer.lineForScreenRow(7).ruleStack?).toBeFalsy() @@ -143,7 +143,7 @@ describe "TokenizedBuffer", -> describe "when there is a buffer change that is smaller than the chunk size", -> describe "when lines are updated, but none are added or removed", -> it "updates tokens to reflect the change", -> - buffer.change([[0, 0], [2, 0]], "foo()\n7\n") + buffer.setTextInRange([[0, 0], [2, 0]], "foo()\n7\n") expect(tokenizedBuffer.lineForScreenRow(0).tokens[1]).toEqual(value: '(', scopes: ['source.js', 'meta.brace.round.js']) expect(tokenizedBuffer.lineForScreenRow(1).tokens[0]).toEqual(value: '7', scopes: ['source.js', 'constant.numeric.js']) @@ -185,7 +185,7 @@ describe "TokenizedBuffer", -> describe "when lines are both updated and removed", -> it "updates tokens to reflect the change", -> - buffer.change([[1, 0], [3, 0]], "foo()") + buffer.setTextInRange([[1, 0], [3, 0]], "foo()") # previous line 0 remains expect(tokenizedBuffer.lineForScreenRow(0).tokens[0]).toEqual(value: 'var', scopes: ['source.js', 'storage.modifier.js']) @@ -209,7 +209,7 @@ describe "TokenizedBuffer", -> buffer.insert([5, 30], '/* */') changeHandler.reset() - buffer.change([[2, 0], [3, 0]], '/*') + buffer.setTextInRange([[2, 0], [3, 0]], '/*') expect(tokenizedBuffer.lineForScreenRow(2).tokens[0].scopes).toEqual ['source.js', 'comment.block.js', 'punctuation.definition.comment.js'] expect(tokenizedBuffer.lineForScreenRow(3).tokens[0].scopes).toEqual ['source.js'] expect(changeHandler).toHaveBeenCalled() @@ -228,7 +228,7 @@ describe "TokenizedBuffer", -> describe "when lines are both updated and inserted", -> it "updates tokens to reflect the change", -> - buffer.change([[1, 0], [2, 0]], "foo()\nbar()\nbaz()\nquux()") + buffer.setTextInRange([[1, 0], [2, 0]], "foo()\nbar()\nbaz()\nquux()") # previous line 0 remains expect(tokenizedBuffer.lineForScreenRow(0).tokens[0]).toEqual( value: 'var', scopes: ['source.js', 'storage.modifier.js']) diff --git a/src/editor.coffee b/src/editor.coffee index c5b83ef67..d9db05305 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -381,7 +381,7 @@ class Editor extends Model else endColumn = @lineForBufferRow(bufferRow).match(/^\s*/)[0].length newIndentString = @buildIndentString(newLevel) - @buffer.change([[bufferRow, 0], [bufferRow, endColumn]], newIndentString) + @buffer.setTextInRange([[bufferRow, 0], [bufferRow, endColumn]], newIndentString) # Public: Get the indentation level of the given line of text. # @@ -456,8 +456,8 @@ class Editor extends Model # {Delegates to: TextBuffer.nextNonBlankRow} nextNonBlankBufferRow: (bufferRow) -> @buffer.nextNonBlankRow(bufferRow) - # {Delegates to: TextBuffer.getEofPosition} - getEofBufferPosition: -> @buffer.getEofPosition() + # {Delegates to: TextBuffer.getEndPosition} + getEofBufferPosition: -> @buffer.getEndPosition() # Public: Returns a {Number} representing the last zero-indexed buffer row # number of the editor. @@ -1348,7 +1348,7 @@ class Editor extends Model # text - A {String} # # Returns the {Range} of the newly-inserted text. - setTextInBufferRange: (range, text) -> @getBuffer().change(range, text) + setTextInBufferRange: (range, text) -> @getBuffer().setTextInRange(range, text) # Public: Get the {Range} of the paragraph surrounding the most recently added # cursor. diff --git a/src/language-mode.coffee b/src/language-mode.coffee index 31b66f7bc..3f3193857 100644 --- a/src/language-mode.coffee +++ b/src/language-mode.coffee @@ -53,11 +53,11 @@ class LanguageMode buffer.transact -> columnStart = startMatch[1].length columnEnd = columnStart + startMatch[2].length - buffer.change([[start, columnStart], [start, columnEnd]], "") + buffer.setTextInRange([[start, columnStart], [start, columnEnd]], "") endLength = buffer.lineLengthForRow(end) - endMatch[2].length endColumn = endLength - endMatch[1].length - buffer.change([[end, endColumn], [end, endLength]], "") + buffer.setTextInRange([[end, endColumn], [end, endLength]], "") else buffer.transact -> buffer.insert([start, 0], commentStartString) @@ -72,7 +72,7 @@ class LanguageMode if match = commentStartRegex.search(buffer.lineForRow(row)) columnStart = match[1].length columnEnd = columnStart + match[2].length - buffer.change([[row, columnStart], [row, columnEnd]], "") + buffer.setTextInRange([[row, columnStart], [row, columnEnd]], "") else if start is end indent = @editor.indentationForBufferRow(start) @@ -86,7 +86,7 @@ class LanguageMode if indentLength = line.match(indentRegex)?[0].length buffer.insert([row, indentLength], commentStartString) else - buffer.change([[row, 0], [row, indentString.length]], indentString + commentStartString) + buffer.setTextInRange([[row, 0], [row, indentString.length]], indentString + commentStartString) # Folds all the foldable lines in the buffer. foldAll: -> diff --git a/src/selection.coffee b/src/selection.coffee index c6673764b..2e262cc93 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -74,7 +74,7 @@ class Selection setBufferRange: (bufferRange, options={}) -> bufferRange = Range.fromObject(bufferRange) @needsAutoscroll = options.autoscroll - options.isReversed ?= @isReversed() + options.reversed ?= @isReversed() @editor.destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds @modifySelection => @cursor.needsAutoscroll = false if options.autoscroll? @@ -293,7 +293,7 @@ class Selection if options.indentBasis? and not options.autoIndent text = @normalizeIndents(text, options.indentBasis) - newBufferRange = @editor.buffer.change(oldBufferRange, text, pick(options, 'undo')) + newBufferRange = @editor.buffer.setTextInRange(oldBufferRange, text, pick(options, 'undo')) if options.select @setBufferRange(newBufferRange, isReversed: wasReversed) else