mirror of
https://github.com/atom/atom.git
synced 2026-02-11 23:25:03 -05:00
Allow autoHeight to be set from the editor
This commit is contained in:
@@ -5804,6 +5804,31 @@ describe "TextEditor", ->
|
||||
atom.config.set('editor.scrollPastEnd', true)
|
||||
expect(scrollPastEndSpy).not.toHaveBeenCalled()
|
||||
|
||||
describe "auto height", ->
|
||||
it "returns true by default but can be customized", ->
|
||||
expect(editor.getAutoHeight()).toBe(true)
|
||||
|
||||
editor.setAutoHeight(false)
|
||||
expect(editor.getAutoHeight()).toBe(false)
|
||||
|
||||
editor.setAutoHeight(true)
|
||||
expect(editor.getAutoHeight()).toBe(true)
|
||||
|
||||
it "emits a onDidChangeAutoHeight event when it changes", ->
|
||||
autoHeightSpy = jasmine.createSpy('onDidChangeAutoHeight')
|
||||
editor.onDidChangeAutoHeight(autoHeightSpy)
|
||||
|
||||
editor.setAutoHeight(true)
|
||||
expect(autoHeightSpy).toHaveBeenCalled()
|
||||
|
||||
autoHeightSpy.reset()
|
||||
editor.setAutoHeight(false)
|
||||
expect(autoHeightSpy).toHaveBeenCalled()
|
||||
|
||||
autoHeightSpy.reset()
|
||||
editor.setAutoHeight(false)
|
||||
expect(autoHeightSpy).not.toHaveBeenCalled()
|
||||
|
||||
describe '.get/setPlaceholderText()', ->
|
||||
it 'can be created with placeholderText', ->
|
||||
newEditor = atom.workspace.buildTextEditor(
|
||||
|
||||
@@ -17,7 +17,6 @@ class TextEditorElement extends HTMLElement
|
||||
focusOnAttach: false
|
||||
hasTiledRendering: true
|
||||
logicalDisplayBuffer: true
|
||||
autoHeight: true
|
||||
|
||||
createdCallback: ->
|
||||
# Use globals when the following instance variables aren't set.
|
||||
@@ -39,8 +38,7 @@ class TextEditorElement extends HTMLElement
|
||||
@setAttribute('tabindex', -1)
|
||||
|
||||
initializeContent: (attributes) ->
|
||||
unless @autoHeight
|
||||
@style.height = "100%"
|
||||
@resetAutoHeight()
|
||||
|
||||
if @config.get('editor.useShadowDOM')
|
||||
@useShadowDOM = true
|
||||
@@ -90,7 +88,7 @@ class TextEditorElement extends HTMLElement
|
||||
@subscriptions.add @component.onDidChangeScrollLeft =>
|
||||
@emitter.emit("did-change-scroll-left", arguments...)
|
||||
|
||||
initialize: (model, {@views, @config, @themes, @workspace, @assert, @styles, @grammars}, @autoHeight = true) ->
|
||||
initialize: (model, {@views, @config, @themes, @workspace, @assert, @styles, @grammars}) ->
|
||||
throw new Error("Must pass a views parameter when initializing TextEditorElements") unless @views?
|
||||
throw new Error("Must pass a config parameter when initializing TextEditorElements") unless @config?
|
||||
throw new Error("Must pass a themes parameter when initializing TextEditorElements") unless @themes?
|
||||
@@ -117,6 +115,7 @@ class TextEditorElement extends HTMLElement
|
||||
@model.onDidChangeEncoding => @addEncodingAttribute()
|
||||
@model.onDidDestroy => @unmountComponent()
|
||||
@model.onDidChangeMini (mini) => if mini then @addMiniAttribute() else @removeMiniAttribute()
|
||||
@model.onDidChangeAutoHeight(@resetAutoHeight.bind(this))
|
||||
@model
|
||||
|
||||
getModel: ->
|
||||
@@ -193,6 +192,10 @@ class TextEditorElement extends HTMLElement
|
||||
removeMiniAttribute: ->
|
||||
@removeAttribute("mini")
|
||||
|
||||
resetAutoHeight: ->
|
||||
unless @getModel().getAutoHeight()
|
||||
@style.height = "100%"
|
||||
|
||||
addEncodingAttribute: ->
|
||||
@dataset.encoding = @model.getEncoding()
|
||||
|
||||
|
||||
@@ -141,7 +141,6 @@ class TextEditor extends Model
|
||||
@cursors = []
|
||||
@cursorsByMarkerId = new Map
|
||||
@selections = []
|
||||
@autoHeight ?= true
|
||||
@hasTerminatedPendingState = false
|
||||
|
||||
@showInvisibles ?= true
|
||||
@@ -3395,7 +3394,7 @@ class TextEditor extends Model
|
||||
|
||||
# Get the Element for the editor.
|
||||
getElement: ->
|
||||
@editorElement ?= new TextEditorElement().initialize(this, atom, @autoHeight)
|
||||
@editorElement ?= new TextEditorElement().initialize(this, atom)
|
||||
|
||||
# Essential: Retrieves the greyed out placeholder of a mini editor.
|
||||
#
|
||||
@@ -3470,6 +3469,17 @@ class TextEditor extends Model
|
||||
Grim.deprecate("This is now a view method. Call TextEditorElement::getHeight instead.")
|
||||
@height
|
||||
|
||||
getAutoHeight: ->
|
||||
@autoHeight ? true
|
||||
|
||||
setAutoHeight: (autoHeight) ->
|
||||
if autoHeight isnt @autoHeight
|
||||
@autoHeight = autoHeight
|
||||
@emitter.emit('did-change-auto-height')
|
||||
|
||||
onDidChangeAutoHeight: (callback) ->
|
||||
@emitter.on('did-change-auto-height', callback)
|
||||
|
||||
setWidth: (width, reentrant=false) ->
|
||||
if reentrant
|
||||
oldWidth = @width
|
||||
|
||||
Reference in New Issue
Block a user