mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
Adjust Editor.scrollTop when removing a line reduces the scroll height
This eliminates rendering artifacts and jerky scrolling at the bottom of the screen
This commit is contained in:
parent
3ee7c0dc0f
commit
bdfdf08ea0
@ -1311,6 +1311,38 @@ describe "Editor", ->
|
||||
expect(editor.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(0)
|
||||
expect(editor.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(6)
|
||||
|
||||
describe "when the last line is removed when the editor is scrolled to the bottom", ->
|
||||
it "reduces the editor's scrollTop (due to the reduced total scroll height) and renders the correct screen lines", ->
|
||||
editor.setCursorScreenPosition([Infinity, Infinity])
|
||||
editor.insertText('\n\n\n')
|
||||
editor.scrollToBottom()
|
||||
|
||||
expect(buffer.getLineCount()).toBe 16
|
||||
|
||||
initialScrollTop = editor.scrollTop()
|
||||
expect(editor.firstRenderedScreenRow).toBe 9
|
||||
expect(editor.lastRenderedScreenRow).toBe 15
|
||||
|
||||
editor.backspace()
|
||||
|
||||
expect(editor.scrollTop()).toBeLessThan initialScrollTop
|
||||
expect(editor.firstRenderedScreenRow).toBe 9
|
||||
expect(editor.lastRenderedScreenRow).toBe 14
|
||||
|
||||
expect(editor.find('.line').length).toBe 6
|
||||
|
||||
editor.backspace()
|
||||
expect(editor.firstRenderedScreenRow).toBe 9
|
||||
expect(editor.lastRenderedScreenRow).toBe 13
|
||||
|
||||
expect(editor.find('.line').length).toBe 5
|
||||
|
||||
editor.backspace()
|
||||
expect(editor.firstRenderedScreenRow).toBe 6
|
||||
expect(editor.lastRenderedScreenRow).toBe 12
|
||||
|
||||
expect(editor.find('.line').length).toBe 7
|
||||
|
||||
it "decreases the width of the rendered screen lines if the max line length changes", ->
|
||||
widthBefore = editor.renderedLines.width()
|
||||
buffer.delete([[6, 0], [6, Infinity]])
|
||||
|
@ -658,6 +658,11 @@ class Editor extends View
|
||||
adjustWidthOfRenderedLines: ->
|
||||
@renderedLines.width(@charWidth * @maxScreenLineLength())
|
||||
|
||||
handleScrollHeightChange: ->
|
||||
scrollHeight = @lineHeight * @screenLineCount()
|
||||
@verticalScrollbarContent.height(scrollHeight)
|
||||
@scrollBottom(scrollHeight) if @scrollBottom() > scrollHeight
|
||||
|
||||
renderLines: ->
|
||||
@clearRenderedLines()
|
||||
@updateRenderedLines()
|
||||
@ -717,7 +722,7 @@ class Editor extends View
|
||||
newScreenRange = e.newRange
|
||||
|
||||
if @attached
|
||||
@verticalScrollbarContent.height(@lineHeight * @screenLineCount())
|
||||
@handleScrollHeightChange() unless newScreenRange.coversSameRows(oldScreenRange)
|
||||
@adjustWidthOfRenderedLines()
|
||||
|
||||
return if oldScreenRange.start.row > @lastRenderedScreenRow
|
||||
|
Loading…
Reference in New Issue
Block a user