mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Display editor's grammar name in status bar
Clicking on the grammar name displays the list of available grammars that can be switched to.
This commit is contained in:
@@ -2137,6 +2137,21 @@ describe "Editor", ->
|
||||
expect(editor.updateDisplay).not.toHaveBeenCalled()
|
||||
expect(editor.getGrammar().name).toBe 'JavaScript'
|
||||
|
||||
it "emits an editor:grammar-changed event when updated", ->
|
||||
rootView.open(path)
|
||||
editor = rootView.getActiveEditor()
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
editor.on('editor:grammar-changed', eventHandler)
|
||||
editor.reloadGrammar()
|
||||
|
||||
expect(eventHandler).not.toHaveBeenCalled()
|
||||
|
||||
jsGrammar = syntax.grammarForFilePath('/tmp/js.js')
|
||||
rootView.project.addGrammarOverrideForPath(path, jsGrammar)
|
||||
editor.reloadGrammar()
|
||||
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
|
||||
describe ".replaceSelectedText()", ->
|
||||
it "doesn't call the replace function when the selection is empty", ->
|
||||
replaced = false
|
||||
|
||||
@@ -1128,6 +1128,7 @@ class Editor extends View
|
||||
if grammarChanged
|
||||
@clearRenderedLines()
|
||||
@updateDisplay()
|
||||
@trigger 'editor:grammar-changed'
|
||||
grammarChanged
|
||||
|
||||
bindToKeyedEvent: (key, event, callback) ->
|
||||
|
||||
@@ -176,3 +176,21 @@ describe "StatusBar", ->
|
||||
it "displays the diff stat for new files", ->
|
||||
rootView.open(newPath)
|
||||
expect(statusBar.gitStatusIcon).toHaveText('+1')
|
||||
|
||||
describe "grammar label", ->
|
||||
it "displays the name of the current grammar", ->
|
||||
expect(statusBar.find('.grammar-name').text()).toBe 'JavaScript'
|
||||
|
||||
describe "when the editor's grammar changes", ->
|
||||
it "displays the new grammar of the editor", ->
|
||||
textGrammar = _.find syntax.grammars, (grammar) -> grammar.name is 'Plain Text'
|
||||
rootView.project.addGrammarOverrideForPath(editor.getPath(), textGrammar)
|
||||
editor.reloadGrammar()
|
||||
expect(statusBar.find('.grammar-name').text()).toBe textGrammar.name
|
||||
|
||||
describe "when clicked", ->
|
||||
it "toggles the editor:select-grammar event", ->
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
editor.on 'editor:select-grammar', eventHandler
|
||||
statusBar.find('.grammar-name').click()
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
|
||||
@@ -25,7 +25,7 @@ class StatusBar extends View
|
||||
@span class: 'current-path', outlet: 'currentPath'
|
||||
@span class: 'buffer-modified', outlet: 'bufferModified'
|
||||
@span class: 'cursor-position', outlet: 'cursorPosition'
|
||||
|
||||
@span class: 'grammar-name', outlet: 'grammarName'
|
||||
|
||||
initialize: (@rootView, @editor) ->
|
||||
@updatePathText()
|
||||
@@ -36,6 +36,8 @@ class StatusBar extends View
|
||||
@updateCursorPositionText()
|
||||
@subscribe @editor, 'cursor:moved', => @updateCursorPositionText()
|
||||
@subscribe $(window), 'focus', => @updateStatusBar()
|
||||
@subscribe @grammarName, 'click', => @editor.trigger 'editor:select-grammar'
|
||||
@subscribe @editor, 'editor:grammar-changed', => @updateGrammarText()
|
||||
|
||||
@subscribeToBuffer()
|
||||
|
||||
@@ -48,10 +50,14 @@ class StatusBar extends View
|
||||
@updateStatusBar()
|
||||
|
||||
updateStatusBar: ->
|
||||
@updateGrammarText()
|
||||
@updateBranchText()
|
||||
@updateBufferHasModifiedText(@buffer.isModified())
|
||||
@updateStatusText()
|
||||
|
||||
updateGrammarText: ->
|
||||
@grammarName.text(@editor.getGrammar().name)
|
||||
|
||||
updateBufferHasModifiedText: (differsFromDisk)->
|
||||
if differsFromDisk
|
||||
@bufferModified.text('*') unless @isModified
|
||||
|
||||
@@ -6,12 +6,19 @@
|
||||
line-height: 14px;
|
||||
color: #969696;
|
||||
position: relative;
|
||||
-webkit-user-select: none;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.status-bar .cursor-position {
|
||||
.status-bar .cursor-position,
|
||||
.status-bar .grammar-name {
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.status-bar .grammar-name {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.status-bar .git-branch {
|
||||
float: right;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user