From 683bf3790730862e087c68c63a6d2cf7126b047d Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 17 Aug 2016 14:10:11 +0200 Subject: [PATCH] Add `autoWidth` to TextEditor --- spec/text-editor-spec.coffee | 8 ++++++++ src/text-editor-presenter.coffee | 3 +++ src/text-editor.coffee | 10 +++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 605b6cf05..e352a6c88 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -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( diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index cb2d70a67..4f5ca74ef 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -896,6 +896,9 @@ class TextEditorPresenter @updateScrollHeight() @updateEndRow() + didChangeAutoWidth: -> + @emitDidUpdateState() + setContentFrameWidth: (contentFrameWidth) -> if @contentFrameWidth isnt contentFrameWidth or @editorWidthInChars? oldContentFrameWidth = @contentFrameWidth diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 354ac8069..420bee702 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -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) ->