From 609855af3c80f3cbb783ff61588fbb8d798e9ea6 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 18 Jun 2014 21:07:13 -0600 Subject: [PATCH] Decide to measure gutter's width in gutter The gutter is in a better position to determine if the max line number length has changed because it's a property that gets passed in so we can compare current with previous. Fixes #2659 --- src/editor-component.coffee | 9 +++------ src/gutter-component.coffee | 12 +++++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 7ddddd323..9c5cfaa69 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -77,7 +77,7 @@ EditorComponent = React.createClass div className: className, style: {fontSize, lineHeight, fontFamily}, tabIndex: -1, GutterComponent { - ref: 'gutter', lineDecorations, + ref: 'gutter', onWidthChanged: @onGutterWidthChanged, lineDecorations, defaultCharWidth, editor, renderedRowRange, maxLineNumberDigits, scrollViewHeight, scrollTop, scrollHeight, lineHeightInPixels, @pendingChanges, mouseWheelScreenRow } @@ -636,7 +636,6 @@ EditorComponent = React.createClass unless oldDefaultCharWidth is editor.getDefaultCharWidth() @remeasureCharacterWidths() - @measureGutter() else if @measureLineHeightAndDefaultCharWidthWhenShown and @state.visible and not prevState.visible @measureLineHeightAndDefaultCharWidth() @@ -648,10 +647,8 @@ EditorComponent = React.createClass remeasureCharacterWidths: -> @refs.lines.remeasureCharacterWidths() - measureGutter: -> - oldGutterWidth = @gutterWidth - @gutterWidth = @refs.gutter.getDOMNode().offsetWidth - @requestUpdate() if @gutterWidth isnt oldGutterWidth + onGutterWidthChanged: (@gutterWidth) -> + @requestUpdate() measureScrollbars: -> @measuringScrollbars = false diff --git a/src/gutter-component.coffee b/src/gutter-component.coffee index c85e19c6b..0f9a55c75 100644 --- a/src/gutter-component.coffee +++ b/src/gutter-component.coffee @@ -12,6 +12,7 @@ GutterComponent = React.createClass mixins: [SubscriberMixin] dummyLineNumberNode: null + measuredWidth: null render: -> {scrollHeight, scrollViewHeight, scrollTop} = @props @@ -48,10 +49,13 @@ GutterComponent = React.createClass false componentDidUpdate: (oldProps) -> - unless oldProps.maxLineNumberDigits is @props.maxLineNumberDigits + unless isEqualForProperties(oldProps, @props, 'maxLineNumberDigits') @updateDummyLineNumber() @removeLineNumberNodes() + unless isEqualForProperties(oldProps, @props, 'maxLineNumberDigits', 'defaultCharWidth') + @measureWidth() + @clearScreenRowCaches() unless oldProps.lineHeightInPixels is @props.lineHeightInPixels @updateLineNumbers() @@ -202,6 +206,12 @@ GutterComponent = React.createClass else editor.foldBufferRow(bufferRow) + measureWidth: -> + width = @getDOMNode().offsetWidth + unless width is @measuredWidth + @measuredWidth = width + @props.onWidthChanged?(width) + # Created because underscore uses === not _.isEqual, which we need contains = (array, target) -> return false unless array?