Take the gutter width into account when sizing TextEditorElement

This commit is contained in:
Antonio Scandurra
2016-08-17 18:33:04 +02:00
parent c37138e09e
commit 1587dcbe89
3 changed files with 26 additions and 11 deletions

View File

@@ -129,7 +129,7 @@ class TextEditorComponent
updateSync: ->
@updateSyncPreMeasurement()
@oldState ?= {content: {}}
@oldState ?= {width: null}
@newState = @presenter.getPostMeasurementState()
if @editor.getLastSelection()? and not @editor.getLastSelection().isEmpty()
@@ -149,14 +149,12 @@ class TextEditorComponent
else
@domNode.style.height = ''
if (@newState.content.autoWidth isnt @oldState.content.autoWidth) or (@newState.content.width isnt @oldState.content.width)
if @newState.content.autoWidth
@hostElement.style.width = @newState.content.width + 'px'
else if @oldState.content.autoWidth
if @newState.width isnt @oldState.width
if @newState.width?
@hostElement.style.width = @newState.width + 'px'
else
@hostElement.style.width = ''
@oldState.content.width = @newState.content.width
@oldState.content.autoWidth = @newState.content.autoWidth
@oldState.width = @newState.width
if @newState.gutters.length
@mountGutterContainerComponent() unless @gutterContainerComponent?

View File

@@ -110,13 +110,14 @@ class TextEditorPresenter
@updateLines()
@updateFocusedState()
@updateHeightState()
@updateVerticalScrollState()
@updateHorizontalScrollState()
@updateScrollbarsState()
@updateHiddenInputState()
@updateContentState()
@updateFocusedState()
@updateHeightState()
@updateWidthState()
@updateHighlightDecorations() if @shouldUpdateDecorations
@updateTilesState()
@updateCursorsState()
@@ -224,6 +225,12 @@ class TextEditorPresenter
else
@state.height = null
updateWidthState: ->
if @model.getAutoWidth()
@state.width = @state.content.width + @gutterWidth
else
@state.width = null
updateVerticalScrollState: ->
@state.content.scrollHeight = @scrollHeight
@sharedGutterStyles.scrollHeight = @scrollHeight
@@ -276,7 +283,6 @@ class TextEditorPresenter
@state.content.width = contentWidth + verticalScrollbarWidth
else
@state.content.width = Math.max(contentWidth + verticalScrollbarWidth, contentFrameWidth)
@state.content.autoWidth = @model.getAutoWidth()
@state.content.scrollWidth = @scrollWidth
@state.content.scrollLeft = @scrollLeft
@state.content.backgroundColor = if @model.isMini() then null else @backgroundColor