mirror of
https://github.com/atom/atom.git
synced 2026-02-08 13:45:09 -05:00
Introduce TextEditor.prototype.update
This allows TextEditor objects to be used within an etch component easily.
This commit is contained in:
@@ -94,6 +94,23 @@ describe "TextEditor", ->
|
||||
editor2.unfoldBufferRow(4)
|
||||
expect(editor2.isFoldedAtBufferRow(4)).not.toBe editor.isFoldedAtBufferRow(4)
|
||||
|
||||
describe ".update()", ->
|
||||
it "updates the editor with the supplied config parameters", ->
|
||||
atom.config.set('editor.showInvisibles', true)
|
||||
editor.onDidChange(changeSpy = jasmine.createSpy('onDidChange'))
|
||||
editor.update({
|
||||
tabLength: 6, softTabs: false, softWrapped: true, editorWidthInChars: 40,
|
||||
ignoreInvisibles: true, mini: false, lineNumberGutterVisible: false
|
||||
})
|
||||
expect(changeSpy.callCount).toBe(1)
|
||||
expect(editor.getTabLength()).toBe(6)
|
||||
expect(editor.getSoftTabs()).toBe(false)
|
||||
expect(editor.isSoftWrapped()).toBe(true)
|
||||
expect(editor.getEditorWidthInChars()).toBe(40)
|
||||
expect(editor.getInvisibles()).toEqual({})
|
||||
expect(editor.isMini()).toBe(false)
|
||||
expect(editor.isLineNumberGutterVisible()).toBe(false)
|
||||
|
||||
describe "config defaults", ->
|
||||
it "uses the `editor.tabLength`, `editor.softWrap`, and `editor.softTabs`, and `core.fileEncoding` config values", ->
|
||||
editor1 = null
|
||||
|
||||
@@ -187,6 +187,49 @@ class TextEditor extends Model
|
||||
if grammar?
|
||||
@setGrammar(grammar)
|
||||
|
||||
update: (params) ->
|
||||
{
|
||||
softTabs, tabLength, softWrapped, mini, placeholderText, lineNumberGutterVisible,
|
||||
showInvisibles, ignoreInvisibles, editorWidthInChars
|
||||
} = params
|
||||
|
||||
resetDisplayLayer = false
|
||||
|
||||
if softTabs? and softTabs isnt @softTabs
|
||||
@setSoftTabs(softTabs)
|
||||
|
||||
if tabLength? and tabLength isnt @tabLength
|
||||
@setTabLength(tabLength, false)
|
||||
resetDisplayLayer = true
|
||||
|
||||
if softWrapped? and softWrapped isnt @softWrapped
|
||||
@setSoftWrapped(softWrapped, false)
|
||||
resetDisplayLayer = true
|
||||
|
||||
if mini? and mini isnt @mini
|
||||
@setMini(mini)
|
||||
|
||||
if placeholderText? and placeholderText isnt @placeholderText
|
||||
@setPlaceholderText(placeholderText)
|
||||
|
||||
if lineNumberGutterVisible? and lineNumberGutterVisible isnt @lineNumberGutterVisible
|
||||
@setLineNumberGutterVisible(lineNumberGutterVisible)
|
||||
|
||||
if showInvisibles? and showInvisibles isnt @showInvisibles
|
||||
@showInvisibles = showInvisibles
|
||||
resetDisplayLayer = true
|
||||
|
||||
if ignoreInvisibles? and ignoreInvisibles isnt @ignoreInvisibles
|
||||
@setIgnoreInvisibles(ignoreInvisibles, false)
|
||||
resetDisplayLayer = true
|
||||
|
||||
if editorWidthInChars? and editorWidthInChars isnt @editorWidthInChars
|
||||
@setEditorWidthInChars(editorWidthInChars, false)
|
||||
resetDisplayLayer = true
|
||||
|
||||
if resetDisplayLayer
|
||||
@resetDisplayLayer()
|
||||
|
||||
serialize: ->
|
||||
tokenizedBufferState = @tokenizedBuffer.serialize()
|
||||
|
||||
@@ -652,12 +695,12 @@ class TextEditor extends Model
|
||||
#
|
||||
# * `editorWidthInChars` A {Number} representing the width of the
|
||||
# {TextEditorElement} in characters.
|
||||
setEditorWidthInChars: (editorWidthInChars) ->
|
||||
setEditorWidthInChars: (editorWidthInChars, resetDisplayLayer=true) ->
|
||||
if editorWidthInChars > 0
|
||||
previousWidthInChars = @editorWidthInChars
|
||||
@editorWidthInChars = editorWidthInChars
|
||||
if editorWidthInChars isnt previousWidthInChars and @isSoftWrapped()
|
||||
@resetDisplayLayer()
|
||||
@resetDisplayLayer() if resetDisplayLayer
|
||||
|
||||
# Returns the editor width in characters.
|
||||
getEditorWidthInChars: ->
|
||||
@@ -2721,18 +2764,18 @@ class TextEditor extends Model
|
||||
#
|
||||
# * `tabLength` {Number} length of a single tab. Setting to `null` will
|
||||
# fallback to using the `editor.tabLength` config setting
|
||||
setTabLength: (tabLength) ->
|
||||
setTabLength: (tabLength, resetDisplayLayer=true) ->
|
||||
return if tabLength is @tabLength
|
||||
|
||||
@tabLength = tabLength
|
||||
@tokenizedBuffer.setTabLength(@tabLength)
|
||||
@resetDisplayLayer()
|
||||
@resetDisplayLayer() if resetDisplayLayer
|
||||
|
||||
setIgnoreInvisibles: (ignoreInvisibles) ->
|
||||
setIgnoreInvisibles: (ignoreInvisibles, resetDisplayLayer=true) ->
|
||||
return if ignoreInvisibles is @ignoreInvisibles
|
||||
|
||||
@ignoreInvisibles = ignoreInvisibles
|
||||
@resetDisplayLayer()
|
||||
@resetDisplayLayer() if resetDisplayLayer
|
||||
|
||||
getInvisibles: ->
|
||||
scopeDescriptor = @getRootScopeDescriptor()
|
||||
@@ -2805,10 +2848,10 @@ class TextEditor extends Model
|
||||
# * `softWrapped` A {Boolean}
|
||||
#
|
||||
# Returns a {Boolean}.
|
||||
setSoftWrapped: (softWrapped) ->
|
||||
setSoftWrapped: (softWrapped, resetDisplayLayer=true) ->
|
||||
if softWrapped isnt @softWrapped
|
||||
@softWrapped = softWrapped
|
||||
@resetDisplayLayer()
|
||||
@resetDisplayLayer() if resetDisplayLayer
|
||||
softWrapped = @isSoftWrapped()
|
||||
@emitter.emit 'did-change-soft-wrapped', softWrapped
|
||||
softWrapped
|
||||
|
||||
Reference in New Issue
Block a user