diff --git a/spec/random-editor-spec.coffee b/spec/random-editor-spec.coffee index d235ebc25..3924a8412 100644 --- a/spec/random-editor-spec.coffee +++ b/spec/random-editor-spec.coffee @@ -15,7 +15,7 @@ describe "TextEditor", -> it "properly renders soft-wrapped lines when randomly mutated", -> times 10, (i) -> buffer = new TextBuffer - editor = new TextEditor({buffer}) + editor = atom.workspace.buildTextEditor({buffer}) editor.setEditorWidthInChars(80) tokenizedBuffer = editor.displayBuffer.tokenizedBuffer steps = [] @@ -80,7 +80,7 @@ describe "TextEditor", -> text getReferenceScreenLines = -> - referenceEditor = new TextEditor({}) + referenceEditor = atom.workspace.buildTextEditor() referenceEditor.setEditorWidthInChars(80) referenceEditor.setText(editor.getText()) referenceEditor.setSoftWrapped(editor.isSoftWrapped()) diff --git a/spec/selection-spec.coffee b/spec/selection-spec.coffee index e81f7906f..ec40e32cc 100644 --- a/spec/selection-spec.coffee +++ b/spec/selection-spec.coffee @@ -5,7 +5,7 @@ describe "Selection", -> beforeEach -> buffer = atom.project.bufferForPathSync('sample.js') - editor = new TextEditor(buffer: buffer, tabLength: 2) + editor = atom.workspace.buildTextEditor(buffer: buffer, tabLength: 2) selection = editor.getLastSelection() afterEach -> diff --git a/spec/text-editor-element-spec.coffee b/spec/text-editor-element-spec.coffee index 148199425..251c178e7 100644 --- a/spec/text-editor-element-spec.coffee +++ b/spec/text-editor-element-spec.coffee @@ -33,7 +33,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 = new TextEditor(mini: true) + model = atom.workspace.buildTextEditor(mini: true) element.setModel(model) expect(element.hasAttribute('mini')).toBe true @@ -67,7 +67,7 @@ describe "TextEditorElement", -> describe "when the editor is detached from the DOM and then reattached", -> it "does not render duplicate line numbers", -> - editor = new TextEditor + editor = atom.workspace.buildTextEditor() editor.setText('1\n2\n3') element = atom.views.getView(editor) @@ -80,7 +80,7 @@ describe "TextEditorElement", -> expect(element.shadowRoot.querySelectorAll('.line-number').length).toBe initialCount it "does not render duplicate decorations in custom gutters", -> - editor = new TextEditor + editor = atom.workspace.buildTextEditor() editor.setText('1\n2\n3') editor.addGutter({name: 'test-gutter'}) marker = editor.markBufferRange([[0, 0], [2, 0]]) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 453196858..bc60da469 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -17,7 +17,7 @@ describe "TextEditorPresenter", -> spyOn(window, "clearInterval").andCallFake window.fakeClearInterval buffer = new TextBuffer(filePath: require.resolve('./fixtures/sample.js')) - editor = new TextEditor({buffer}) + editor = atom.workspace.buildTextEditor({buffer}) waitsForPromise -> buffer.load() afterEach -> @@ -2804,7 +2804,7 @@ describe "TextEditorPresenter", -> performSetup = -> buffer = new TextBuffer - editor = new TextEditor({buffer}) + editor = atom.workspace.buildTextEditor({buffer}) editor.setEditorWidthInChars(80) presenterParams = model: editor diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 6d29073e1..e3eb5eb6d 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -31,7 +31,7 @@ describe "TextEditor", -> runs -> fs.mkdirSync(pathToOpen) - expect(TextEditor.deserialize(editor1.serialize())).toBeUndefined() + expect(TextEditor.deserialize(editor1.serialize(), atom)).toBeUndefined() it "restores selections and folds based on markers in the buffer", -> editor.setSelectedBufferRange([[1, 2], [3, 4]]) @@ -39,7 +39,7 @@ describe "TextEditor", -> editor.foldBufferRow(4) expect(editor.isFoldedAtBufferRow(4)).toBeTruthy() - editor2 = TextEditor.deserialize(editor.serialize()) + editor2 = TextEditor.deserialize(editor.serialize(), atom) expect(editor2.id).toBe editor.id expect(editor2.getBuffer().getPath()).toBe editor.getBuffer().getPath() @@ -52,7 +52,7 @@ describe "TextEditor", -> atom.config.set('editor.showInvisibles', true) previousInvisibles = editor.tokenizedLineForScreenRow(0).invisibles - editor2 = TextEditor.deserialize(editor.serialize()) + editor2 = TextEditor.deserialize(editor.serialize(), atom) expect(previousInvisibles).toBeDefined() expect(editor2.displayBuffer.tokenizedLineForScreenRow(0).invisibles).toEqual previousInvisibles @@ -62,7 +62,7 @@ describe "TextEditor", -> state = editor.serialize() atom.config.set('editor.invisibles', eol: '?') - editor2 = TextEditor.deserialize(state) + editor2 = TextEditor.deserialize(state, atom) expect(editor.tokenizedLineForScreenRow(0).invisibles.eol).toBe '?' @@ -4411,11 +4411,10 @@ describe "TextEditor", -> describe '.get/setPlaceholderText()', -> it 'can be created with placeholderText', -> - TextBuffer = require 'text-buffer' - newEditor = new TextEditor - buffer: new TextBuffer + newEditor = atom.workspace.buildTextEditor( mini: true placeholderText: 'yep' + ) expect(newEditor.getPlaceholderText()).toBe 'yep' it 'models placeholderText and emits an event when changed', -> @@ -4443,7 +4442,7 @@ describe "TextEditor", -> describe "when there's no repository for the editor's file", -> it "doesn't do anything", -> - editor = new TextEditor({}) + editor = atom.workspace.buildTextEditor() editor.setText("stuff") editor.checkoutHeadRevision() diff --git a/src/text-editor-element.coffee b/src/text-editor-element.coffee index 5f87bb6ff..d8667770f 100644 --- a/src/text-editor-element.coffee +++ b/src/text-editor-element.coffee @@ -99,7 +99,7 @@ class TextEditorElement extends HTMLElement @model ? @buildModel() buildModel: -> - @setModel(new TextEditor( + @setModel(atom.workspace.buildTextEditor( buffer: new TextBuffer(@textContent) softWrapped: false tabLength: 2 diff --git a/src/text-editor.coffee b/src/text-editor.coffee index e6719565c..18d61e06a 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -65,7 +65,7 @@ class TextEditor extends Model selectionFlashDuration: 500 gutterContainer: null - @deserialize: (state) -> + @deserialize: (state, atomEnvironment) -> try displayBuffer = DisplayBuffer.deserialize(state.displayBuffer) catch error @@ -75,12 +75,19 @@ class TextEditor extends Model throw error state.displayBuffer = displayBuffer + state.config = atomEnvironment.config state.registerEditor = true new this(state) - constructor: ({@softTabs, @scrollRow, @scrollColumn, initialLine, initialColumn, tabLength, softWrapped, @displayBuffer, buffer, registerEditor, suppressCursorCreation, @mini, @placeholderText, lineNumberGutterVisible, largeFileMode}={}) -> + constructor: (params={}) -> super + { + @softTabs, @scrollRow, @scrollColumn, initialLine, initialColumn, tabLength, + softWrapped, @displayBuffer, buffer, registerEditor, suppressCursorCreation, + @mini, @placeholderText, lineNumberGutterVisible, largeFileMode, @config + } = params + @emitter = new Emitter @disposables = new CompositeDisposable @cursors = [] @@ -105,7 +112,7 @@ class TextEditor extends Model @languageMode = new LanguageMode(this) - @setEncoding(atom.config.get('core.fileEncoding', scope: @getRootScopeDescriptor())) + @setEncoding(@config.get('core.fileEncoding', scope: @getRootScopeDescriptor())) @gutterContainer = new GutterContainer(this) @lineNumberGutter = @gutterContainer.addGutter @@ -146,7 +153,7 @@ class TextEditor extends Model subscribeToTabTypeConfig: -> @tabTypeSubscription?.dispose() - @tabTypeSubscription = atom.config.observe 'editor.tabType', scope: @getRootScopeDescriptor(), => + @tabTypeSubscription = @config.observe 'editor.tabType', scope: @getRootScopeDescriptor(), => @softTabs = @shouldUseSoftTabs(defaultValue: @softTabs) destroyed: -> @@ -454,7 +461,10 @@ class TextEditor extends Model copy: -> displayBuffer = @displayBuffer.copy() softTabs = @getSoftTabs() - newEditor = new TextEditor({@buffer, displayBuffer, @tabLength, softTabs, suppressCursorCreation: true, registerEditor: true}) + newEditor = new TextEditor({ + @buffer, displayBuffer, @tabLength, softTabs, suppressCursorCreation: true, + registerEditor: true, @config + }) for marker in @findMarkers(editorId: @id) marker.copy(editorId: newEditor.id, preserveFolds: true) newEditor @@ -592,14 +602,14 @@ class TextEditor extends Model # Essential: Saves the editor's text buffer. # # See {TextBuffer::save} for more details. - save: -> @buffer.save(backup: atom.config.get('editor.backUpBeforeSaving')) + save: -> @buffer.save(backup: @config.get('editor.backUpBeforeSaving')) # Essential: Saves the editor's text buffer as the given path. # # See {TextBuffer::saveAs} for more details. # # * `filePath` A {String} path. - saveAs: (filePath) -> @buffer.saveAs(filePath, backup: atom.config.get('editor.backUpBeforeSaving')) + saveAs: (filePath) -> @buffer.saveAs(filePath, backup: @config.get('editor.backUpBeforeSaving')) # Determine whether the user should be prompted to save before closing # this editor. @@ -746,7 +756,7 @@ class TextEditor extends Model return false unless @emitWillInsertTextEvent(text) groupingInterval = if options.groupUndo - atom.config.get('editor.undoGroupingInterval') + @config.get('editor.undoGroupingInterval') else 0 @@ -2380,10 +2390,10 @@ class TextEditor extends Model # # Returns a {Boolean} shouldUseSoftTabs: ({defaultValue}) -> - tabType = atom.config.get('editor.tabType', scope: @getRootScopeDescriptor()) + tabType = @config.get('editor.tabType', scope: @getRootScopeDescriptor()) switch tabType when 'auto' - @usesSoftTabs() ? defaultValue ? atom.config.get('editor.softTabs') ? true + @usesSoftTabs() ? defaultValue ? @config.get('editor.softTabs') ? true when 'hard' false when 'soft' @@ -2906,10 +2916,10 @@ class TextEditor extends Model ### shouldAutoIndent: -> - atom.config.get("editor.autoIndent", scope: @getRootScopeDescriptor()) + @config.get("editor.autoIndent", scope: @getRootScopeDescriptor()) shouldAutoIndentOnPaste: -> - atom.config.get("editor.autoIndentOnPaste", scope: @getRootScopeDescriptor()) + @config.get("editor.autoIndentOnPaste", scope: @getRootScopeDescriptor()) ### Section: Event Handlers diff --git a/src/workspace.coffee b/src/workspace.coffee index 51910f90f..c0f13b714 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -458,7 +458,7 @@ class Workspace extends Model @buildTextEditor(_.extend({buffer, largeFileMode}, options)) buildTextEditor: (params) -> - new TextEditor(params) + new TextEditor(_.extend({@config}, params)) # Public: Asynchronously reopens the last-closed item's URI if it hasn't already been # reopened.