mirror of
https://github.com/atom/atom.git
synced 2026-02-10 14:45:11 -05:00
Adjust the width of rendered lines to account for the longest line
This commit is contained in:
@@ -235,20 +235,11 @@ class Editor extends View
|
||||
@clearRenderedLines()
|
||||
@subscribeToFontSize()
|
||||
@calculateDimensions()
|
||||
@setSoftWrapColumn() if @softWrap
|
||||
@prepareForVerticalScrolling()
|
||||
|
||||
# this also renders the visible lines
|
||||
@setScrollPositionFromActiveEditSession()
|
||||
|
||||
# TODO: The redundant assignment of scrollLeft below is needed because the
|
||||
# lines weren't rendered when we called
|
||||
# setScrollPositionFromActiveEditSession above. Remove this when we fix that
|
||||
# problem by setting the width of the lines container based on the max line
|
||||
# length
|
||||
|
||||
@scrollView.scrollLeft(@getActiveEditSession().scrollLeft ? 0)
|
||||
@hiddenInput.width(@charWidth)
|
||||
@setSoftWrapColumn() if @softWrap
|
||||
@prepareForScrolling()
|
||||
@setScrollPositionFromActiveEditSession() # this also renders the visible lines
|
||||
$(window).on "resize.editor#{@id}", => @updateRenderedLines()
|
||||
@focus() if @isFocused
|
||||
@trigger 'editor-open', [this]
|
||||
|
||||
@@ -264,10 +255,17 @@ class Editor extends View
|
||||
@compositeSelection.mergeIntersectingSelections({reverse})
|
||||
@syncCursorAnimations()
|
||||
|
||||
prepareForVerticalScrolling: ->
|
||||
linesHeight = @lineHeight * @screenLineCount()
|
||||
@verticalScrollbarContent.height(linesHeight)
|
||||
@renderedLines.css('padding-bottom', linesHeight)
|
||||
prepareForScrolling: ->
|
||||
@adjustHeightOfRenderedLines()
|
||||
@adjustWidthOfRenderedLines()
|
||||
|
||||
adjustHeightOfRenderedLines: ->
|
||||
heightOfRenderedLines = @lineHeight * @screenLineCount()
|
||||
@verticalScrollbarContent.height(heightOfRenderedLines)
|
||||
@renderedLines.css('padding-bottom', heightOfRenderedLines)
|
||||
|
||||
adjustWidthOfRenderedLines: ->
|
||||
@renderedLines.width(@charWidth * @maxScreenLineLength())
|
||||
|
||||
scrollTop: (scrollTop, options) ->
|
||||
return @cachedScrollTop or 0 unless scrollTop?
|
||||
@@ -314,6 +312,9 @@ class Editor extends View
|
||||
screenLineCount: ->
|
||||
@renderer.lineCount()
|
||||
|
||||
maxScreenLineLength: ->
|
||||
@renderer.maxLineLength()
|
||||
|
||||
getLastScreenRow: ->
|
||||
@screenLineCount() - 1
|
||||
|
||||
@@ -333,11 +334,9 @@ class Editor extends View
|
||||
@buffer.on "path-change.editor#{@id}", => @trigger 'editor-path-change'
|
||||
|
||||
@renderer = new Renderer(@buffer, { softWrapColumn: @calcSoftWrapColumn(), tabText: @tabText })
|
||||
if @attached
|
||||
@prepareForVerticalScrolling()
|
||||
@renderLines()
|
||||
|
||||
@prepareForScrolling() if @attached
|
||||
@loadEditSessionForBuffer(@buffer)
|
||||
@renderLines() if @attached
|
||||
|
||||
@buffer.on "change.editor#{@id}", (e) => @handleBufferChange(e)
|
||||
@renderer.on 'change', (e) => @handleRendererChange(e)
|
||||
@@ -452,6 +451,7 @@ class Editor extends View
|
||||
|
||||
if @attached
|
||||
@verticalScrollbarContent.height(@lineHeight * @screenLineCount())
|
||||
@adjustWidthOfRenderedLines()
|
||||
|
||||
return if oldScreenRange.start.row > @lastRenderedScreenRow
|
||||
|
||||
|
||||
@@ -54,6 +54,13 @@ class LineMap
|
||||
lastScreenRow: ->
|
||||
@screenLineCount() - 1
|
||||
|
||||
maxScreenLineLength: ->
|
||||
maxLength = 0
|
||||
@traverseByDelta 'screenDelta', [0, 0], [@lastScreenRow(), 0], ({lineFragment}) ->
|
||||
length = lineFragment.text.length
|
||||
maxLength = length if length > maxLength
|
||||
maxLength
|
||||
|
||||
screenPositionForBufferPosition: (bufferPosition, options) ->
|
||||
@translatePosition('bufferDelta', 'screenDelta', bufferPosition, options)
|
||||
|
||||
|
||||
@@ -150,6 +150,9 @@ class Renderer
|
||||
lineCount: ->
|
||||
@lineMap.screenLineCount()
|
||||
|
||||
maxLineLength: ->
|
||||
@lineMap.maxScreenLineLength()
|
||||
|
||||
screenPositionForBufferPosition: (position, options) ->
|
||||
@lineMap.screenPositionForBufferPosition(position, options)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user