mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Move largeFileMode logic to TokenizedBuffer
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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]})
|
||||
|
||||
@@ -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))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user