mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Move keymap from app to window
This commit is contained in:
@@ -91,7 +91,8 @@ describe "RootView", ->
|
||||
beforeEach ->
|
||||
commandHandler = jasmine.createSpy('commandHandler')
|
||||
rootView.on('foo-command', commandHandler)
|
||||
atom.globalKeymap.bindKeys('*', 'x': 'foo-command')
|
||||
|
||||
window.keymap.bindKeys('*', 'x': 'foo-command')
|
||||
|
||||
describe "when a keydown event is triggered on the RootView (not originating from Ace)", ->
|
||||
it "triggers matching keybindings for that event", ->
|
||||
|
||||
@@ -9,11 +9,11 @@ require 'window'
|
||||
window.showConsole()
|
||||
|
||||
beforeEach ->
|
||||
window.keymap = new GlobalKeymap
|
||||
window.resetTimeouts()
|
||||
|
||||
afterEach ->
|
||||
(new Native).resetMainMenu()
|
||||
atom.globalKeymap.reset()
|
||||
$('#jasmine-content').empty()
|
||||
|
||||
# Use underscore's definition of equality for toEqual assertions
|
||||
@@ -102,7 +102,7 @@ $.fn.resultOfTrigger = (type) ->
|
||||
event.result
|
||||
|
||||
$.fn.enableKeymap = ->
|
||||
@on 'keydown', (e) => atom.globalKeymap.handleKeyEvent(e)
|
||||
@on 'keydown', (e) => window.keymap.handleKeyEvent(e)
|
||||
|
||||
$.fn.attachToDom = ->
|
||||
$('#jasmine-content').append(this)
|
||||
|
||||
@@ -1,26 +1,17 @@
|
||||
EventEmitter = require 'event-emitter'
|
||||
Native = require 'native'
|
||||
GlobalKeymap = require 'global-keymap'
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class App
|
||||
globalKeymap: null
|
||||
native: null
|
||||
windows: null
|
||||
|
||||
constructor: (@loadPath, nativeMethods)->
|
||||
@globalKeymap = new GlobalKeymap
|
||||
@native = new Native(nativeMethods)
|
||||
@windows = []
|
||||
|
||||
bindKeys: (selector, bindings) ->
|
||||
@globalKeymap.bindKeys(selector, bindings)
|
||||
|
||||
bindKey: (selector, pattern, eventName) ->
|
||||
@globalKeymap.bindKey(selector, pattern, eventName)
|
||||
|
||||
open: (url) ->
|
||||
@native.open url
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class Editor extends View
|
||||
@setBuffer(new Buffer)
|
||||
|
||||
bindKeys: ->
|
||||
atom.bindKeys '*:not(.editor *)',
|
||||
window.keymap.bindKeys '*:not(.editor *)',
|
||||
right: 'move-right'
|
||||
left: 'move-left'
|
||||
down: 'move-down'
|
||||
|
||||
@@ -17,7 +17,7 @@ class FileFinder extends View
|
||||
@maxResults = 10
|
||||
|
||||
@populateUrlList()
|
||||
atom.bindKeys ".file-finder",
|
||||
window.keymap.bindKeys ".file-finder",
|
||||
'up': 'move-up'
|
||||
'down': 'move-down'
|
||||
'enter': 'select'
|
||||
|
||||
@@ -7,7 +7,6 @@ Buffer = require 'buffer'
|
||||
Editor = require 'editor'
|
||||
FileFinder = require 'file-finder'
|
||||
Project = require 'project'
|
||||
GlobalKeymap = require 'global-keymap'
|
||||
VimMode = require 'vim-mode'
|
||||
|
||||
module.exports =
|
||||
@@ -18,13 +17,11 @@ class RootView extends View
|
||||
@div id: 'main', outlet: 'main', =>
|
||||
@subview 'editor', new Editor
|
||||
|
||||
globalKeymap: null
|
||||
|
||||
initialize: ({url}) ->
|
||||
@editor.keyEventHandler = atom.globalKeymap
|
||||
@editor.keyEventHandler = window.keymap
|
||||
@createProject(url)
|
||||
|
||||
atom.bindKeys '*'
|
||||
window.keymap.bindKeys '*'
|
||||
'meta-s': 'save'
|
||||
'meta-w': 'close'
|
||||
'meta-t': 'toggle-file-finder'
|
||||
@@ -43,9 +40,6 @@ class RootView extends View
|
||||
@project = new Project(fs.directory(url))
|
||||
@editor.setBuffer(@project.open(url)) if fs.isFile(url)
|
||||
|
||||
bindKeys: (selector, bindings) ->
|
||||
@globalKeymap.bindKeys(selector, bindings)
|
||||
|
||||
addPane: (view) ->
|
||||
pane = $('<div class="pane">')
|
||||
pane.append(view)
|
||||
|
||||
@@ -15,13 +15,13 @@ class VimMode
|
||||
@opStack = []
|
||||
@activateCommandMode()
|
||||
|
||||
atom.bindKeys '.editor', 'escape': 'activate-command-mode'
|
||||
window.keymap.bindKeys '.editor', 'escape': 'activate-command-mode'
|
||||
@editor.on 'activate-command-mode', => @activateCommandMode()
|
||||
|
||||
@setupCommandMode()
|
||||
|
||||
setupCommandMode: ->
|
||||
atom.bindKeys '.command-mode', (e) =>
|
||||
window.keymap.bindKeys '.command-mode', (e) =>
|
||||
if e.keystroke.match /^\d$/
|
||||
return 'command-mode:numeric-prefix'
|
||||
if e.keystroke.match /^.$/
|
||||
@@ -62,7 +62,7 @@ class VimMode
|
||||
for pattern, commandName of bindings
|
||||
prefixedBindings[pattern] = "command-mode:#{commandName}"
|
||||
|
||||
atom.bindKeys ".command-mode", prefixedBindings
|
||||
window.keymap.bindKeys ".command-mode", prefixedBindings
|
||||
|
||||
handleCommands: (commands) ->
|
||||
_.each commands, (fn, commandName) =>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
fs = require 'fs'
|
||||
_ = require 'underscore'
|
||||
$ = require 'jquery'
|
||||
fs = require 'fs'
|
||||
|
||||
GlobalKeymap = require 'global-keymap'
|
||||
RootView = require 'root-view'
|
||||
|
||||
# This a weirdo file. We don't create a Window class, we just add stuff to
|
||||
@@ -11,20 +11,28 @@ RootView = require 'root-view'
|
||||
windowAdditions =
|
||||
rootView: null
|
||||
menuItemActions: null
|
||||
keymap: null
|
||||
|
||||
startup: (url) ->
|
||||
@menuItemActions = {}
|
||||
@rootView = new RootView {url}
|
||||
$('body').append @rootView
|
||||
@attachRootView(url)
|
||||
@registerEventHandlers()
|
||||
@bindMenuItems()
|
||||
$(this).on 'close', => @close()
|
||||
$(window).focus()
|
||||
atom.windowOpened this
|
||||
|
||||
@keymap = new GlobalKeymap()
|
||||
$(document).on 'keydown', (e) -> @keymap.handleKeyEvent(e)
|
||||
|
||||
shutdown: ->
|
||||
@rootView.remove()
|
||||
$(window).unbind('focus')
|
||||
$(window).unbind('blur')
|
||||
atom.windowClosed this
|
||||
|
||||
attachRootView: (url) ->
|
||||
@rootView = new RootView {url}
|
||||
$('body').append @rootView
|
||||
|
||||
requireStylesheet: (path) ->
|
||||
fullPath = require.resolve(path)
|
||||
@@ -40,6 +48,7 @@ windowAdditions =
|
||||
@menuItemActions[path] = {action: action, pattern: pattern}
|
||||
|
||||
registerEventHandlers: ->
|
||||
$(window).on 'close', => @close()
|
||||
$(window).focus => @registerMenuItems()
|
||||
$(window).blur -> atom.native.resetMainMenu()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user