From c09c6728434e70a153beb6785f804e4763e856d2 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 13 Jun 2012 14:40:23 -0600 Subject: [PATCH] Rename screenLineForRow -> lineForScreenRow --- spec/app/edit-session-spec.coffee | 26 ++++++------ spec/app/highlighter-spec.coffee | 68 +++++++++++++++---------------- spec/app/screen-line-spec.coffee | 6 +-- src/app/edit-session.coffee | 4 +- src/app/editor.coffee | 1 - src/app/highlighter.coffee | 2 +- src/app/renderer.coffee | 2 +- 7 files changed, 54 insertions(+), 55 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index c712c60b4..d05ad699c 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -613,7 +613,7 @@ describe "EditSession", -> editSession.createFold(2,4) editSession.setSelectedBufferRange([[1,0], [2,0]]) editSession.insertText('holy cow') - expect(editSession.screenLineForRow(2).fold).toBeUndefined() + expect(editSession.lineForScreenRow(2).fold).toBeUndefined() describe "when auto-indent is enabled", -> beforeEach -> @@ -846,7 +846,7 @@ describe "EditSession", -> editSession.createFold(2,4) editSession.setSelectedBufferRange([[1,0], [2,0]]) editSession.backspace() - expect(editSession.screenLineForRow(2).fold).toBeUndefined() + expect(editSession.lineForScreenRow(2).fold).toBeUndefined() describe "when there are multiple selections", -> it "removes all selected text", -> @@ -908,8 +908,8 @@ describe "EditSession", -> editSession.setSelectedBufferRange([[2, 0], [2, 0]]) editSession.delete() - expect(editSession.screenLineForRow(2).text).toBe oldLine7 - expect(editSession.screenLineForRow(3).text).toBe oldLine8 + expect(editSession.lineForScreenRow(2).text).toBe oldLine7 + expect(editSession.lineForScreenRow(3).text).toBe oldLine8 describe "when there are multiple cursors", -> describe "when cursors are on the same line", -> @@ -1241,31 +1241,31 @@ describe "EditSession", -> editSession.setCursorBufferPosition([1,0]) editSession.toggleFold() - expect(editSession.screenLineForRow(1).fold).toBeDefined() + expect(editSession.lineForScreenRow(1).fold).toBeDefined() editSession.toggleFold() - expect(editSession.screenLineForRow(1).fold).toBeUndefined() + expect(editSession.lineForScreenRow(1).fold).toBeUndefined() it "creates/destroys the largest fold containing the cursor position", -> editSession.foldAll() editSession.setCursorBufferPosition([5,1]) editSession.toggleFold() - expect(editSession.screenLineForRow(0).fold).toBeUndefined() - expect(editSession.screenLineForRow(1).fold).toBeDefined() + expect(editSession.lineForScreenRow(0).fold).toBeUndefined() + expect(editSession.lineForScreenRow(1).fold).toBeDefined() editSession.toggleFold() - expect(editSession.screenLineForRow(0).fold).toBeUndefined() - expect(editSession.screenLineForRow(1).fold).toBeUndefined() - expect(editSession.screenLineForRow(4).fold).toBeDefined() + expect(editSession.lineForScreenRow(0).fold).toBeUndefined() + expect(editSession.lineForScreenRow(1).fold).toBeUndefined() + expect(editSession.lineForScreenRow(4).fold).toBeDefined() describe "when a fold-all event is triggered", -> it "creates folds on every line that can be folded", -> editSession.setCursorBufferPosition([5,13]) editSession.foldAll() - expect(editSession.screenLineForRow(0).fold).toBeDefined() - expect(editSession.screenLineForRow(1)).toBeUndefined() + expect(editSession.lineForScreenRow(0).fold).toBeDefined() + expect(editSession.lineForScreenRow(1)).toBeUndefined() it "maintains cursor buffer position when a fold is created/destroyed", -> editSession.setCursorBufferPosition([5,5]) diff --git a/spec/app/highlighter-spec.coffee b/spec/app/highlighter-spec.coffee index 1b1c07cd6..8677dcc25 100644 --- a/spec/app/highlighter-spec.coffee +++ b/spec/app/highlighter-spec.coffee @@ -11,8 +11,8 @@ describe "Highlighter", -> describe "constructor", -> it "tokenizes all the lines in the buffer", -> - expect(highlighter.screenLineForRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var') - expect(highlighter.screenLineForRow(11).tokens[1]).toEqual(type: 'keyword', value: 'return') + expect(highlighter.lineForScreenRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var') + expect(highlighter.lineForScreenRow(11).tokens[1]).toEqual(type: 'keyword', value: 'return') describe "when the buffer changes", -> changeHandler = null @@ -26,11 +26,11 @@ describe "Highlighter", -> range = new Range([0, 0], [2, 0]) buffer.change(range, "foo()\nbar()\n") - expect(highlighter.screenLineForRow(0).tokens[0]).toEqual(type: 'identifier', value: 'foo') - expect(highlighter.screenLineForRow(1).tokens[0]).toEqual(type: 'identifier', value: 'bar') + expect(highlighter.lineForScreenRow(0).tokens[0]).toEqual(type: 'identifier', value: 'foo') + expect(highlighter.lineForScreenRow(1).tokens[0]).toEqual(type: 'identifier', value: 'bar') # line 2 is unchanged - expect(highlighter.screenLineForRow(2).tokens[1]).toEqual(type: 'keyword', value: 'if') + expect(highlighter.lineForScreenRow(2).tokens[1]).toEqual(type: 'keyword', value: 'if') expect(changeHandler).toHaveBeenCalled() [event] = changeHandler.argsForCall[0] @@ -43,9 +43,9 @@ describe "Highlighter", -> changeHandler.reset() buffer.insert([2, 0], '/*') - expect(highlighter.screenLineForRow(3).tokens[0].type).toBe 'comment' - expect(highlighter.screenLineForRow(4).tokens[0].type).toBe 'comment' - expect(highlighter.screenLineForRow(5).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(3).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(4).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(5).tokens[0].type).toBe 'comment' expect(changeHandler).toHaveBeenCalled() [event] = changeHandler.argsForCall[0] @@ -57,7 +57,7 @@ describe "Highlighter", -> buffer.insert([5, 0], '*/') buffer.insert([1, 0], 'var ') - expect(highlighter.screenLineForRow(1).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(1).tokens[0].type).toBe 'comment' describe "when lines are both updated and removed", -> it "updates tokens to reflect the removed lines", -> @@ -65,16 +65,16 @@ describe "Highlighter", -> buffer.change(range, "foo()") # previous line 0 remains - expect(highlighter.screenLineForRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var') + expect(highlighter.lineForScreenRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var') # previous line 3 should be combined with input to form line 1 - expect(highlighter.screenLineForRow(1).tokens[0]).toEqual(type: 'identifier', value: 'foo') - expect(highlighter.screenLineForRow(1).tokens[6]).toEqual(type: 'identifier', value: 'pivot') + expect(highlighter.lineForScreenRow(1).tokens[0]).toEqual(type: 'identifier', value: 'foo') + expect(highlighter.lineForScreenRow(1).tokens[6]).toEqual(type: 'identifier', value: 'pivot') # lines below deleted regions should be shifted upward - expect(highlighter.screenLineForRow(2).tokens[1]).toEqual(type: 'keyword', value: 'while') - expect(highlighter.screenLineForRow(3).tokens[1]).toEqual(type: 'identifier', value: 'current') - expect(highlighter.screenLineForRow(4).tokens[3]).toEqual(type: 'keyword.operator', value: '<') + expect(highlighter.lineForScreenRow(2).tokens[1]).toEqual(type: 'keyword', value: 'while') + expect(highlighter.lineForScreenRow(3).tokens[1]).toEqual(type: 'identifier', value: 'current') + expect(highlighter.lineForScreenRow(4).tokens[3]).toEqual(type: 'keyword.operator', value: '<') expect(changeHandler).toHaveBeenCalled() [event] = changeHandler.argsForCall[0] @@ -86,9 +86,9 @@ describe "Highlighter", -> changeHandler.reset() buffer.change(new Range([2, 0], [3, 0]), '/*') - expect(highlighter.screenLineForRow(2).tokens[0].type).toBe 'comment' - expect(highlighter.screenLineForRow(3).tokens[0].type).toBe 'comment' - expect(highlighter.screenLineForRow(4).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(2).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(3).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(4).tokens[0].type).toBe 'comment' expect(changeHandler).toHaveBeenCalled() [event] = changeHandler.argsForCall[0] @@ -101,19 +101,19 @@ describe "Highlighter", -> buffer.change(range, "foo()\nbar()\nbaz()\nquux()") # previous line 0 remains - expect(highlighter.screenLineForRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var') + expect(highlighter.lineForScreenRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var') # 3 new lines inserted - expect(highlighter.screenLineForRow(1).tokens[0]).toEqual(type: 'identifier', value: 'foo') - expect(highlighter.screenLineForRow(2).tokens[0]).toEqual(type: 'identifier', value: 'bar') - expect(highlighter.screenLineForRow(3).tokens[0]).toEqual(type: 'identifier', value: 'baz') + expect(highlighter.lineForScreenRow(1).tokens[0]).toEqual(type: 'identifier', value: 'foo') + expect(highlighter.lineForScreenRow(2).tokens[0]).toEqual(type: 'identifier', value: 'bar') + expect(highlighter.lineForScreenRow(3).tokens[0]).toEqual(type: 'identifier', value: 'baz') # previous line 2 is joined with quux() on line 4 - expect(highlighter.screenLineForRow(4).tokens[0]).toEqual(type: 'identifier', value: 'quux') - expect(highlighter.screenLineForRow(4).tokens[4]).toEqual(type: 'keyword', value: 'if') + expect(highlighter.lineForScreenRow(4).tokens[0]).toEqual(type: 'identifier', value: 'quux') + expect(highlighter.lineForScreenRow(4).tokens[4]).toEqual(type: 'keyword', value: 'if') # previous line 3 is pushed down to become line 5 - expect(highlighter.screenLineForRow(5).tokens[3]).toEqual(type: 'identifier', value: 'pivot') + expect(highlighter.lineForScreenRow(5).tokens[3]).toEqual(type: 'identifier', value: 'pivot') expect(changeHandler).toHaveBeenCalled() [event] = changeHandler.argsForCall[0] @@ -125,13 +125,13 @@ describe "Highlighter", -> changeHandler.reset() buffer.insert([2, 0], '/*\nabcde\nabcder') - expect(highlighter.screenLineForRow(2).tokens[0].type).toBe 'comment' - expect(highlighter.screenLineForRow(3).tokens[0].type).toBe 'comment' - expect(highlighter.screenLineForRow(4).tokens[0].type).toBe 'comment' - expect(highlighter.screenLineForRow(5).tokens[0].type).toBe 'comment' - expect(highlighter.screenLineForRow(6).tokens[0].type).toBe 'comment' - expect(highlighter.screenLineForRow(7).tokens[0].type).toBe 'comment' - expect(highlighter.screenLineForRow(8).tokens[0].type).not.toBe 'comment' + expect(highlighter.lineForScreenRow(2).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(3).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(4).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(5).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(6).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(7).tokens[0].type).toBe 'comment' + expect(highlighter.lineForScreenRow(8).tokens[0].type).not.toBe 'comment' expect(changeHandler).toHaveBeenCalled() [event] = changeHandler.argsForCall[0] @@ -147,7 +147,7 @@ describe "Highlighter", -> highlighter = new Highlighter(buffer, tabText) it "always renders each tab as its own atomic token containing tabText", -> - screenLine0 = highlighter.screenLineForRow(0) + screenLine0 = highlighter.lineForScreenRow(0) expect(screenLine0.text).toBe "# Econ 101#{tabText}" { tokens } = screenLine0 expect(tokens.length).toBe 2 @@ -156,7 +156,7 @@ describe "Highlighter", -> expect(tokens[1].type).toBe tokens[0].type expect(tokens[1].isAtomic).toBeTruthy() - expect(highlighter.screenLineForRow(2).text).toBe "#{tabText} buy()#{tabText}while supply > demand" + expect(highlighter.lineForScreenRow(2).text).toBe "#{tabText} buy()#{tabText}while supply > demand" describe ".findClosingBracket(startBracketPosition)", -> describe "when called with a bracket type of '{'", -> diff --git a/spec/app/screen-line-spec.coffee b/spec/app/screen-line-spec.coffee index 4fab60651..af884555e 100644 --- a/spec/app/screen-line-spec.coffee +++ b/spec/app/screen-line-spec.coffee @@ -9,7 +9,7 @@ describe "ScreenLine", -> tabText = ' ' buffer = new Buffer(require.resolve 'fixtures/sample.js') highlighter = new Highlighter(buffer, tabText) - screenLine = highlighter.screenLineForRow(3) + screenLine = highlighter.lineForScreenRow(3) describe ".splitAt(column)", -> it "breaks the line fragment into two fragments", -> @@ -70,7 +70,7 @@ describe "ScreenLine", -> [left, right] = screenLine.splitAt(14) expect(left.concat(right)).toEqual screenLine - concatenated = screenLine.concat(highlighter.screenLineForRow(4)) + concatenated = screenLine.concat(highlighter.lineForScreenRow(4)) expect(concatenated.text).toBe ' var pivot = items.shift(), current, left = [], right = []; while(items.length > 0) {' expect(tokensText concatenated.tokens).toBe concatenated.text expect(concatenated.screenDelta).toEqual [2, 0] @@ -80,7 +80,7 @@ describe "ScreenLine", -> beforeEach -> buffer.insert([0, 13], '\t') buffer.insert([0, 0], '\t\t') - screenLine = highlighter.screenLineForRow(0) + screenLine = highlighter.lineForScreenRow(0) describe "when translating from buffer to screen coordinates", -> it "accounts for tab characters being wider on screen", -> diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 1d55b273f..0651e6b3b 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -207,7 +207,7 @@ class EditSession @setCursorBufferPosition([fold.startRow, 0]) isFoldedAtScreenRow: (screenRow) -> - @screenLineForRow(screenRow).fold? + @lineForScreenRow(screenRow).fold? toggleLineCommentsInRange: (range) -> @renderer.toggleLineCommentsInRange(range) @@ -218,7 +218,7 @@ class EditSession fn(selection) for selection in selections @buffer.endUndoBatch(@getSelectedBufferRanges()) - screenLineForRow: (row) -> + lineForScreenRow: (row) -> @renderer.lineForRow(row) stateForScreenRow: (screenRow) -> diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 1dce28b21..01f98d707 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -220,7 +220,6 @@ class Editor extends View @activeEditSession.setSoftWrapColumn(softWrapColumn) if softWrapColumn getScreenLines: -> @renderer.getLines() - screenLineForRow: (start) -> @renderer.lineForRow(start) screenLinesForRows: (start, end) -> @renderer.linesForRows(start, end) screenLineCount: -> @renderer.lineCount() maxScreenLineLength: -> @renderer.maxLineLength() diff --git a/src/app/highlighter.coffee b/src/app/highlighter.coffee index 9fa68a2b9..7ccdac9fb 100644 --- a/src/app/highlighter.coffee +++ b/src/app/highlighter.coffee @@ -65,7 +65,7 @@ class Highlighter text = _.pluck(tokenObjects, 'value').join('') new ScreenLine(tokenObjects, text, [1, 0], [1, 0], { state }) - screenLineForRow: (row) -> + lineForScreenRow: (row) -> @screenLines[row] screenLinesForRows: (startRow, endRow) -> diff --git a/src/app/renderer.coffee b/src/app/renderer.coffee index 70f8ba62a..8117776a3 100644 --- a/src/app/renderer.coffee +++ b/src/app/renderer.coffee @@ -202,7 +202,7 @@ class Renderer startBufferColumn = 0 while currentBufferRow <= endBufferRow - screenLine = @highlighter.screenLineForRow(currentBufferRow) + screenLine = @highlighter.lineForScreenRow(currentBufferRow) screenLine.foldable = @foldSuggester.isBufferRowFoldable(currentBufferRow) if fold = @largestFoldForBufferRow(currentBufferRow)