Add autoWidth to TextEditor

This commit is contained in:
Antonio Scandurra
2016-08-17 14:10:11 +02:00
parent f376316d60
commit 683bf37907
3 changed files with 20 additions and 1 deletions

View File

@@ -5516,6 +5516,14 @@ describe "TextEditor", ->
editor.update({autoHeight: true})
expect(editor.getAutoHeight()).toBe(true)
describe "auto width", ->
it "returns false by default but can be customized", ->
expect(editor.getAutoWidth()).toBe(false)
editor.update({autoWidth: true})
expect(editor.getAutoWidth()).toBe(true)
editor.update({autoWidth: false})
expect(editor.getAutoWidth()).toBe(false)
describe '.get/setPlaceholderText()', ->
it 'can be created with placeholderText', ->
newEditor = atom.workspace.buildTextEditor(

View File

@@ -896,6 +896,9 @@ class TextEditorPresenter
@updateScrollHeight()
@updateEndRow()
didChangeAutoWidth: ->
@emitDidUpdateState()
setContentFrameWidth: (contentFrameWidth) ->
if @contentFrameWidth isnt contentFrameWidth or @editorWidthInChars?
oldContentFrameWidth = @contentFrameWidth

View File

@@ -127,7 +127,7 @@ class TextEditor extends Model
@softTabs, @firstVisibleScreenRow, @firstVisibleScreenColumn, initialLine, initialColumn, tabLength,
@softWrapped, @decorationManager, @selectionsMarkerLayer, @buffer, suppressCursorCreation,
@mini, @placeholderText, lineNumberGutterVisible, @largeFileMode, @clipboard,
@assert, grammar, @showInvisibles, @autoHeight, @scrollPastEnd, @editorWidthInChars,
@assert, grammar, @showInvisibles, @autoHeight, @autoWidth, @scrollPastEnd, @editorWidthInChars,
@tokenizedBuffer, @displayLayer, @invisibles, @showIndentGuide, @softWrapHangingIndentLength,
@softWrapped, @softWrapAtPreferredLineLength, @preferredLineLength
} = params
@@ -144,6 +144,7 @@ class TextEditor extends Model
@selections = []
@hasTerminatedPendingState = false
@autoWidth ?= false
@autoHeight ?= true
@mini ?= false
@scrollPastEnd ?= true
@@ -320,6 +321,10 @@ class TextEditor extends Model
@autoHeight = value
@editorElement?.didChangeAutoHeight()
when 'autoWidth'
if value isnt @autoWidth
@autoWidth = value
@presenter?.didChangeAutoWidth()
else
throw new TypeError("Invalid TextEditor parameter: '#{param}'")
@@ -3552,6 +3557,9 @@ class TextEditor extends Model
Grim.deprecate("This is now a view method. Call TextEditorElement::getWidth instead.")
@width
getAutoWidth: ->
@autoWidth
# Experimental: Scroll the editor such that the given screen row is at the
# top of the visible area.
setFirstVisibleScreenRow: (screenRow, fromView) ->