From 04b0ed9704c89fe7a8b2607dd963d31c0aa64d75 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 4 Sep 2014 15:14:38 -0700 Subject: [PATCH 1/7] Deprecate EditorView::scrollTo*Position() functions --- src/editor-view.coffee | 13 +++-------- src/editor.coffee | 50 +++++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index cefec694d..8d9421a52 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -173,23 +173,16 @@ class EditorView extends View scrollToBottom: -> @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. diff --git a/src/editor.coffee b/src/editor.coffee index 4e5be2195..7ea4f888b 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -2293,14 +2293,44 @@ 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) + + 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()) @@ -2419,22 +2449,6 @@ class Editor extends Model 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") From c511a714886b17fb8d7dae505abe7d2eead51fc0 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 4 Sep 2014 15:17:01 -0700 Subject: [PATCH 2/7] Deprecate EditorView::scrollToBottom --- src/editor-view.coffee | 2 +- src/editor.coffee | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 8d9421a52..544f77288 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -169,8 +169,8 @@ 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) scrollToScreenPosition: (screenPosition, options) -> diff --git a/src/editor.coffee b/src/editor.coffee index 7ea4f888b..f4ae24ddc 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -2319,6 +2319,10 @@ class Editor extends Model scrollToScreenPosition: (screenPosition, options) -> @displayBuffer.scrollToScreenPosition(screenPosition, options) + # Essential: Scrolls the editor to the bottom + scrollToBottom: -> + @setScrollBottom(Infinity) + scrollToScreenRange: (screenRange, options) -> @displayBuffer.scrollToScreenRange(screenRange, options) horizontallyScrollable: -> @displayBuffer.horizontallyScrollable() From 5ae040f6887c2ec27156a14cf475106f4917bdb7 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 4 Sep 2014 15:17:17 -0700 Subject: [PATCH 3/7] Add Editor::scrollToTop to compliment scrollToBottom() --- src/editor.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/editor.coffee b/src/editor.coffee index f4ae24ddc..d95445491 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -2319,6 +2319,10 @@ class Editor extends Model 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) From 52c19a5dcd419e73d550eda424a0b4633fb6e42a Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 4 Sep 2014 15:20:20 -0700 Subject: [PATCH 4/7] Deprecate pixelPositionFor*Position --- src/editor-view.coffee | 14 ++------------ src/editor.coffee | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 544f77288..cc891ec3a 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -185,22 +185,12 @@ class EditorView extends View 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) -> diff --git a/src/editor.coffee b/src/editor.coffee index d95445491..2ca4d20d4 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -2396,6 +2396,22 @@ class Editor extends Model Section: Editor Rendering ### + # 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) -> @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' @@ -2449,10 +2465,6 @@ 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) From dc21e8707f54de77fb0f4459df897c5dace95247 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 4 Sep 2014 15:25:55 -0700 Subject: [PATCH 5/7] Deprecate EditorView::getFirstVisibleScreenRow --- benchmark/benchmark-suite.coffee | 8 ++++---- src/editor-view.coffee | 14 ++++---------- src/editor.coffee | 16 +++++++++++++++- 3 files changed, 23 insertions(+), 15 deletions(-) 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 cc891ec3a..3eccc2340 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -256,19 +256,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. # diff --git a/src/editor.coffee b/src/editor.coffee index 2ca4d20d4..de62f8453 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -2396,7 +2396,21 @@ class Editor extends Model Section: Editor Rendering ### - # Public: Converts a buffer position to a pixel position. + # 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} From dba1e22dedad98cc2a28f6d8bfe3445e4c104db7 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 4 Sep 2014 15:29:54 -0700 Subject: [PATCH 6/7] Deprecate EditorView::setSoftWrap --- src/editor-view.coffee | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 3eccc2340..41d6d4431 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -306,10 +306,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. From 70df5a5c0ab594579340b154229ad2ddd16c04f3 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 4 Sep 2014 15:30:06 -0700 Subject: [PATCH 7/7] Remove unnecessary fixme --- src/editor-view.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 41d6d4431..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')