Allow autoHeight to be set from the editor

This commit is contained in:
Antonio Scandurra
2016-06-30 15:27:47 +02:00
parent 7325381fd6
commit 8cb0fbcc5c
3 changed files with 44 additions and 6 deletions

View File

@@ -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()

View File

@@ -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