From 5efb969a633e13c647c77f53b6ab2eb212e12f4c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 17 Mar 2016 11:19:54 +0100 Subject: [PATCH] :green_heart: Start fixing TextEditorComponent specs --- spec/text-editor-component-spec.js | 15 +++++++-------- src/text-editor.coffee | 4 +++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 37a9751e1..d806b872e 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -69,13 +69,12 @@ describe('TextEditorComponent', function () { describe('line rendering', async function () { function expectTileContainsRow (tileNode, screenRow, {top}) { let lineNode = tileNode.querySelector('[data-screen-row="' + screenRow + '"]') - let tokenizedLine = editor.tokenizedLineForScreenRow(screenRow) - + let text = editor.lineTextForScreenRow(screenRow) expect(lineNode.offsetTop).toBe(top) - if (tokenizedLine.text === '') { + if (text === '') { expect(lineNode.innerHTML).toBe(' ') } else { - expect(lineNode.textContent).toBe(tokenizedLine.text) + expect(lineNode.textContent).toBe(text) } } @@ -294,12 +293,12 @@ describe('TextEditorComponent', function () { await nextViewUpdatePromise() - expect(component.lineNodeForScreenRow(3).textContent).toBe(editor.tokenizedLineForScreenRow(3).text) + expect(component.lineNodeForScreenRow(3).textContent).toBe(editor.lineTextForScreenRow(3)) buffer.delete([[0, 0], [3, 0]]) await nextViewUpdatePromise() - expect(component.lineNodeForScreenRow(3).textContent).toBe(editor.tokenizedLineForScreenRow(3).text) + expect(component.lineNodeForScreenRow(3).textContent).toBe(editor.lineTextForScreenRow(3)) }) it('updates the top position of lines when the line height changes', async function () { @@ -550,8 +549,8 @@ describe('TextEditorComponent', function () { }) it('does not show end of line invisibles at the end of wrapped lines', function () { - expect(component.lineNodeForScreenRow(0).textContent).toBe('a line that ') - expect(component.lineNodeForScreenRow(1).textContent).toBe('wraps' + invisibles.space + invisibles.eol) + expect(component.lineNodeForScreenRow(0).textContent).toBe('a line ') + expect(component.lineNodeForScreenRow(1).textContent).toBe('that wraps' + invisibles.space + invisibles.eol) }) }) }) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index b2ea7985e..52d5ffd47 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -773,7 +773,9 @@ class TextEditor extends Model # given screen row. # # * `screenRow` A {Number} representing a zero-indexed screen row. - lineTextForScreenRow: (screenRow) -> @displayBuffer.tokenizedLineForScreenRow(screenRow)?.text + lineTextForScreenRow: (screenRow) -> + line = @displayLayer.getScreenLines(screenRow, screenRow + 1)[0] + line?.tokens.map((t) -> t.text).join('') # Gets the screen line for the given screen row. #