diff --git a/benchmark/benchmark-suite.coffee b/benchmark/benchmark-suite.coffee index c60811985..0a3901ec9 100644 --- a/benchmark/benchmark-suite.coffee +++ b/benchmark/benchmark-suite.coffee @@ -62,8 +62,8 @@ describe "editorView.", -> describe "empty-vs-set-innerHTML.", -> [firstRow, lastRow] = [] beforeEach -> - firstRow = editorView.getFirstVisibleScreenRow() - lastRow = editorView.getLastVisibleScreenRow() + firstRow = editorView.getModel().getFirstVisibleScreenRow() + lastRow = editorView.getModel().getLastVisibleScreenRow() benchmark "build-gutter-html.", 1000, -> editorView.gutter.renderLineNumbers(null, firstRow, lastRow) @@ -97,8 +97,8 @@ describe "editorView.", -> describe "multiple-lines.", -> [firstRow, lastRow] = [] beforeEach -> - firstRow = editorView.getFirstVisibleScreenRow() - lastRow = editorView.getLastVisibleScreenRow() + firstRow = editorView.getModel().getFirstVisibleScreenRow() + lastRow = editorView.getModel().getLastVisibleScreenRow() benchmark "cache-entire-visible-area", 100, -> for i in [firstRow..lastRow] diff --git a/src/editor-view.coffee b/src/editor-view.coffee index cefec694d..852463d8e 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -101,7 +101,6 @@ class EditorView extends View @overlayer = $(node).find('.lines').addClass('overlayer') @hiddenInput = $(node).find('.hidden-input') - # FIXME: there should be a better way to deal with the gutter element @subscribe atom.config.observe 'editor.showLineNumbers', => @gutter = $(node).find('.gutter') @@ -169,45 +168,28 @@ class EditorView extends View else @editor.getScrollLeft() - # Public: Scrolls the editor to the bottom. scrollToBottom: -> + deprecate 'Use Editor::scrollToBottom instead. You can get the editor via editorView.getModel()' @editor.setScrollBottom(Infinity) - # Public: Scrolls the editor to the given screen position. - # - # * `screenPosition` An object that represents a buffer position. It can be either - # an {Object} (`{row, column}`), {Array} (`[row, column]`), or {Point} - # * `options` (optional) {Object} matching the options available to {::scrollToScreenPosition} scrollToScreenPosition: (screenPosition, options) -> + deprecate 'Use Editor::scrollToScreenPosition instead. You can get the editor via editorView.getModel()' @editor.scrollToScreenPosition(screenPosition, options) - # Public: Scrolls the editor to the given buffer position. - # - # * `bufferPosition` An object that represents a buffer position. It can be either - # an {Object} (`{row, column}`), {Array} (`[row, column]`), or {Point} - # * `options` (optional) {Object} matching the options available to {::scrollToBufferPosition} scrollToBufferPosition: (bufferPosition, options) -> + deprecate 'Use Editor::scrollToBufferPosition instead. You can get the editor via editorView.getModel()' @editor.scrollToBufferPosition(bufferPosition, options) scrollToCursorPosition: -> + deprecate 'Use Editor::scrollToCursorPosition instead. You can get the editor via editorView.getModel()' @editor.scrollToCursorPosition() - # Public: Converts a buffer position to a pixel position. - # - # * `bufferPosition` An object that represents a buffer position. It can be either - # an {Object} (`{row, column}`), {Array} (`[row, column]`), or {Point} - # - # Returns an {Object} with two values: `top` and `left`, representing the pixel positions. pixelPositionForBufferPosition: (bufferPosition) -> + deprecate 'Use Editor::pixelPositionForBufferPosition instead. You can get the editor via editorView.getModel()' @editor.pixelPositionForBufferPosition(bufferPosition) - # Public: Converts a screen position to a pixel position. - # - # * `screenPosition` An object that represents a screen position. It can be either - # an {Object} (`{row, column}`), {Array} (`[row, column]`), or {Point} - # - # Returns an object with two values: `top` and `left`, representing the pixel positions. pixelPositionForScreenPosition: (screenPosition) -> + deprecate 'Use Editor::pixelPositionForScreenPosition instead. You can get the editor via editorView.getModel()' @editor.pixelPositionForScreenPosition(screenPosition) appendToLinesView: (view) -> @@ -273,19 +255,13 @@ class EditorView extends View deprecate('Use editorView.getModel().pageUp()') @editor.pageUp() - # Public: Retrieves the number of the row that is visible and currently at the - # top of the editor. - # - # Returns a {Number}. getFirstVisibleScreenRow: -> - @editor.getVisibleRowRange()[0] + deprecate 'Use Editor::getFirstVisibleScreenRow instead. You can get the editor via editorView.getModel()' + @editor.getFirstVisibleScreenRow() - # Public: Retrieves the number of the row that is visible and currently at the - # bottom of the editor. - # - # Returns a {Number}. getLastVisibleScreenRow: -> - @editor.getVisibleRowRange()[1] + deprecate 'Use Editor::getLastVisibleScreenRow instead. You can get the editor via editorView.getModel()' + @editor.getLastVisibleScreenRow() # Public: Gets the font family for the editor. # @@ -329,10 +305,8 @@ class EditorView extends View setShowIndentGuide: (showIndentGuide) -> @component.setShowIndentGuide(showIndentGuide) - # Public: Enables/disables soft wrap on the editor. - # - # * `softWrap` A {Boolean} which, if `true`, enables soft wrap setSoftWrap: (softWrap) -> + deprecate 'Use Editor::setSoftWrap instead. You can get the editor via editorView.getModel()' @editor.setSoftWrap(softWrap) # Public: Set whether invisible characters are shown. diff --git a/src/editor.coffee b/src/editor.coffee index 4e5be2195..de62f8453 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -2293,14 +2293,52 @@ class Editor extends Model Section: Scrolling the Editor ### - # Public: Scroll the editor to reveal the most recently added cursor if it is + # Essential: Scroll the editor to reveal the most recently added cursor if it is # off-screen. # # * `options` (optional) {Object} - # * `center` Center the editor around the cursor if possible. Defauls to true. + # * `center` Center the editor around the cursor if possible. (default: true) scrollToCursorPosition: (options) -> @getLastCursor().autoscroll(center: options?.center ? true) + # Essential: Scrolls the editor to the given buffer position. + # + # * `bufferPosition` An object that represents a buffer position. It can be either + # an {Object} (`{row, column}`), {Array} (`[row, column]`), or {Point} + # * `options` (optional) {Object} + # * `center` Center the editor around the position if possible. (default: false) + scrollToBufferPosition: (bufferPosition, options) -> + @displayBuffer.scrollToBufferPosition(bufferPosition, options) + + # Essential: Scrolls the editor to the given screen position. + # + # * `screenPosition` An object that represents a buffer position. It can be either + # an {Object} (`{row, column}`), {Array} (`[row, column]`), or {Point} + # * `options` (optional) {Object} + # * `center` Center the editor around the position if possible. (default: false) + scrollToScreenPosition: (screenPosition, options) -> + @displayBuffer.scrollToScreenPosition(screenPosition, options) + + # Essential: Scrolls the editor to the top + scrollToTop: -> + @setScrollTop(0) + + # Essential: Scrolls the editor to the bottom + scrollToBottom: -> + @setScrollBottom(Infinity) + + scrollToScreenRange: (screenRange, options) -> @displayBuffer.scrollToScreenRange(screenRange, options) + + horizontallyScrollable: -> @displayBuffer.horizontallyScrollable() + + verticallyScrollable: -> @displayBuffer.verticallyScrollable() + + getHorizontalScrollbarHeight: -> @displayBuffer.getHorizontalScrollbarHeight() + setHorizontalScrollbarHeight: (height) -> @displayBuffer.setHorizontalScrollbarHeight(height) + + getVerticalScrollbarWidth: -> @displayBuffer.getVerticalScrollbarWidth() + setVerticalScrollbarWidth: (width) -> @displayBuffer.setVerticalScrollbarWidth(width) + pageUp: -> newScrollTop = @getScrollTop() - @getHeight() @moveUp(@getRowsPerPage()) @@ -2358,6 +2396,36 @@ class Editor extends Model Section: Editor Rendering ### + # Extended: Retrieves the number of the row that is visible and currently at the + # top of the editor. + # + # Returns a {Number}. + getFirstVisibleScreenRow: -> + @getVisibleRowRange()[0] + + # Extended: Retrieves the number of the row that is visible and currently at the + # bottom of the editor. + # + # Returns a {Number}. + getLastVisibleScreenRow: -> + @getVisibleRowRange()[1] + + # Extended: Converts a buffer position to a pixel position. + # + # * `bufferPosition` An object that represents a buffer position. It can be either + # an {Object} (`{row, column}`), {Array} (`[row, column]`), or {Point} + # + # Returns an {Object} with two values: `top` and `left`, representing the pixel positions. + pixelPositionForBufferPosition: (bufferPosition) -> @displayBuffer.pixelPositionForBufferPosition(bufferPosition) + + # Extended: Converts a screen position to a pixel position. + # + # * `screenPosition` An object that represents a screen position. It can be either + # an {Object} (`{row, column}`), {Array} (`[row, column]`), or {Point} + # + # Returns an {Object} with two values: `top` and `left`, representing the pixel positions. + pixelPositionForScreenPosition: (screenPosition) -> @displayBuffer.pixelPositionForScreenPosition(screenPosition) + getSelectionMarkerAttributes: -> type: 'selection', editorId: @id, invalidate: 'never' @@ -2411,30 +2479,10 @@ class Editor extends Model selectionIntersectsVisibleRowRange: (selection) -> @displayBuffer.selectionIntersectsVisibleRowRange(selection) - pixelPositionForScreenPosition: (screenPosition) -> @displayBuffer.pixelPositionForScreenPosition(screenPosition) - - pixelPositionForBufferPosition: (bufferPosition) -> @displayBuffer.pixelPositionForBufferPosition(bufferPosition) - screenPositionForPixelPosition: (pixelPosition) -> @displayBuffer.screenPositionForPixelPosition(pixelPosition) pixelRectForScreenRange: (screenRange) -> @displayBuffer.pixelRectForScreenRange(screenRange) - scrollToScreenRange: (screenRange, options) -> @displayBuffer.scrollToScreenRange(screenRange, options) - - scrollToScreenPosition: (screenPosition, options) -> @displayBuffer.scrollToScreenPosition(screenPosition, options) - - scrollToBufferPosition: (bufferPosition, options) -> @displayBuffer.scrollToBufferPosition(bufferPosition, options) - - horizontallyScrollable: -> @displayBuffer.horizontallyScrollable() - - verticallyScrollable: -> @displayBuffer.verticallyScrollable() - - getHorizontalScrollbarHeight: -> @displayBuffer.getHorizontalScrollbarHeight() - setHorizontalScrollbarHeight: (height) -> @displayBuffer.setHorizontalScrollbarHeight(height) - - getVerticalScrollbarWidth: -> @displayBuffer.getVerticalScrollbarWidth() - setVerticalScrollbarWidth: (width) -> @displayBuffer.setVerticalScrollbarWidth(width) - # Deprecated: Call {::joinLines} instead. joinLine: -> deprecate("Use Editor::joinLines() instead")