diff --git a/spec/text-editor-spec.js b/spec/text-editor-spec.js index 72e1e9f53..3afcce5ce 100644 --- a/spec/text-editor-spec.js +++ b/spec/text-editor-spec.js @@ -85,22 +85,6 @@ describe('TextEditor', () => { }) }) - describe('when the editor is constructed with the largeFileMode option set to true', () => { - it("loads the editor but doesn't tokenize", async () => { - editor = await atom.workspace.openTextFile('sample.js', {largeFileMode: true}) - buffer = editor.getBuffer() - 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.tokensForScreenRow(0).length).toBe(1) - expect(editor.tokensForScreenRow(1).length).toBe(2) - }) - }) - describe('.copy()', () => { it('returns a different editor with the same initial state', () => { expect(editor.getAutoHeight()).toBeFalsy() diff --git a/spec/tokenized-buffer-spec.js b/spec/tokenized-buffer-spec.js index b1574673a..8bc55d538 100644 --- a/spec/tokenized-buffer-spec.js +++ b/spec/tokenized-buffer-spec.js @@ -33,6 +33,34 @@ describe('TokenizedBuffer', () => { } } + describe('when the editor is constructed with the largeFileMode option set to true', () => { + it("loads the editor but doesn't tokenize", async () => { + const line = 'a b c d\n' + buffer = new TextBuffer(line.repeat(256 * 1024)) + expect(buffer.getText().length).toBe(2 * 1024 * 1024) + tokenizedBuffer = new TokenizedBuffer({ + buffer, + grammar: atom.grammars.grammarForScopeName('source.js'), + tabLength: 2 + }) + buffer.setLanguageMode(tokenizedBuffer) + + expect(tokenizedBuffer.isRowCommented(0)).toBeFalsy() + + // It treats the entire line as one big token + let iterator = tokenizedBuffer.buildHighlightIterator() + iterator.seek({row: 0, column: 0}) + iterator.moveToSuccessor() + expect(iterator.getPosition()).toEqual({row: 0, column: 7}) + + buffer.insert([0, 0], 'hey"') + iterator = tokenizedBuffer.buildHighlightIterator() + iterator.seek({row: 0, column: 0}) + iterator.moveToSuccessor() + expect(iterator.getPosition()).toEqual({row: 0, column: 11}) + }) + }) + describe('serialization', () => { describe('when the underlying buffer has a path', () => { beforeEach(async () => { diff --git a/src/text-editor.js b/src/text-editor.js index b98461b28..ac495a355 100644 --- a/src/text-editor.js +++ b/src/text-editor.js @@ -123,7 +123,6 @@ class TextEditor { this.mini = (params.mini != null) ? params.mini : false this.placeholderText = params.placeholderText this.showLineNumbers = params.showLineNumbers - this.largeFileMode = params.largeFileMode this.assert = params.assert || (condition => condition) this.showInvisibles = (params.showInvisibles != null) ? params.showInvisibles : true this.autoHeight = params.autoHeight @@ -528,7 +527,6 @@ class TextEditor { mini: this.mini, editorWidthInChars: this.editorWidthInChars, width: this.width, - largeFileMode: this.largeFileMode, maxScreenLineLength: this.maxScreenLineLength, registered: this.registered, invisibles: this.invisibles, diff --git a/src/tokenized-buffer.js b/src/tokenized-buffer.js index 0ddbebdf1..633187198 100644 --- a/src/tokenized-buffer.js +++ b/src/tokenized-buffer.js @@ -29,6 +29,9 @@ class TokenizedBuffer { this.tabLength = params.tabLength this.largeFileMode = params.largeFileMode this.config = params.config + this.largeFileMode = params.largeFileMode != null + ? params.largeFileMode + : this.buffer.buffer.getLength() >= 2 * 1024 * 1024 this.grammar = params.grammar || NullGrammar this.rootScopeDescriptor = new ScopeDescriptor({scopes: [this.grammar.scopeName]}) diff --git a/src/workspace.js b/src/workspace.js index 3e47a8fad..9f2ad397b 100644 --- a/src/workspace.js +++ b/src/workspace.js @@ -1211,9 +1211,7 @@ module.exports = class Workspace extends Model { } const fileSize = fs.getSizeSync(filePath) - - const largeFileMode = fileSize >= (2 * 1048576) // 2MB - if (fileSize >= (this.config.get('core.warnOnLargeFileLimit') * 1048576)) { // 20MB by default + if (fileSize >= (this.config.get('core.warnOnLargeFileLimit') * 1048576)) { const choice = this.applicationDelegate.confirm({ message: 'Atom will be unresponsive during the loading of very large files.', detailedMessage: 'Do you still want to load this file?', @@ -1228,7 +1226,7 @@ module.exports = class Workspace extends Model { return this.project.bufferForPath(filePath, options) .then(buffer => { - return this.textEditorRegistry.build(Object.assign({buffer, largeFileMode, autoHeight: false}, options)) + return this.textEditorRegistry.build(Object.assign({buffer, autoHeight: false}, options)) }) }