mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Replace Keymap subclass with keymap-extensions
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
fs = require 'fs-plus'
|
||||
path = require 'path'
|
||||
temp = require 'temp'
|
||||
Keymap = require '../src/keymap'
|
||||
Keymap = require 'atom-keymap'
|
||||
require '../src/keymap-extensions'
|
||||
{$, $$, WorkspaceView} = require 'atom'
|
||||
|
||||
describe "Keymap", ->
|
||||
@@ -12,7 +13,10 @@ describe "Keymap", ->
|
||||
|
||||
beforeEach ->
|
||||
configDirPath = temp.mkdirSync('atom')
|
||||
keymap = new Keymap({configDirPath, resourcePath})
|
||||
keymap = new Keymap
|
||||
keymap.configDirPath = configDirPath
|
||||
keymap.resourcePath = resourcePath
|
||||
|
||||
fragment = $ """
|
||||
<div class="command-mode">
|
||||
<div class="child-node">
|
||||
@@ -386,7 +390,9 @@ describe "Keymap", ->
|
||||
|
||||
beforeEach ->
|
||||
resourcePath = temp.mkdirSync('atom')
|
||||
customKeymap = new Keymap({configDirPath, resourcePath})
|
||||
customKeymap = new Keymap
|
||||
customKeymap.configDirPath = configDirPath
|
||||
customKeymap.resourcePath = resourcePath
|
||||
|
||||
afterEach ->
|
||||
customKeymap.destroy()
|
||||
|
||||
@@ -6,8 +6,9 @@ require '../vendor/jasmine-jquery'
|
||||
path = require 'path'
|
||||
_ = require 'underscore-plus'
|
||||
fs = require 'fs-plus'
|
||||
Keymap = require 'atom-keymap'
|
||||
{$, WorkspaceView} = require 'atom'
|
||||
Keymap = require '../src/keymap'
|
||||
require '../src/keymap-extensions'
|
||||
Config = require '../src/config'
|
||||
{Point} = require 'text-buffer'
|
||||
Project = require '../src/project'
|
||||
|
||||
@@ -138,7 +138,8 @@ class Atom extends Model
|
||||
@loadTime = null
|
||||
|
||||
Config = require './config'
|
||||
Keymap = require './keymap'
|
||||
Keymap = require 'atom-keymap'
|
||||
require './keymap-extensions'
|
||||
PackageManager = require './package-manager'
|
||||
Clipboard = require './clipboard'
|
||||
Syntax = require './syntax'
|
||||
@@ -149,7 +150,9 @@ class Atom extends Model
|
||||
configDirPath = @getConfigDirPath()
|
||||
|
||||
@config = new Config({configDirPath, resourcePath})
|
||||
@keymap = new Keymap({configDirPath, resourcePath})
|
||||
@keymap = new Keymap
|
||||
@keymap.configDirPath = configDirPath
|
||||
@keymap.resourcePath = resourcePath
|
||||
@packages = new PackageManager({devMode, configDirPath, resourcePath})
|
||||
@themes = new ThemeManager({packageManager: @packages, configDirPath, resourcePath})
|
||||
@contextMenu = new ContextMenuManager(devMode)
|
||||
|
||||
19
src/keymap-extensions.coffee
Normal file
19
src/keymap-extensions.coffee
Normal file
@@ -0,0 +1,19 @@
|
||||
fs = require 'fs-plus'
|
||||
path = require 'path'
|
||||
Keymap = require 'atom-keymap'
|
||||
season = require 'season'
|
||||
|
||||
Keymap::loadBundledKeymaps = ->
|
||||
@loadKeyBindings(path.join(@resourcePath, 'keymaps'))
|
||||
@emit('bundled-keymaps-loaded')
|
||||
|
||||
Keymap::getUserKeymapPath = ->
|
||||
if userKeymapPath = season.resolve(path.join(@configDirPath, 'keymap'))
|
||||
userKeymapPath
|
||||
else
|
||||
path.join(@configDirPath, 'keymap.cson')
|
||||
|
||||
Keymap::loadUserKeymap = ->
|
||||
userKeymapPath = @getUserKeymapPath()
|
||||
if fs.isFileSync(userKeymapPath)
|
||||
@loadKeyBindings(userKeymapPath, watch: true, suppressErrors: true)
|
||||
@@ -1,41 +0,0 @@
|
||||
path = require 'path'
|
||||
AtomKeymap = require 'atom-keymap'
|
||||
season = require 'season'
|
||||
fs = require 'fs-plus'
|
||||
|
||||
# Public: Associates keybindings with commands.
|
||||
#
|
||||
# An instance of this class is always available as the `atom.keymap` global.
|
||||
#
|
||||
# Keymaps are defined in a CSON/JSON format. A typical keymap looks something
|
||||
# like this:
|
||||
#
|
||||
# ```cson
|
||||
# 'body':
|
||||
# 'ctrl-l': 'package:do-something'
|
||||
# '.someClass':
|
||||
# 'enter': 'package:confirm'
|
||||
# ```
|
||||
#
|
||||
# As a key, you define the DOM element you want to work on, using CSS notation.
|
||||
# For that key, you define one or more key:value pairs, associating keystrokes
|
||||
# with a command to execute.
|
||||
module.exports =
|
||||
class Keymap extends AtomKeymap
|
||||
constructor: ({@resourcePath, @configDirPath}) ->
|
||||
super
|
||||
|
||||
loadBundledKeymaps: ->
|
||||
@loadKeyBindings(path.join(@resourcePath, 'keymaps'))
|
||||
@emit('bundled-keymaps-loaded')
|
||||
|
||||
getUserKeymapPath: ->
|
||||
if userKeymapPath = season.resolve(path.join(@configDirPath, 'keymap'))
|
||||
userKeymapPath
|
||||
else
|
||||
path.join(@configDirPath, 'keymap.cson')
|
||||
|
||||
loadUserKeymap: ->
|
||||
userKeymapPath = @getUserKeymapPath()
|
||||
if fs.isFileSync(userKeymapPath)
|
||||
@loadKeyBindings(userKeymapPath, watch: true, suppressErrors: true)
|
||||
Reference in New Issue
Block a user