mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
Ensure editors don't scroll or show scrollbars when autoWidth is enabled
This commit is contained in:
@@ -425,6 +425,13 @@ describe "TextEditorPresenter", ->
|
||||
editor.setMini(false)
|
||||
expect(getState(presenter).horizontalScrollbar.visible).toBe true
|
||||
|
||||
it "is false when `editor.autoWidth` is true", ->
|
||||
editor.update({autoWidth: true})
|
||||
presenter = buildPresenter(explicitHeight: 10, contentFrameWidth: 30, verticalScrollbarWidth: 7, baseCharacterWidth: 10)
|
||||
getState(presenter) # trigger a state update to store state in the presenter
|
||||
editor.setText('abcdefghijklm')
|
||||
expect(getState(presenter).horizontalScrollbar.visible).toBe(false)
|
||||
|
||||
describe ".height", ->
|
||||
it "tracks the value of ::horizontalScrollbarHeight", ->
|
||||
presenter = buildPresenter(horizontalScrollbarHeight: 10)
|
||||
@@ -538,6 +545,21 @@ describe "TextEditorPresenter", ->
|
||||
presenter.setScrollLeft(10)
|
||||
expect(getState(presenter).content.scrollLeft).toBe 0
|
||||
|
||||
it "is always 0 when `editor.autoWidth` is true", ->
|
||||
editor.update({autoWidth: true})
|
||||
editor.setText('abcdefghijklm')
|
||||
presenter = buildPresenter(explicitHeight: 10, contentFrameWidth: 30, verticalScrollbarWidth: 15, baseCharacterWidth: 10)
|
||||
getState(presenter) # trigger a state update to store state in the presenter
|
||||
|
||||
editor.setCursorBufferPosition([0, Infinity])
|
||||
editor.insertText('n')
|
||||
expect(getState(presenter).content.scrollLeft).toBe(0)
|
||||
|
||||
editor.setText('abcdefghijklm\nnopqrstuvwxy') # make the vertical scrollbar appear
|
||||
editor.setCursorBufferPosition([1, Infinity])
|
||||
editor.insertText('z')
|
||||
expect(getState(presenter).content.scrollLeft).toBe(0)
|
||||
|
||||
describe ".verticalScrollbar", ->
|
||||
describe ".visible", ->
|
||||
it "is true if the scrollHeight exceeds the computed client height", ->
|
||||
@@ -755,6 +777,39 @@ describe "TextEditorPresenter", ->
|
||||
expect(getState(presenter).hiddenInput.width).toBe 2
|
||||
|
||||
describe ".content", ->
|
||||
describe '.width', ->
|
||||
describe "when `editor.autoWidth` is false (the default)", ->
|
||||
it "equals to the max width between the content frame width and the content width + the vertical scrollbar width", ->
|
||||
editor.setText('abc\ndef\nghi\njkl')
|
||||
presenter = buildPresenter(explicitHeight: 10, contentFrameWidth: 33, verticalScrollbarWidth: 7, baseCharacterWidth: 10)
|
||||
expect(getState(presenter).content.width).toBe(3 * 10 + 7 + 1)
|
||||
presenter.setContentFrameWidth(50)
|
||||
expect(getState(presenter).content.width).toBe(50)
|
||||
presenter.setVerticalScrollbarWidth(27)
|
||||
expect(getState(presenter).content.width).toBe(3 * 10 + 27 + 1)
|
||||
|
||||
describe "when `editor.autoWidth` is true", ->
|
||||
it "equals to the content width + the vertical scrollbar width", ->
|
||||
editor.setText('abc\ndef\nghi\njkl')
|
||||
presenter = buildPresenter(explicitHeight: 10, contentFrameWidth: 300, verticalScrollbarWidth: 7, baseCharacterWidth: 10)
|
||||
expectStateUpdate presenter, -> editor.update({autoWidth: true})
|
||||
expect(getState(presenter).content.width).toBe(3 * 10 + 7 + 1)
|
||||
editor.setText('abcdefghi\n')
|
||||
expect(getState(presenter).content.width).toBe(9 * 10 + 7 + 1)
|
||||
|
||||
it "ignores the vertical scrollbar width when it is unset", ->
|
||||
editor.setText('abcdef\nghijkl')
|
||||
presenter = buildPresenter(explicitHeight: 10, contentFrameWidth: 33, verticalScrollbarWidth: 7, baseCharacterWidth: 10)
|
||||
presenter.setVerticalScrollbarWidth(null)
|
||||
expect(getState(presenter).content.width).toBe(6 * 10 + 1)
|
||||
|
||||
it "ignores the content frame width when it is unset", ->
|
||||
editor.setText('abc\ndef\nghi\njkl')
|
||||
presenter = buildPresenter(explicitHeight: 10, contentFrameWidth: 33, verticalScrollbarWidth: 7, baseCharacterWidth: 10)
|
||||
getState(presenter) # trigger a state update, causing verticalScrollbarWidth to be stored in the presenter
|
||||
presenter.setContentFrameWidth(null)
|
||||
expect(getState(presenter).content.width).toBe(3 * 10 + 7 + 1)
|
||||
|
||||
describe ".maxHeight", ->
|
||||
it "changes based on boundingClientRect", ->
|
||||
presenter = buildPresenter(scrollTop: 0, lineHeight: 10)
|
||||
@@ -2664,39 +2719,6 @@ describe "TextEditorPresenter", ->
|
||||
pixelPosition: {top: 10, left: 0}
|
||||
}
|
||||
|
||||
describe ".width", ->
|
||||
describe "when `editor.autoWidth` is false (the default)", ->
|
||||
it "equals to the max width between the content frame width and the content width + the vertical scrollbar width", ->
|
||||
editor.setText('abc\ndef\nghi\njkl')
|
||||
presenter = buildPresenter(explicitHeight: 10, contentFrameWidth: 33, verticalScrollbarWidth: 7, baseCharacterWidth: 10)
|
||||
expect(getState(presenter).content.width).toBe(3 * 10 + 7 + 1)
|
||||
presenter.setContentFrameWidth(50)
|
||||
expect(getState(presenter).content.width).toBe(50)
|
||||
presenter.setVerticalScrollbarWidth(27)
|
||||
expect(getState(presenter).content.width).toBe(3 * 10 + 27 + 1)
|
||||
|
||||
describe "when `editor.autoWidth` is true", ->
|
||||
it "equals to the content width + the vertical scrollbar width", ->
|
||||
editor.setText('abc\ndef\nghi\njkl')
|
||||
presenter = buildPresenter(explicitHeight: 10, contentFrameWidth: 300, verticalScrollbarWidth: 7, baseCharacterWidth: 10)
|
||||
expectStateUpdate presenter, -> editor.update({autoWidth: true})
|
||||
expect(getState(presenter).content.width).toBe(3 * 10 + 7 + 1)
|
||||
editor.setText('abcdefghi\n')
|
||||
expect(getState(presenter).content.width).toBe(9 * 10 + 7 + 1)
|
||||
|
||||
it "ignores the vertical scrollbar width when it is unset", ->
|
||||
editor.setText('abcdef\nghijkl')
|
||||
presenter = buildPresenter(explicitHeight: 10, contentFrameWidth: 33, verticalScrollbarWidth: 7, baseCharacterWidth: 10)
|
||||
presenter.setVerticalScrollbarWidth(null)
|
||||
expect(getState(presenter).content.width).toBe(6 * 10 + 1)
|
||||
|
||||
it "ignores the content frame width when it is unset", ->
|
||||
editor.setText('abc\ndef\nghi\njkl')
|
||||
presenter = buildPresenter(explicitHeight: 10, contentFrameWidth: 33, verticalScrollbarWidth: 7, baseCharacterWidth: 10)
|
||||
getState(presenter) # trigger a state update, causing verticalScrollbarWidth to be stored in the presenter
|
||||
presenter.setContentFrameWidth(null)
|
||||
expect(getState(presenter).content.width).toBe(3 * 10 + 7 + 1)
|
||||
|
||||
describe ".height", ->
|
||||
it "updates model's rows per page when it changes", ->
|
||||
presenter = buildPresenter(explicitHeight: 50, lineHeightInPixels: 10, horizontalScrollbarHeight: 10)
|
||||
|
||||
@@ -669,6 +669,7 @@ class TextEditorPresenter
|
||||
|
||||
if @contentWidth isnt oldContentWidth
|
||||
@updateScrollbarDimensions()
|
||||
@updateClientWidth()
|
||||
@updateScrollWidth()
|
||||
|
||||
updateClientHeight: ->
|
||||
@@ -685,7 +686,11 @@ class TextEditorPresenter
|
||||
updateClientWidth: ->
|
||||
return unless @contentFrameWidth? and @verticalScrollbarWidth?
|
||||
|
||||
clientWidth = @contentFrameWidth - @verticalScrollbarWidth
|
||||
if @model.getAutoWidth()
|
||||
clientWidth = @contentWidth
|
||||
else
|
||||
clientWidth = @contentFrameWidth - @verticalScrollbarWidth
|
||||
|
||||
@model.setWidth(clientWidth, true) unless @editorWidthInChars
|
||||
|
||||
unless @clientWidth is clientWidth
|
||||
@@ -727,29 +732,30 @@ class TextEditorPresenter
|
||||
return unless @measuredVerticalScrollbarWidth? and @measuredHorizontalScrollbarHeight?
|
||||
return unless @contentWidth? and @contentHeight?
|
||||
|
||||
clientWidthWithVerticalScrollbar = @contentFrameWidth
|
||||
if @model.getAutoWidth()
|
||||
clientWidthWithVerticalScrollbar = @contentWidth + @measuredVerticalScrollbarWidth
|
||||
else
|
||||
clientWidthWithVerticalScrollbar = @contentFrameWidth
|
||||
clientWidthWithoutVerticalScrollbar = clientWidthWithVerticalScrollbar - @measuredVerticalScrollbarWidth
|
||||
clientHeightWithHorizontalScrollbar = @height
|
||||
clientHeightWithoutHorizontalScrollbar = clientHeightWithHorizontalScrollbar - @measuredHorizontalScrollbarHeight
|
||||
|
||||
horizontalScrollbarVisible =
|
||||
not @model.isMini() and
|
||||
(@contentWidth > clientWidthWithVerticalScrollbar or
|
||||
@contentWidth > clientWidthWithoutVerticalScrollbar and @contentHeight > clientHeightWithHorizontalScrollbar)
|
||||
|
||||
verticalScrollbarVisible =
|
||||
not @model.isMini() and
|
||||
(@contentHeight > clientHeightWithHorizontalScrollbar or
|
||||
@contentHeight > clientHeightWithoutHorizontalScrollbar and @contentWidth > clientWidthWithVerticalScrollbar)
|
||||
|
||||
horizontalScrollbarHeight =
|
||||
if horizontalScrollbarVisible
|
||||
if horizontalScrollbarVisible and not @model.isMini()
|
||||
@measuredHorizontalScrollbarHeight
|
||||
else
|
||||
0
|
||||
|
||||
verticalScrollbarWidth =
|
||||
if verticalScrollbarVisible
|
||||
if verticalScrollbarVisible and not @model.isMini()
|
||||
@measuredVerticalScrollbarWidth
|
||||
else
|
||||
0
|
||||
|
||||
Reference in New Issue
Block a user