mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Merge pull request #3812 from atom/bo-speedup-scoped-config
Speedup scoped config
This commit is contained in:
commit
b57f5a7afa
@ -51,7 +51,7 @@
|
||||
"reactionary-atom-fork": "^1.0.0",
|
||||
"runas": "1.0.1",
|
||||
"scandal": "1.0.2",
|
||||
"scoped-property-store": "^0.13.1",
|
||||
"scoped-property-store": "^0.13.2",
|
||||
"scrollbar-style": "^1.0.2",
|
||||
"season": "^1.0.2",
|
||||
"semver": "1.1.4",
|
||||
|
@ -441,14 +441,13 @@ class Config
|
||||
# file in the type specified by the configuration schema.
|
||||
get: (scopeDescriptor, keyPath) ->
|
||||
if arguments.length == 1
|
||||
keyPath = scopeDescriptor
|
||||
scopeDescriptor = undefined
|
||||
|
||||
if scopeDescriptor?
|
||||
# cannot assign to keyPath for the sake of v8 optimization
|
||||
globalKeyPath = scopeDescriptor
|
||||
@getRawValue(globalKeyPath)
|
||||
else
|
||||
value = @getRawScopedValue(scopeDescriptor, keyPath)
|
||||
return value if value?
|
||||
|
||||
@getRawValue(keyPath)
|
||||
value ?= @getRawValue(keyPath)
|
||||
value
|
||||
|
||||
# Essential: Sets the value for a configuration setting.
|
||||
#
|
||||
|
@ -52,14 +52,12 @@ class DisplayBuffer extends Model
|
||||
@foldsByMarkerId = {}
|
||||
@decorationsById = {}
|
||||
@decorationsByMarkerId = {}
|
||||
@updateAllScreenLines()
|
||||
@createFoldForMarker(marker) for marker in @buffer.findMarkers(@getFoldMarkerAttributes())
|
||||
@subscribe @tokenizedBuffer.observeGrammar @subscribeToScopedConfigSettings
|
||||
@subscribe @tokenizedBuffer.onDidChange @handleTokenizedBufferChange
|
||||
@subscribe @buffer.onDidUpdateMarkers @handleBufferMarkersUpdated
|
||||
@subscribe @buffer.onDidCreateMarker @handleBufferMarkerCreated
|
||||
|
||||
@updateAllScreenLines()
|
||||
@createFoldForMarker(marker) for marker in @buffer.findMarkers(@getFoldMarkerAttributes())
|
||||
|
||||
subscribeToScopedConfigSettings: =>
|
||||
@scopedConfigSubscriptions?.dispose()
|
||||
@ -67,15 +65,30 @@ class DisplayBuffer extends Model
|
||||
|
||||
scopeDescriptor = @getRootScopeDescriptor()
|
||||
|
||||
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.softWrap', =>
|
||||
oldConfigSettings = @configSettings
|
||||
@configSettings =
|
||||
scrollPastEnd: atom.config.get(scopeDescriptor, 'editor.scrollPastEnd')
|
||||
softWrap: atom.config.get(scopeDescriptor, 'editor.softWrap')
|
||||
softWrapAtPreferredLineLength: atom.config.get(scopeDescriptor, 'editor.softWrapAtPreferredLineLength')
|
||||
preferredLineLength: atom.config.get(scopeDescriptor, 'editor.preferredLineLength')
|
||||
|
||||
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.softWrap', ({newValue}) =>
|
||||
@configSettings.softWrap = newValue
|
||||
@updateWrappedScreenLines()
|
||||
|
||||
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.softWrapAtPreferredLineLength', =>
|
||||
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.softWrapAtPreferredLineLength', ({newValue}) =>
|
||||
@configSettings.softWrapAtPreferredLineLength = newValue
|
||||
@updateWrappedScreenLines() if @isSoftWrapped()
|
||||
|
||||
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.preferredLineLength', =>
|
||||
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.preferredLineLength', ({newValue}) =>
|
||||
@configSettings.preferredLineLength = newValue
|
||||
@updateWrappedScreenLines() if @isSoftWrapped() and atom.config.get(scopeDescriptor, 'editor.softWrapAtPreferredLineLength')
|
||||
|
||||
subscriptions.add atom.config.observe scopeDescriptor, 'editor.scrollPastEnd', (value) =>
|
||||
@configSettings.scrollPastEnd = value
|
||||
|
||||
@updateWrappedScreenLines() if oldConfigSettings? and not _.isEqual(oldConfigSettings, @configSettings)
|
||||
|
||||
serializeParams: ->
|
||||
id: @id
|
||||
softWrapped: @isSoftWrapped()
|
||||
@ -328,7 +341,7 @@ class DisplayBuffer extends Model
|
||||
return 0 unless lineHeight > 0
|
||||
|
||||
scrollHeight = @getLineCount() * lineHeight
|
||||
if @height? and atom.config.get(@getRootScopeDescriptor(), 'editor.scrollPastEnd')
|
||||
if @height? and @configSettings.scrollPastEnd
|
||||
scrollHeight = scrollHeight + @height - (lineHeight * 3)
|
||||
|
||||
scrollHeight
|
||||
@ -429,7 +442,7 @@ class DisplayBuffer extends Model
|
||||
@isSoftWrapped()
|
||||
|
||||
isSoftWrapped: ->
|
||||
@softWrapped ? atom.config.get(@getRootScopeDescriptor(), 'editor.softWrap') ? false
|
||||
@softWrapped ? @configSettings.softWrap ? false
|
||||
|
||||
# Set the number of characters that fit horizontally in the editor.
|
||||
#
|
||||
@ -451,8 +464,8 @@ class DisplayBuffer extends Model
|
||||
@editorWidthInChars
|
||||
|
||||
getSoftWrapColumn: ->
|
||||
if atom.config.get(@getRootScopeDescriptor(), 'editor.softWrapAtPreferredLineLength')
|
||||
Math.min(@getEditorWidthInChars(), atom.config.get(@getRootScopeDescriptor(), 'editor.preferredLineLength'))
|
||||
if @configSettings.softWrapAtPreferredLineLength
|
||||
Math.min(@getEditorWidthInChars(), @configSettings.preferredLineLength)
|
||||
else
|
||||
@getEditorWidthInChars()
|
||||
|
||||
|
@ -82,13 +82,17 @@ class TokenizedBuffer extends Model
|
||||
@grammarScopeDescriptor = [@grammar.scopeName]
|
||||
@currentGrammarScore = score ? grammar.getScore(@buffer.getPath(), @buffer.getText())
|
||||
@subscribe @grammar.onDidUpdate => @retokenizeLines()
|
||||
@retokenizeLines()
|
||||
|
||||
@configSettings = tabLength: atom.config.get(@grammarScopeDescriptor, 'editor.tabLength')
|
||||
|
||||
@grammarTabLengthSubscription?.dispose()
|
||||
@grammarTabLengthSubscription = atom.config.onDidChange @grammarScopeDescriptor, 'editor.tabLength', =>
|
||||
@grammarTabLengthSubscription = atom.config.onDidChange @grammarScopeDescriptor, 'editor.tabLength', ({newValue}) =>
|
||||
@configSettings.tabLength = newValue
|
||||
@retokenizeLines()
|
||||
@subscribe @grammarTabLengthSubscription
|
||||
|
||||
@retokenizeLines()
|
||||
|
||||
@emit 'grammar-changed', grammar
|
||||
@emitter.emit 'did-change-grammar', grammar
|
||||
|
||||
@ -118,7 +122,7 @@ class TokenizedBuffer extends Model
|
||||
@tokenizeInBackground() if @visible
|
||||
|
||||
getTabLength: ->
|
||||
@tabLength ? atom.config.get(@grammarScopeDescriptor, 'editor.tabLength')
|
||||
@tabLength ? @configSettings.tabLength
|
||||
|
||||
setTabLength: (@tabLength) ->
|
||||
@retokenizeLines()
|
||||
|
Loading…
Reference in New Issue
Block a user