From 326f2c6a9e2cd3b2ccf39eeda4b3d9a13085daf8 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 22 Mar 2016 14:49:29 +0100 Subject: [PATCH] Add `TextEditor.prototype.tokensForScreenRow` for testing purposes --- spec/text-editor-spec.coffee | 25 +++++++++++-------------- src/text-editor.coffee | 4 ++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index d4f28d9cc..1526dfe3b 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -39,21 +39,19 @@ describe "TextEditor", -> it "preserves the invisibles setting", -> atom.config.set('editor.showInvisibles', true) - previousInvisibles = editor.tokenizedLineForScreenRow(0).invisibles - + previousLineText = editor.lineTextForScreenRow(0) editor2 = TextEditor.deserialize(editor.serialize(), atom) - - expect(previousInvisibles).toBeDefined() - expect(editor2.displayBuffer.tokenizedLineForScreenRow(0).invisibles).toEqual previousInvisibles + expect(editor2.lineTextForScreenRow(0)).toBe(previousLineText) it "updates invisibles if the settings have changed between serialization and deserialization", -> atom.config.set('editor.showInvisibles', true) - + previousLineText = editor.lineTextForScreenRow(0) state = editor.serialize() atom.config.set('editor.invisibles', eol: '?') editor2 = TextEditor.deserialize(state, atom) - expect(editor.tokenizedLineForScreenRow(0).invisibles.eol).toBe '?' + expect(editor2.lineTextForScreenRow(0)).not.toBe(previousLineText) + expect(editor2.lineTextForScreenRow(0).endsWith('?')).toBe(true) describe "when the editor is constructed with the largeFileMode option set to true", -> it "loads the editor but doesn't tokenize", -> @@ -64,15 +62,14 @@ describe "TextEditor", -> runs -> buffer = editor.getBuffer() - expect(editor.tokenizedLineForScreenRow(0).text).toBe buffer.lineForRow(0) - expect(editor.tokenizedLineForScreenRow(0).tokens.length).toBe 1 - expect(editor.tokenizedLineForScreenRow(1).tokens.length).toBe 2 # soft tab - expect(editor.tokenizedLineForScreenRow(12).text).toBe buffer.lineForRow(12) - expect(editor.tokenizedLineForScreenRow(0).tokens.length).toBe 1 + expect(editor.lineTextForScreenRow(0)).toBe buffer.lineForRow(0) + expect(editor.tokensForScreenRow(0).length).toBe 1 + expect(editor.tokensForScreenRow(1).length).toBe 2 # soft tab + expect(editor.lineTextForScreenRow(12)).toBe buffer.lineForRow(12) expect(editor.getCursorScreenPosition()).toEqual [0, 0] editor.insertText('hey"') - expect(editor.tokenizedLineForScreenRow(0).tokens.length).toBe 1 - expect(editor.tokenizedLineForScreenRow(1).tokens.length).toBe 2 # sof tab + expect(editor.tokensForScreenRow(0).length).toBe 1 + expect(editor.tokensForScreenRow(1).length).toBe 2 # soft tab describe ".copy()", -> it "returns a different edit session with the same initial state", -> diff --git a/src/text-editor.coffee b/src/text-editor.coffee index b06ab5194..1f9893132 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -778,6 +778,10 @@ class TextEditor extends Model lineTextForScreenRow: (screenRow) -> @screenLineForScreenRow(screenRow)?.lineText + tokensForScreenRow: (screenRow) -> + for tagCode in @screenLineForScreenRow(screenRow).tagCodes when @displayLayer.isOpenTagCode(tagCode) + @displayLayer.tagForCode(tagCode) + screenLineForScreenRow: (screenRow) -> @displayLayer.getScreenLines(screenRow, screenRow + 1)[0]