mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Merge pull request #2996 from thomasjo/editorview-grammarscopes
Add grammar scope to EditorView
This commit is contained in:
@@ -3045,3 +3045,12 @@ describe "EditorView", ->
|
||||
editorView.pixelPositionForScreenPosition([0, editor.getTabLength()])
|
||||
editorView.pixelPositionForScreenPosition([0, editor.getTabLength() + 1])
|
||||
expect(editorView.measureToColumn.callCount).toBe 0
|
||||
|
||||
describe "grammar data attributes", ->
|
||||
it "adds and updates the grammar data attribute based on the current grammar", ->
|
||||
editorView.attachToDom()
|
||||
editor.setGrammar(atom.syntax.grammarForScopeName('text.plain'))
|
||||
expect(editorView.attr('data-grammar')).toBe 'text plain'
|
||||
|
||||
editor.setGrammar(atom.syntax.grammarForScopeName('source.js'))
|
||||
expect(editorView.attr('data-grammar')).toBe 'source js'
|
||||
|
||||
@@ -560,6 +560,7 @@ class EditorView extends View
|
||||
@trigger 'editor:path-changed'
|
||||
|
||||
@subscribe @editor, "grammar-changed", =>
|
||||
@addGrammarScopeAttribute()
|
||||
@trigger 'editor:grammar-changed'
|
||||
|
||||
@subscribe @editor, 'selection-added', (selection) =>
|
||||
@@ -581,10 +582,15 @@ class EditorView extends View
|
||||
|
||||
@trigger 'editor:path-changed'
|
||||
@resetDisplay()
|
||||
@addGrammarScopeAttribute()
|
||||
|
||||
if @attached and @editor.buffer.isInConflict()
|
||||
_.defer => @showBufferConflictAlert(@editor) # Display after editor has a chance to display
|
||||
|
||||
addGrammarScopeAttribute: ->
|
||||
grammarScope = @editor.getGrammar()?.scopeName?.replace(/\./g, ' ')
|
||||
@attr('data-grammar', grammarScope)
|
||||
|
||||
getModel: ->
|
||||
@editor
|
||||
|
||||
|
||||
@@ -81,8 +81,17 @@ class ReactEditorView extends View
|
||||
@attached = true
|
||||
@component.pollDOM()
|
||||
@focus() if @focusOnAttach
|
||||
|
||||
@addGrammarScopeAttribute()
|
||||
@subscribe @editor, 'grammar-changed', =>
|
||||
@addGrammarScopeAttribute()
|
||||
|
||||
@trigger 'editor:attached', [this]
|
||||
|
||||
addGrammarScopeAttribute: ->
|
||||
grammarScope = @editor.getGrammar()?.scopeName?.replace(/\./g, ' ')
|
||||
@attr('data-grammar', grammarScope)
|
||||
|
||||
scrollTop: (scrollTop) ->
|
||||
if scrollTop?
|
||||
@editor.setScrollTop(scrollTop)
|
||||
|
||||
Reference in New Issue
Block a user