From b47f6265c71d8df981b1a89b09694e116f76299d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 3 Jun 2014 18:25:25 +0900 Subject: [PATCH] Move gutter width measurement into EditorComponent --- src/editor-component.coffee | 14 ++++++++------ src/gutter-component.coffee | 12 +----------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 7dfc3b830..64cbc8039 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -69,9 +69,8 @@ EditorComponent = React.createClass div className: className, style: {fontSize, lineHeight, fontFamily}, tabIndex: -1, GutterComponent { - ref: 'gutter', editor, renderedRowRange, maxLineNumberDigits, - scrollTop, scrollHeight, lineHeight, lineHeightInPixels, defaultCharWidth, - @pendingChanges, onWidthChanged: @onGutterWidthChanged, mouseWheelScreenRow + ref: 'gutter', editor, renderedRowRange, maxLineNumberDigits, scrollTop, + scrollHeight, lineHeightInPixels, @pendingChanges, mouseWheelScreenRow } div ref: 'scrollView', className: 'scroll-view', onMouseDown: @onMouseDown, @@ -506,9 +505,6 @@ EditorComponent = React.createClass onCursorsMoved: -> @cursorsMoved = true - onGutterWidthChanged: (@gutterWidth) -> - @requestUpdate() - selectToMousePositionUntilMouseUp: (event) -> {editor} = @props dragging = false @@ -587,6 +583,7 @@ EditorComponent = React.createClass unless oldDefaultCharWidth is editor.getDefaultCharWidth() @remeasureCharacterWidths() + @measureGutter() else if @measureLineHeightAndDefaultCharWidthWhenShown and @state.visible and not prevState.visible @measureLineHeightAndDefaultCharWidth() @@ -598,6 +595,11 @@ EditorComponent = React.createClass remeasureCharacterWidths: -> @refs.lines.remeasureCharacterWidths() + measureGutter: -> + oldGutterWidth = @gutterWidth + @gutterWidth = @refs.gutter.getDOMNode().offsetWidth + @requestUpdate() if @gutterWidth isnt oldGutterWidth + measureScrollbars: -> @measuringScrollbars = false diff --git a/src/gutter-component.coffee b/src/gutter-component.coffee index dda3a1b90..72581cd0a 100644 --- a/src/gutter-component.coffee +++ b/src/gutter-component.coffee @@ -10,7 +10,6 @@ GutterComponent = React.createClass displayName: 'GutterComponent' mixins: [SubscriberMixin] - lastMeasuredWidth: null dummyLineNumberNode: null render: -> @@ -34,8 +33,7 @@ GutterComponent = React.createClass # visible row range. shouldComponentUpdate: (newProps) -> return true unless isEqualForProperties(newProps, @props, - 'renderedRowRange', 'scrollTop', 'lineHeightInPixels', 'defaultCharWidth', - 'mouseWheelScreenRow' + 'renderedRowRange', 'scrollTop', 'lineHeightInPixels', 'mouseWheelScreenRow' ) {renderedRowRange, pendingChanges} = newProps @@ -49,7 +47,6 @@ GutterComponent = React.createClass @updateDummyLineNumber() @removeLineNumberNodes() - @measureWidth() unless @lastMeasuredWidth? and isEqualForProperties(oldProps, @props, 'maxLineNumberDigits', 'defaultCharWidth') @clearScreenRowCaches() unless oldProps.lineHeightInPixels is @props.lineHeightInPixels @updateLineNumbers() @@ -159,10 +156,3 @@ GutterComponent = React.createClass lineNumberNodeForScreenRow: (screenRow) -> @lineNumberNodesById[@lineNumberIdsByScreenRow[screenRow]] - - measureWidth: -> - lineNumberNode = @refs.lineNumbers.getDOMNode().firstChild - - width = lineNumberNode.offsetWidth - if width isnt @lastMeasuredWidth - @props.onWidthChanged(@lastMeasuredWidth = width)