diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 2c8320383..2fe53ceb3 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -92,7 +92,7 @@ beforeEach -> grammarRegistry: atom.grammars, notificationManager: atom.notifications, setRepresentedFilename: jasmine.createSpy('setRepresentedFilename'), setDocumentEdited: atom.setDocumentEdited.bind(atom), atomVersion: atom.getVersion(), - clipboard: atom.clipboard + clipboard: atom.clipboard, viewRegistry: atom.views }) atom.themes.workspace = atom.workspace atom.keymaps.keyBindings = _.clone(keyBindingsToRestore) diff --git a/src/atom.coffee b/src/atom.coffee index 6e46497f4..1341ae0be 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -175,7 +175,7 @@ class Atom extends Model @workspace = new Workspace({ @config, @project, packageManager: @packages, grammarRegistry: @grammars, notificationManager: @notifications, setRepresentedFilename: @setRepresentedFilename.bind(this), - setDocumentEdited: @setDocumentEdited.bind(this), @clipboard + setDocumentEdited: @setDocumentEdited.bind(this), @clipboard, viewRegistry: @views }) @themes.workspace = @workspace diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 4859c64d4..cd64c1036 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -77,6 +77,7 @@ class TextEditor extends Model state.config = atomEnvironment.config state.notificationManager = atomEnvironment.notifications state.clipboard = atomEnvironment.clipboard + state.viewRegistry = atomEnvironment.views new this(state) constructor: (params={}) -> @@ -85,7 +86,8 @@ class TextEditor extends Model { @softTabs, @scrollRow, @scrollColumn, initialLine, initialColumn, tabLength, softWrapped, @displayBuffer, buffer, suppressCursorCreation, @mini, @placeholderText, - lineNumberGutterVisible, largeFileMode, @config, @notificationManager, @clipboard + lineNumberGutterVisible, largeFileMode, @config, @notificationManager, @clipboard, + @viewRegistry } = params @emitter = new Emitter @@ -432,12 +434,12 @@ class TextEditor extends Model onDidChangeScrollTop: (callback) -> Grim.deprecate("This is now a view method. Call TextEditorElement::onDidChangeScrollTop instead.") - atom.views.getView(this).onDidChangeScrollTop(callback) + @viewRegistry.getView(this).onDidChangeScrollTop(callback) onDidChangeScrollLeft: (callback) -> Grim.deprecate("This is now a view method. Call TextEditorElement::onDidChangeScrollLeft instead.") - atom.views.getView(this).onDidChangeScrollLeft(callback) + @viewRegistry.getView(this).onDidChangeScrollLeft(callback) onDidRequestAutoscroll: (callback) -> @displayBuffer.onDidRequestAutoscroll(callback) @@ -461,7 +463,7 @@ class TextEditor extends Model softTabs = @getSoftTabs() newEditor = new TextEditor({ @buffer, displayBuffer, @tabLength, softTabs, suppressCursorCreation: true, - @config, @notificationManager, @clipboard + @config, @notificationManager, @clipboard, @viewRegistry }) for marker in @findMarkers(editorId: @id) marker.copy(editorId: newEditor.id, preserveFolds: true) @@ -2872,24 +2874,24 @@ class TextEditor extends Model scrollToTop: -> Grim.deprecate("This is now a view method. Call TextEditorElement::scrollToTop instead.") - atom.views.getView(this).scrollToTop() + @viewRegistry.getView(this).scrollToTop() scrollToBottom: -> Grim.deprecate("This is now a view method. Call TextEditorElement::scrollToTop instead.") - atom.views.getView(this).scrollToBottom() + @viewRegistry.getView(this).scrollToBottom() scrollToScreenRange: (screenRange, options) -> @displayBuffer.scrollToScreenRange(screenRange, options) getHorizontalScrollbarHeight: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getHorizontalScrollbarHeight instead.") - atom.views.getView(this).getHorizontalScrollbarHeight() + @viewRegistry.getView(this).getHorizontalScrollbarHeight() getVerticalScrollbarWidth: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getVerticalScrollbarWidth instead.") - atom.views.getView(this).getVerticalScrollbarWidth() + @viewRegistry.getView(this).getVerticalScrollbarWidth() pageUp: -> @moveUp(@getRowsPerPage()) @@ -2956,19 +2958,19 @@ class TextEditor extends Model getFirstVisibleScreenRow: -> deprecate("This is now a view method. Call TextEditorElement::getFirstVisibleScreenRow instead.") - atom.views.getView(this).getVisibleRowRange()[0] + @viewRegistry.getView(this).getVisibleRowRange()[0] getLastVisibleScreenRow: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getLastVisibleScreenRow instead.") - atom.views.getView(this).getVisibleRowRange()[1] + @viewRegistry.getView(this).getVisibleRowRange()[1] pixelPositionForBufferPosition: (bufferPosition) -> Grim.deprecate("This method is deprecated on the model layer. Use `TextEditorElement::pixelPositionForBufferPosition` instead") - atom.views.getView(this).pixelPositionForBufferPosition(bufferPosition) + @viewRegistry.getView(this).pixelPositionForBufferPosition(bufferPosition) pixelPositionForScreenPosition: (screenPosition) -> Grim.deprecate("This method is deprecated on the model layer. Use `TextEditorElement::pixelPositionForScreenPosition` instead") - atom.views.getView(this).pixelPositionForScreenPosition(screenPosition) + @viewRegistry.getView(this).pixelPositionForScreenPosition(screenPosition) getSelectionMarkerAttributes: -> {type: 'selection', editorId: @id, invalidate: 'never', maintainHistory: true} @@ -2999,7 +3001,7 @@ class TextEditor extends Model @displayBuffer.setHeight(height) else Grim.deprecate("This is now a view method. Call TextEditorElement::setHeight instead.") - atom.views.getView(this).setHeight(height) + @viewRegistry.getView(this).setHeight(height) getHeight: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getHeight instead.") @@ -3012,7 +3014,7 @@ class TextEditor extends Model @displayBuffer.setWidth(width) else Grim.deprecate("This is now a view method. Call TextEditorElement::setWidth instead.") - atom.views.getView(this).setWidth(width) + @viewRegistry.getView(this).setWidth(width) getWidth: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getWidth instead.") @@ -3027,77 +3029,77 @@ class TextEditor extends Model getScrollTop: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getScrollTop instead.") - atom.views.getView(this).getScrollTop() + @viewRegistry.getView(this).getScrollTop() setScrollTop: (scrollTop) -> Grim.deprecate("This is now a view method. Call TextEditorElement::setScrollTop instead.") - atom.views.getView(this).setScrollTop(scrollTop) + @viewRegistry.getView(this).setScrollTop(scrollTop) getScrollBottom: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getScrollBottom instead.") - atom.views.getView(this).getScrollBottom() + @viewRegistry.getView(this).getScrollBottom() setScrollBottom: (scrollBottom) -> Grim.deprecate("This is now a view method. Call TextEditorElement::setScrollBottom instead.") - atom.views.getView(this).setScrollBottom(scrollBottom) + @viewRegistry.getView(this).setScrollBottom(scrollBottom) getScrollLeft: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getScrollLeft instead.") - atom.views.getView(this).getScrollLeft() + @viewRegistry.getView(this).getScrollLeft() setScrollLeft: (scrollLeft) -> Grim.deprecate("This is now a view method. Call TextEditorElement::setScrollLeft instead.") - atom.views.getView(this).setScrollLeft(scrollLeft) + @viewRegistry.getView(this).setScrollLeft(scrollLeft) getScrollRight: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getScrollRight instead.") - atom.views.getView(this).getScrollRight() + @viewRegistry.getView(this).getScrollRight() setScrollRight: (scrollRight) -> Grim.deprecate("This is now a view method. Call TextEditorElement::setScrollRight instead.") - atom.views.getView(this).setScrollRight(scrollRight) + @viewRegistry.getView(this).setScrollRight(scrollRight) getScrollHeight: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getScrollHeight instead.") - atom.views.getView(this).getScrollHeight() + @viewRegistry.getView(this).getScrollHeight() getScrollWidth: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getScrollWidth instead.") - atom.views.getView(this).getScrollWidth() + @viewRegistry.getView(this).getScrollWidth() getVisibleRowRange: -> Grim.deprecate("This is now a view method. Call TextEditorElement::getVisibleRowRange instead.") - atom.views.getView(this).getVisibleRowRange() + @viewRegistry.getView(this).getVisibleRowRange() intersectsVisibleRowRange: (startRow, endRow) -> Grim.deprecate("This is now a view method. Call TextEditorElement::intersectsVisibleRowRange instead.") - atom.views.getView(this).intersectsVisibleRowRange(startRow, endRow) + @viewRegistry.getView(this).intersectsVisibleRowRange(startRow, endRow) selectionIntersectsVisibleRowRange: (selection) -> Grim.deprecate("This is now a view method. Call TextEditorElement::selectionIntersectsVisibleRowRange instead.") - atom.views.getView(this).selectionIntersectsVisibleRowRange(selection) + @viewRegistry.getView(this).selectionIntersectsVisibleRowRange(selection) screenPositionForPixelPosition: (pixelPosition) -> Grim.deprecate("This is now a view method. Call TextEditorElement::screenPositionForPixelPosition instead.") - atom.views.getView(this).screenPositionForPixelPosition(pixelPosition) + @viewRegistry.getView(this).screenPositionForPixelPosition(pixelPosition) pixelRectForScreenRange: (screenRange) -> Grim.deprecate("This is now a view method. Call TextEditorElement::pixelRectForScreenRange instead.") - atom.views.getView(this).pixelRectForScreenRange(screenRange) + @viewRegistry.getView(this).pixelRectForScreenRange(screenRange) ### Section: Utility diff --git a/src/workspace.coffee b/src/workspace.coffee index 396bb9445..8e7004cf5 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -26,8 +26,10 @@ class Workspace extends Model constructor: (params) -> super - {@packageManager, @config, @project, @grammarRegistry, @notificationManager, @clipboard} = params - {@setRepresentedFilename, @setDocumentEdited} = params + { + @packageManager, @config, @project, @grammarRegistry, @notificationManager, + @clipboard, @viewRegistry, @setRepresentedFilename, @setDocumentEdited + } = params @emitter = new Emitter @openers = [] @@ -456,7 +458,7 @@ class Workspace extends Model @buildTextEditor(_.extend({buffer, largeFileMode}, options)) buildTextEditor: (params) -> - new TextEditor(_.extend({@config, @notificationManager, @clipboard}, params)) + new TextEditor(_.extend({@config, @notificationManager, @clipboard, @viewRegistry}, params)) # Public: Asynchronously reopens the last-closed item's URI if it hasn't already been # reopened.