diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 718a31a9c..be637d5da 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -813,6 +813,19 @@ describe "Workspace", -> editor.destroy() expect(workspace.getTextEditors()).toHaveLength 0 + describe "when an editor is copied because its pane is split", -> + it "sets up the new editor to be configured by the text editor registry", -> + waitsForPromise -> + atom.packages.activatePackage('language-javascript') + + waitsForPromise -> + workspace.open('a').then (editor) -> + editor.setGrammar(atom.grammars.grammarForScopeName('source.js')) + workspace.getActivePane().splitRight(copyActiveItem: true) + newEditor = workspace.getActiveTextEditor() + expect(newEditor).not.toBe(editor) + expect(newEditor.getGrammar().name).toBe(editor.getGrammar().name) + it "stores the active grammars used by all the open editors", -> waitsForPromise -> atom.packages.activatePackage('language-javascript') diff --git a/src/text-editor-registry.js b/src/text-editor-registry.js index 1fb9fccde..2d57ddcc9 100644 --- a/src/text-editor-registry.js +++ b/src/text-editor-registry.js @@ -124,6 +124,10 @@ export default class TextEditorRegistry { } maintainGrammar (editor) { + if (this.editorsWithMaintainedGrammar.has(editor)) { + return + } + this.editorsWithMaintainedGrammar.add(editor) this.selectGrammarForEditor(editor) this.subscriptions.add(editor.onDidChangePath(() => { @@ -148,6 +152,10 @@ export default class TextEditorRegistry { } maintainConfig (editor) { + if (this.editorsWithMaintainedConfig.has(editor)) { + return + } + this.editorsWithMaintainedConfig.add(editor) this.subscribeToSettingsForEditorScope(editor) editor.setScopedSettingsDelegate(this.scopedSettingsDelegate) diff --git a/src/workspace.coffee b/src/workspace.coffee index 865027893..79600b969 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -84,10 +84,12 @@ class Workspace extends Model @openers = [] @destroyedItemURIs = [] @consumeServices(@packageManager) + @subscribeToAddedItems() subscribeToEvents: -> @subscribeToActiveItem() @subscribeToFontSize() + @subscribeToAddedItems() consumeServices: ({serviceHub}) -> @directorySearchers = [] @@ -160,6 +162,13 @@ class Workspace extends Model @activeItemSubscriptions.add(titleSubscription) if titleSubscription? @activeItemSubscriptions.add(modifiedSubscription) if modifiedSubscription? + subscribeToAddedItems: -> + @onDidAddPaneItem ({item, pane, index}) => + if item instanceof TextEditor + # @textEditorRegistry.maintainConfig(item) + # @textEditorRegistry.maintainGrammar(item) + @emitter.emit 'did-add-text-editor', {textEditor: item, pane, index} + # Updates the application's title and proxy icon based on whichever file is # open. updateWindowTitle: => @@ -383,8 +392,7 @@ class Workspace extends Model # # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. onDidAddTextEditor: (callback) -> - @onDidAddPaneItem ({item, pane, index}) -> - callback({textEditor: item, pane, index}) if item instanceof TextEditor + @emitter.on 'did-add-text-editor', callback ### Section: Opening