Merge pull request #2996 from thomasjo/editorview-grammarscopes

Add grammar scope to EditorView
This commit is contained in:
Kevin Sawicki
2014-08-25 10:14:46 -07:00
3 changed files with 24 additions and 0 deletions

View File

@@ -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'

View File

@@ -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

View File

@@ -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)