mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Move GlobalKeymap instance to App. Clear bindings between examples.
This commit is contained in:
@@ -10,6 +10,7 @@ describe "RootView", ->
|
||||
beforeEach ->
|
||||
url = require.resolve 'fixtures/dir/a'
|
||||
rootView = RootView.build {url}
|
||||
rootView.enableKeymap()
|
||||
project = rootView.project
|
||||
|
||||
describe "initialize", ->
|
||||
@@ -86,7 +87,7 @@ describe "RootView", ->
|
||||
beforeEach ->
|
||||
commandHandler = jasmine.createSpy('commandHandler')
|
||||
rootView.on('foo-command', commandHandler)
|
||||
rootView.globalKeymap.bindKeys('*', 'x': 'foo-command')
|
||||
atom.globalKeymap.bindKeys('*', 'x': 'foo-command')
|
||||
|
||||
describe "when a key is typed in the editor that has a binding in the keymap", ->
|
||||
it "triggers the key binding's command as an event and stops its propagation", ->
|
||||
@@ -99,6 +100,7 @@ describe "RootView", ->
|
||||
describe "when a keydown event is triggered on the RootView (not originating from Ace)", ->
|
||||
it "triggers matching keybindings for that event", ->
|
||||
event = keydownEvent 'x', target: rootView[0]
|
||||
|
||||
rootView.trigger(event)
|
||||
expect(commandHandler).toHaveBeenCalled()
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ BindingSet = require 'binding-set'
|
||||
|
||||
afterEach ->
|
||||
(new Native).resetMainMenu()
|
||||
atom.globalKeymap.reset()
|
||||
|
||||
window.atom = new (require 'app')
|
||||
|
||||
@@ -25,3 +26,7 @@ $.fn.resultOfTrigger = (type) ->
|
||||
event = $.Event(type)
|
||||
this.trigger(event)
|
||||
event.result
|
||||
|
||||
$.fn.enableKeymap = ->
|
||||
@on 'keydown', (e) => atom.globalKeymap.handleKeyEvent(e)
|
||||
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
Native = require 'native'
|
||||
GlobalKeymap = require 'global-keymap'
|
||||
$ = require 'jquery'
|
||||
|
||||
module.exports =
|
||||
class App
|
||||
globalKeymap: null
|
||||
native: null
|
||||
|
||||
constructor: ->
|
||||
@native = new Native
|
||||
@globalKeymap = new GlobalKeymap
|
||||
$(document).on 'keydown', (e) => console.log e; @globalKeymap.handleKeyEvent(e)
|
||||
|
||||
bindKeys: (selector, bindings) ->
|
||||
window.rootView.bindKeys(selector, bindings)
|
||||
@globalKeymap.bindKeys(selector, bindings)
|
||||
|
||||
open: (url) ->
|
||||
OSX.NSApp.open url
|
||||
|
||||
@@ -23,3 +23,6 @@ class GlobalKeymap
|
||||
return true
|
||||
currentNode = currentNode.parent()
|
||||
false
|
||||
|
||||
reset: ->
|
||||
@BindingSets = []
|
||||
|
||||
@@ -22,22 +22,16 @@ class RootView extends Template
|
||||
globalKeymap: null
|
||||
|
||||
initialize: ({url}) ->
|
||||
@createGlobalKeymap()
|
||||
@editor.keyEventHandler = atom.globalKeymap
|
||||
@createProject(url)
|
||||
|
||||
@bindKeys '*'
|
||||
atom.bindKeys '*'
|
||||
'meta-s': 'save'
|
||||
'meta-w': 'close'
|
||||
'meta-t': 'toggle-file-finder'
|
||||
|
||||
@on 'toggle-file-finder', => @toggleFileFinder()
|
||||
|
||||
|
||||
createGlobalKeymap: ->
|
||||
@globalKeymap = new GlobalKeymap
|
||||
@on 'keydown', (e) => @globalKeymap.handleKeyEvent(e)
|
||||
@editor.keyEventHandler = @globalKeymap
|
||||
|
||||
createProject: (url) ->
|
||||
if url
|
||||
@project = new Project(fs.directory(url))
|
||||
|
||||
Reference in New Issue
Block a user