From fe0b7b8de3a88e7453273972303ac5a47b0cc7c0 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 7 Oct 2016 17:40:04 +0200 Subject: [PATCH 1/4] Start exporting `TextEditor` constructor again --- exports/atom.js | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/exports/atom.js b/exports/atom.js index b22a4cdfb..9ad4f60c2 100644 --- a/exports/atom.js +++ b/exports/atom.js @@ -3,8 +3,6 @@ import TextBuffer, {Point, Range} from 'text-buffer' import {File, Directory} from 'pathwatcher' import {Emitter, Disposable, CompositeDisposable} from 'event-kit' -import Grim from 'grim' -import dedent from 'dedent' import BufferedNodeProcess from '../src/buffered-node-process' import BufferedProcess from '../src/buffered-process' import GitRepository from '../src/git-repository' @@ -39,25 +37,7 @@ if (process.platform === 'win32') { // only be exported when not running as a child node process if (process.type === 'renderer') { atomExport.Task = require('../src/task') - - const TextEditor = (params) => { - return atom.workspace.buildTextEditor(params) - } - - TextEditor.prototype = require('../src/text-editor').prototype - - Object.defineProperty(atomExport, 'TextEditor', { - enumerable: true, - get () { - Grim.deprecate(dedent` - The \`TextEditor\` constructor is no longer public. - - To construct a text editor, use \`atom.workspace.buildTextEditor()\`. - To check if an object is a text editor, use \`atom.workspace.isTextEditor(object)\`. - `) - return TextEditor - } - }) + atomExport.TextEditor = require('../src/text-editor') } export default atomExport From 18ddcf902b1cd567df099653a47f5479104ba6f6 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 7 Oct 2016 18:21:09 +0200 Subject: [PATCH 2/4] Statically assign a clipboard instance to the `TextEditor` class --- spec/text-editor-registry-spec.js | 18 +++--------------- spec/text-editor-spec.coffee | 7 +------ spec/workspace-spec.coffee | 6 +++--- src/atom-environment.coffee | 9 +++------ src/initialize-application-window.coffee | 13 +++++++++---- src/initialize-test-window.coffee | 6 ++++++ src/selection.coffee | 8 ++++---- src/text-editor-registry.js | 8 ++------ src/text-editor.coffee | 17 ++++++++++------- src/workspace.coffee | 2 +- 10 files changed, 42 insertions(+), 52 deletions(-) diff --git a/spec/text-editor-registry-spec.js b/spec/text-editor-registry-spec.js index 05c9548b7..86bb71a6f 100644 --- a/spec/text-editor-registry-spec.js +++ b/spec/text-editor-registry-spec.js @@ -15,15 +15,11 @@ describe('TextEditorRegistry', function () { registry = new TextEditorRegistry({ assert: atom.assert, config: atom.config, - clipboard: atom.clipboard, grammarRegistry: atom.grammars, packageManager: {deferredActivationHooks: null} }) - editor = new TextEditor({ - config: atom.config, - clipboard: atom.clipboard, - }) + editor = new TextEditor() }) afterEach(function () { @@ -194,10 +190,7 @@ describe('TextEditorRegistry', function () { it('does not update the editor when config settings change for unrelated scope selectors', async function () { await atom.packages.activatePackage('language-javascript') - const editor2 = new TextEditor({ - config: atom.config, - clipboard: atom.clipboard, - }) + const editor2 = new TextEditor() editor2.setGrammar(atom.grammars.selectGrammar('test.js')) @@ -224,7 +217,6 @@ describe('TextEditorRegistry', function () { registry = new TextEditorRegistry({ assert: atom.assert, config: atom.config, - clipboard: atom.clipboard, grammarRegistry: atom.grammars, packageManager: { deferredActivationHooks: [], @@ -669,10 +661,7 @@ describe('TextEditorRegistry', function () { describe('serialization', function () { it('persists editors\' grammar overrides', async function () { - const editor2 = new TextEditor({ - config: atom.config, - clipboard: atom.clipboard, - }) + const editor2 = new TextEditor() await atom.packages.activatePackage('language-c') await atom.packages.activatePackage('language-html') @@ -691,7 +680,6 @@ describe('TextEditorRegistry', function () { const registryCopy = new TextEditorRegistry({ assert: atom.assert, config: atom.config, - clipboard: atom.clipboard, grammarRegistry: atom.grammars, packageManager: {deferredActivationHooks: null} }) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 2c4ba084f..4192c5d5a 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -54,7 +54,6 @@ describe "TextEditor", -> # reusing the same buffer instance editor2 = TextEditor.deserialize(editor.serialize(), { assert: atom.assert, - clipboard: atom.clipboard, textEditors: atom.textEditors, project: { bufferForIdSync: (id) -> TextBuffer.deserialize(editor.buffer.serialize()) @@ -5831,11 +5830,7 @@ describe "TextEditor", -> atom.packages.activatePackage('language-coffee-script') it "sets the grammar", -> - editor = new TextEditor({ - grammar: atom.grammars.grammarForScopeName('source.coffee') - clipboard: atom.clipboard - }) - + editor = new TextEditor({grammar: atom.grammars.grammarForScopeName('source.coffee')}) expect(editor.getGrammar().name).toBe 'CoffeeScript' describe "softWrapAtPreferredLineLength", -> diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index fe4c661c6..06a650b87 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -29,7 +29,7 @@ describe "Workspace", -> atom.workspace = new Workspace({ config: atom.config, project: atom.project, packageManager: atom.packages, grammarRegistry: atom.grammars, deserializerManager: atom.deserializers, - notificationManager: atom.notifications, clipboard: atom.clipboard, + notificationManager: atom.notifications, applicationDelegate: atom.applicationDelegate, viewRegistry: atom.views, assert: atom.assert.bind(atom), textEditorRegistry: atom.textEditors @@ -871,7 +871,7 @@ describe "Workspace", -> workspace2 = new Workspace({ config: atom.config, project: atom.project, packageManager: atom.packages, notificationManager: atom.notifications, deserializerManager: atom.deserializers, - clipboard: atom.clipboard, viewRegistry: atom.views, grammarRegistry: atom.grammars, + viewRegistry: atom.views, grammarRegistry: atom.grammars, applicationDelegate: atom.applicationDelegate, assert: atom.assert.bind(atom), textEditorRegistry: atom.textEditors }) @@ -934,7 +934,7 @@ describe "Workspace", -> workspace2 = new Workspace({ config: atom.config, project: atom.project, packageManager: atom.packages, notificationManager: atom.notifications, deserializerManager: atom.deserializers, - clipboard: atom.clipboard, viewRegistry: atom.views, grammarRegistry: atom.grammars, + viewRegistry: atom.views, grammarRegistry: atom.grammars, applicationDelegate: atom.applicationDelegate, assert: atom.assert.bind(atom), textEditorRegistry: atom.textEditors }) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 13361c576..92a8d1ad3 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -28,7 +28,6 @@ ThemeManager = require './theme-manager' MenuManager = require './menu-manager' ContextMenuManager = require './context-menu-manager' CommandInstaller = require './command-installer' -Clipboard = require './clipboard' Project = require './project' TitleBar = require './title-bar' Workspace = require './workspace' @@ -127,7 +126,7 @@ class AtomEnvironment extends Model # Call .loadOrCreate instead constructor: (params={}) -> - {@blobStore, @applicationDelegate, @window, @document, @configDirPath, @enablePersistence, onlyLoadBaseStyleSheets} = params + {@blobStore, @applicationDelegate, @window, @document, @clipboard, @configDirPath, @enablePersistence, onlyLoadBaseStyleSheets} = params @unloaded = false @loadTime = null @@ -182,20 +181,18 @@ class AtomEnvironment extends Model @packages.setContextMenuManager(@contextMenu) @packages.setThemeManager(@themes) - @clipboard = new Clipboard() - @project = new Project({notificationManager: @notifications, packageManager: @packages, @config, @applicationDelegate}) @commandInstaller = new CommandInstaller(@getVersion(), @applicationDelegate) @textEditors = new TextEditorRegistry({ - @config, grammarRegistry: @grammars, assert: @assert.bind(this), @clipboard, + @config, grammarRegistry: @grammars, assert: @assert.bind(this), packageManager: @packages }) @workspace = new Workspace({ @config, @project, packageManager: @packages, grammarRegistry: @grammars, deserializerManager: @deserializers, - notificationManager: @notifications, @applicationDelegate, @clipboard, viewRegistry: @views, assert: @assert.bind(this), + notificationManager: @notifications, @applicationDelegate, viewRegistry: @views, assert: @assert.bind(this), textEditorRegistry: @textEditors, }) diff --git a/src/initialize-application-window.coffee b/src/initialize-application-window.coffee index 63cfa1c2e..585ec93f7 100644 --- a/src/initialize-application-window.coffee +++ b/src/initialize-application-window.coffee @@ -20,16 +20,21 @@ module.exports = ({blobStore}) -> AtomEnvironment = require './atom-environment' ApplicationDelegate = require './application-delegate' + Clipboard = require './clipboard' + TextEditor = require './text-editor' + + clipboard = new Clipboard + TextEditor.setClipboard(clipboard) + window.atom = new AtomEnvironment({ - window, document, blobStore, + window, document, clipboard, blobStore, applicationDelegate: new ApplicationDelegate, - configDirPath: process.env.ATOM_HOME - enablePersistence: true + configDirPath: process.env.ATOM_HOME, + enablePersistence: true, env: process.env }) atom.startEditorWindow().then -> - # Workaround for focus getting cleared upon window creation windowFocused = -> window.removeEventListener('focus', windowFocused) diff --git a/src/initialize-test-window.coffee b/src/initialize-test-window.coffee index 6c812b4d3..e4706fe1d 100644 --- a/src/initialize-test-window.coffee +++ b/src/initialize-test-window.coffee @@ -21,6 +21,8 @@ module.exports = ({blobStore}) -> {getWindowLoadSettings} = require './window-load-settings-helpers' AtomEnvironment = require '../src/atom-environment' ApplicationDelegate = require '../src/application-delegate' + Clipboard = require '../src/clipboard' + TextEditor = require '../src/text-editor' require '../src/electron-shims' {testRunnerPath, legacyTestRunnerPath, headless, logFile, testPaths} = getWindowLoadSettings() @@ -58,11 +60,15 @@ module.exports = ({blobStore}) -> document.title = "Spec Suite" + clipboard = new Clipboard + TextEditor.setClipboard(clipboard) + testRunner = require(testRunnerPath) legacyTestRunner = require(legacyTestRunnerPath) buildDefaultApplicationDelegate = -> new ApplicationDelegate() buildAtomEnvironment = (params) -> params = cloneObject(params) + params.clipboard = clipboard unless params.hasOwnProperty("clipboard") params.blobStore = blobStore unless params.hasOwnProperty("blobStore") params.onlyLoadBaseStyleSheets = true unless params.hasOwnProperty("onlyLoadBaseStyleSheets") new AtomEnvironment(params) diff --git a/src/selection.coffee b/src/selection.coffee index d63605a86..5eaa9c8dd 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -14,7 +14,7 @@ class Selection extends Model initialScreenRange: null wordwise: false - constructor: ({@cursor, @marker, @editor, id, @clipboard}) -> + constructor: ({@cursor, @marker, @editor, id}) -> @emitter = new Emitter @assignId(id) @@ -605,7 +605,7 @@ class Selection extends Model startLevel = @editor.indentLevelForLine(precedingText) if maintainClipboard - {text: clipboardText, metadata} = @clipboard.readWithMetadata() + {text: clipboardText, metadata} = @editor.constructor.clipboard.readWithMetadata() metadata ?= {} unless metadata.selections? metadata.selections = [{ @@ -618,9 +618,9 @@ class Selection extends Model indentBasis: startLevel, fullLine: fullLine }) - @clipboard.write([clipboardText, selectionText].join("\n"), metadata) + @editor.constructor.clipboard.write([clipboardText, selectionText].join("\n"), metadata) else - @clipboard.write(selectionText, { + @editor.constructor.clipboard.write(selectionText, { indentBasis: startLevel, fullLine: fullLine }) diff --git a/src/text-editor-registry.js b/src/text-editor-registry.js index 9868df2d5..b29a3887c 100644 --- a/src/text-editor-registry.js +++ b/src/text-editor-registry.js @@ -39,9 +39,8 @@ const GRAMMAR_SELECTION_RANGE = Range(Point.ZERO, Point(10, 0)).freeze() // done using your editor, be sure to call `dispose` on the returned disposable // to avoid leaking editors. export default class TextEditorRegistry { - constructor ({config, grammarRegistry, clipboard, assert, packageManager}) { + constructor ({config, grammarRegistry, assert, packageManager}) { this.assert = assert - this.clipboard = clipboard this.config = config this.grammarRegistry = grammarRegistry this.scopedSettingsDelegate = new ScopedSettingsDelegate(config) @@ -109,10 +108,7 @@ export default class TextEditorRegistry { } build (params) { - params = Object.assign({ - clipboard: this.clipboard, - assert: this.assert - }, params) + params = Object.assign({assert: this.assert}, params) let scope = null if (params.buffer) { diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 034b9e8f0..052d5e1b4 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -59,6 +59,9 @@ ZERO_WIDTH_NBSP = '\ufeff' # soft wraps and folds to ensure your code interacts with them correctly. module.exports = class TextEditor extends Model + @setClipboard: (clipboard) -> + @clipboard = clipboard + serializationVersion: 1 buffer: null @@ -114,7 +117,6 @@ class TextEditor extends Model if state.displayLayer = state.buffer.getDisplayLayer(state.displayLayerId) state.selectionsMarkerLayer = state.displayLayer.getMarkerLayer(state.selectionsMarkerLayerId) - state.clipboard = atomEnvironment.clipboard state.assert = atomEnvironment.assert.bind(atomEnvironment) editor = new this(state) if state.registered @@ -123,19 +125,20 @@ class TextEditor extends Model editor constructor: (params={}) -> + unless @constructor.clipboard? + throw new Error("Must call TextEditor.setClipboard at least once before creating TextEditor instances") + super { @softTabs, @firstVisibleScreenRow, @firstVisibleScreenColumn, initialLine, initialColumn, tabLength, @softWrapped, @decorationManager, @selectionsMarkerLayer, @buffer, suppressCursorCreation, - @mini, @placeholderText, lineNumberGutterVisible, @largeFileMode, @clipboard, + @mini, @placeholderText, lineNumberGutterVisible, @largeFileMode, @assert, grammar, @showInvisibles, @autoHeight, @autoWidth, @scrollPastEnd, @editorWidthInChars, @tokenizedBuffer, @displayLayer, @invisibles, @showIndentGuide, @softWrapped, @softWrapAtPreferredLineLength, @preferredLineLength } = params - throw new Error("Must pass a clipboard parameter when constructing TextEditors") unless @clipboard? - @assert ?= (condition) -> condition @firstVisibleScreenRow ?= 0 @firstVisibleScreenColumn ?= 0 @@ -705,7 +708,7 @@ class TextEditor extends Model suppressCursorCreation: true, tabLength: @tokenizedBuffer.getTabLength(), @firstVisibleScreenRow, @firstVisibleScreenColumn, - @clipboard, @assert, displayLayer, grammar: @getGrammar(), + @assert, displayLayer, grammar: @getGrammar(), @autoWidth, @autoHeight }) @@ -2718,7 +2721,7 @@ class TextEditor extends Model # Returns the new {Selection}. addSelection: (marker, options={}) -> cursor = @addCursor(marker) - selection = new Selection(Object.assign({editor: this, marker, cursor, @clipboard}, options)) + selection = new Selection(Object.assign({editor: this, marker, cursor}, options)) @selections.push(selection) selectionBufferRange = selection.getBufferRange() @mergeIntersectingSelections(preserveFolds: options.preserveFolds) @@ -3127,7 +3130,7 @@ class TextEditor extends Model # # * `options` (optional) See {Selection::insertText}. pasteText: (options={}) -> - {text: clipboardText, metadata} = @clipboard.readWithMetadata() + {text: clipboardText, metadata} = @constructor.clipboard.readWithMetadata() return false unless @emitWillInsertTextEvent(clipboardText) metadata ?= {} diff --git a/src/workspace.coffee b/src/workspace.coffee index c279e8062..89c53b678 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -28,7 +28,7 @@ class Workspace extends Model { @packageManager, @config, @project, @grammarRegistry, @notificationManager, - @clipboard, @viewRegistry, @grammarRegistry, @applicationDelegate, @assert, + @viewRegistry, @grammarRegistry, @applicationDelegate, @assert, @deserializerManager, @textEditorRegistry } = params From dbd7817823098988077fe43187267a4e530ed5dd Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 10 Oct 2016 09:26:52 +0200 Subject: [PATCH 3/4] Make `TextEditor.prototype.scrollPastEnd` false by default --- src/text-editor.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 052d5e1b4..02cce3daf 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -150,7 +150,7 @@ class TextEditor extends Model @hasTerminatedPendingState = false @mini ?= false - @scrollPastEnd ?= true + @scrollPastEnd ?= false @showInvisibles ?= true @softTabs ?= true tabLength ?= 2 From 3d2e18747f0d54634d5a750f9cac534923a50359 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 10 Oct 2016 09:28:36 +0200 Subject: [PATCH 4/4] Prefer using `new TextEditor` to `Workspace.prototype.buildTextEditor` --- spec/selection-spec.coffee | 4 +++- spec/text-editor-component-spec.js | 5 +++-- spec/text-editor-element-spec.coffee | 9 +++++---- spec/text-editor-presenter-spec.coffee | 12 ++++++++++-- spec/text-editor-spec.coffee | 6 +++--- spec/workspace-spec.coffee | 5 +++-- src/language-mode.coffee | 6 +++++- src/tokenized-buffer.coffee | 4 +++- 8 files changed, 35 insertions(+), 16 deletions(-) diff --git a/spec/selection-spec.coffee b/spec/selection-spec.coffee index f22b6f6b8..1b21d7411 100644 --- a/spec/selection-spec.coffee +++ b/spec/selection-spec.coffee @@ -1,9 +1,11 @@ +TextEditor = require '../src/text-editor' + describe "Selection", -> [buffer, editor, selection] = [] beforeEach -> buffer = atom.project.bufferForPathSync('sample.js') - editor = atom.workspace.buildTextEditor(buffer: buffer, tabLength: 2) + editor = new TextEditor({buffer: buffer, tabLength: 2}) selection = editor.getLastSelection() afterEach -> diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index afbb3a50e..7de1c6ccd 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -2,6 +2,7 @@ import {it, fit, ffit, fffit, beforeEach, afterEach, conditionPromise} from './async-spec-helpers' import Grim from 'grim' +import TextEditor from '../src/text-editor' import TextEditorElement from '../src/text-editor-element' import _, {extend, flatten, last, toArray} from 'underscore-plus' @@ -4419,7 +4420,7 @@ describe('TextEditorComponent', function () { describe('when autoHeight is not assigned on the editor', function () { it('implicitly assigns autoHeight to true and emits a deprecation warning if the editor has its height assigned via an inline style', function () { - editor = atom.workspace.buildTextEditor() + editor = new TextEditor() element = editor.getElement() element.setUpdatedSynchronously(false) element.style.height = '200px' @@ -4434,7 +4435,7 @@ describe('TextEditorComponent', function () { }) it('implicitly assigns autoHeight to true and emits a deprecation warning if the editor has its height assigned via position absolute with an assigned top and bottom', function () { - editor = atom.workspace.buildTextEditor() + editor = new TextEditor() element = editor.getElement() element.setUpdatedSynchronously(false) parentElement = document.createElement('div') diff --git a/spec/text-editor-element-spec.coffee b/spec/text-editor-element-spec.coffee index 951b5ea36..22b921647 100644 --- a/spec/text-editor-element-spec.coffee +++ b/spec/text-editor-element-spec.coffee @@ -1,3 +1,4 @@ +TextEditor = require '../src/text-editor' TextEditorElement = require '../src/text-editor-element' {Disposable} = require 'event-kit' @@ -33,7 +34,7 @@ describe "TextEditorElement", -> describe "when the model is assigned", -> it "adds the 'mini' attribute if .isMini() returns true on the model", -> element = new TextEditorElement - model = atom.workspace.buildTextEditor(mini: true) + model = new TextEditor({mini: true}) element.setModel(model) expect(element.hasAttribute('mini')).toBe true @@ -52,7 +53,7 @@ describe "TextEditorElement", -> describe "when the editor is detached from the DOM and then reattached", -> it "does not render duplicate line numbers", -> - editor = atom.workspace.buildTextEditor() + editor = new TextEditor editor.setText('1\n2\n3') element = atom.views.getView(editor) @@ -65,7 +66,7 @@ describe "TextEditorElement", -> expect(element.shadowRoot.querySelectorAll('.line-number').length).toBe initialCount it "does not render duplicate decorations in custom gutters", -> - editor = atom.workspace.buildTextEditor() + editor = new TextEditor editor.setText('1\n2\n3') editor.addGutter({name: 'test-gutter'}) marker = editor.markBufferRange([[0, 0], [2, 0]]) @@ -200,7 +201,7 @@ describe "TextEditorElement", -> describe "::getMaxScrollTop", -> it "returns the maximum scroll top that can be applied to the element", -> - editor = atom.workspace.buildTextEditor() + editor = new TextEditor editor.setText('1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16') element = atom.views.getView(editor) element.style.lineHeight = "10px" diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 8cc5e5086..f4760ece1 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -2,6 +2,7 @@ _ = require 'underscore-plus' randomWords = require 'random-words' TextBuffer = require 'text-buffer' {Point, Range} = TextBuffer +TextEditor = require '../src/text-editor' TextEditorPresenter = require '../src/text-editor-presenter' FakeLinesYardstick = require './fake-lines-yardstick' LineTopIndex = require 'line-top-index' @@ -18,7 +19,7 @@ describe "TextEditorPresenter", -> spyOn(window, "clearInterval").andCallFake window.fakeClearInterval buffer = new TextBuffer(filePath: require.resolve('./fixtures/sample.js')) - editor = atom.workspace.buildTextEditor({buffer}) + editor = new TextEditor({buffer}) waitsForPromise -> buffer.load() afterEach -> @@ -474,6 +475,7 @@ describe "TextEditorPresenter", -> waitsForPromise -> atom.packages.activatePackage('language-javascript') runs -> + editor.setGrammar(atom.grammars.grammarForScopeName('source.js')) maxLineLength = editor.getMaxScreenLineLength() presenter = buildPresenter(contentFrameWidth: 50, baseCharacterWidth: 10) @@ -758,6 +760,7 @@ describe "TextEditorPresenter", -> waitsForPromise -> atom.packages.activatePackage('language-javascript') runs -> + editor.setGrammar(atom.grammars.grammarForScopeName('source.js')) editor.setCursorBufferPosition([3, 6]) presenter = buildPresenter() expect(getState(presenter).hiddenInput.width).toBe 10 @@ -917,6 +920,7 @@ describe "TextEditorPresenter", -> waitsForPromise -> atom.packages.activatePackage('language-javascript') runs -> + editor.setGrammar(atom.grammars.grammarForScopeName('source.js')) maxLineLength = editor.getMaxScreenLineLength() presenter = buildPresenter(contentFrameWidth: 50, baseCharacterWidth: 10) @@ -1264,6 +1268,8 @@ describe "TextEditorPresenter", -> expectValues lineStateForScreenRow(presenter, 3), {screenRow: 3, tagCodes: editor.screenLineForScreenRow(3).tagCodes} it "includes the .endOfLineInvisibles if the editor.showInvisibles config option is true", -> + editor.update({showInvisibles: false, invisibles: {eol: 'X'}}) + editor.setText("hello\nworld\r\n") presenter = buildPresenter(explicitHeight: 25, scrollTop: 0, lineHeight: 10) expect(tagsForCodes(presenter, lineStateForScreenRow(presenter, 0).tagCodes).openTags).not.toContain('invisible-character eol') @@ -1730,6 +1736,7 @@ describe "TextEditorPresenter", -> atom.packages.activatePackage('language-javascript') runs -> + editor.setGrammar(atom.grammars.grammarForScopeName('source.js')) editor.setCursorBufferPosition([1, 4]) presenter = buildPresenter(explicitHeight: 20) @@ -2075,6 +2082,7 @@ describe "TextEditorPresenter", -> atom.packages.activatePackage('language-javascript') runs -> + editor.setGrammar(atom.grammars.grammarForScopeName('source.js')) editor.setSelectedBufferRanges([ [[2, 4], [2, 6]], ]) @@ -3666,7 +3674,7 @@ describe "TextEditorPresenter", -> performSetup = -> buffer = new TextBuffer - editor = atom.workspace.buildTextEditor({buffer}) + editor = new TextEditor({buffer}) editor.setEditorWidthInChars(80) presenterParams = model: editor diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 4192c5d5a..c1c7141c3 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -5524,7 +5524,7 @@ describe "TextEditor", -> describe "auto height", -> it "returns true by default but can be customized", -> - editor = atom.workspace.buildTextEditor() + editor = new TextEditor expect(editor.getAutoHeight()).toBe(true) editor.update({autoHeight: false}) expect(editor.getAutoHeight()).toBe(false) @@ -5542,10 +5542,10 @@ describe "TextEditor", -> describe '.get/setPlaceholderText()', -> it 'can be created with placeholderText', -> - newEditor = atom.workspace.buildTextEditor( + newEditor = new TextEditor({ mini: true placeholderText: 'yep' - ) + }) expect(newEditor.getPlaceholderText()).toBe 'yep' it 'models placeholderText and emits an event when changed', -> diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 06a650b87..61f1e8266 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -1,5 +1,6 @@ path = require 'path' temp = require 'temp' +TextEditor = require '../src/text-editor' Workspace = require '../src/workspace' Project = require '../src/project' platform = require './spec-helper-platform' @@ -795,7 +796,7 @@ describe "Workspace", -> describe "::isTextEditor(obj)", -> it "returns true when the passed object is an instance of `TextEditor`", -> - expect(workspace.isTextEditor(atom.workspace.buildTextEditor())).toBe(true) + expect(workspace.isTextEditor(new TextEditor)).toBe(true) expect(workspace.isTextEditor({getText: -> null})).toBe(false) expect(workspace.isTextEditor(null)).toBe(false) expect(workspace.isTextEditor(undefined)).toBe(false) @@ -1727,7 +1728,7 @@ describe "Workspace", -> describe "when there's no repository for the editor's file", -> it "doesn't do anything", -> - editor = atom.workspace.buildTextEditor() + editor = new TextEditor editor.setText("stuff") atom.workspace.checkoutHeadRevision(editor) diff --git a/src/language-mode.coffee b/src/language-mode.coffee index 0e1013cca..ad038d7db 100644 --- a/src/language-mode.coffee +++ b/src/language-mode.coffee @@ -2,6 +2,7 @@ _ = require 'underscore-plus' {OnigRegExp} = require 'oniguruma' ScopeDescriptor = require './scope-descriptor' +NullGrammar = require './null-grammar' module.exports = class LanguageMode @@ -245,7 +246,10 @@ class LanguageMode @suggestedIndentForTokenizedLineAtBufferRow(bufferRow, line, tokenizedLine, options) suggestedIndentForLineAtBufferRow: (bufferRow, line, options) -> - tokenizedLine = @editor.tokenizedBuffer.buildTokenizedLineForRowWithText(bufferRow, line) + if @editor.largeFileMode or @editor.tokenizedBuffer.grammar is NullGrammar + tokenizedLine = @editor.tokenizedBuffer.buildPlaceholderTokenizedLineForRowWithText(bufferRow, line) + else + tokenizedLine = @editor.tokenizedBuffer.buildTokenizedLineForRowWithText(bufferRow, line) @suggestedIndentForTokenizedLineAtBufferRow(bufferRow, line, tokenizedLine, options) suggestedIndentForTokenizedLineAtBufferRow: (bufferRow, line, tokenizedLine, options) -> diff --git a/src/tokenized-buffer.coffee b/src/tokenized-buffer.coffee index 20df76c66..80358f23d 100644 --- a/src/tokenized-buffer.coffee +++ b/src/tokenized-buffer.coffee @@ -263,11 +263,13 @@ class TokenizedBuffer extends Model @buildPlaceholderTokenizedLineForRow(row) for row in [startRow..endRow] by 1 buildPlaceholderTokenizedLineForRow: (row) -> + @buildPlaceholderTokenizedLineForRowWithText(row, @buffer.lineForRow(row)) + + buildPlaceholderTokenizedLineForRowWithText: (row, text) -> if @grammar isnt NullGrammar openScopes = [@grammar.startIdForScope(@grammar.scopeName)] else openScopes = [] - text = @buffer.lineForRow(row) tags = [text.length] lineEnding = @buffer.lineEndingForRow(row) new TokenizedLine({openScopes, text, tags, lineEnding, @tokenIterator})