Skip to content

Commit

Permalink
Make vice a keyboard handler as all the nasty bugs were fixed in ace.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Sep 8, 2011
1 parent aac24ee commit eb30b87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
23 changes: 12 additions & 11 deletions keyboard.js
Expand Up @@ -192,25 +192,26 @@ var states = exports.states = {
]
}

var handler = new StateHandler(states)
var handler = exports.handler = new StateHandler(states)
exports.bindings = function(env) {
var data = {}
return {
setKeyboardHandler: function() {},
getKeyboardHandler: function() { return handler },
handle: function handle(e, hashId, keyOrText, keyCode) {
var action = handler.handleKeyboard(data, hashId, keyOrText, keyCode, e)
if ((!action || !action.command) && hashId === 0 && keyCode === 0)
action = { command: "inserttext", args: { text: keyOrText } }
if (canon && canon.exec(action.command, env, "editor", action.args))
return event.stopEvent(e)
if ((!action || !action.command) && (hashId === 0 || keyCode === 0))
action = canon.findKeyCommand(env, "editor", hashId, keyOrText) || { command: "inserttext", args: { text: keyOrText } }

if (action && canon.exec(action.command || action.name, env, "editor", action.args))
return !event.stopEvent(e)

return false
},
onCommandKey: function onCommandKey(event, hashId, keyCode) {
var keyString = keyUtil.keyCodeToString(keyCode)
this.handle(event, hashId, keyString, keyCode)
onCommandKey: function onCommandKey(event, hashId, keyCode, keyString) {
keyString = keyString || keyUtil.keyCodeToString(keyCode)
return this.handle(event, hashId, keyString, keyCode)
},
onTextInput: function onTextInput(input) {
this.handle({}, 0, input, 0)
return this.handle({}, 0, input, 0)
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions settings.js
Expand Up @@ -10,9 +10,8 @@
// save `env` given on startup and use it in setting change listeners.
var env

var keyboardBindings = require('./keyboard').bindings
var handler = require('./keyboard').handler
var utils = require('./utils')
var defaultKeyboardBindings;

var settings = {
isVimMode: {
Expand All @@ -22,12 +21,11 @@ var settings = {
defaultValue: true,
onChange: function onChange(event) {
if (event.value) {
defaultKeyboardBindings = env.editor.keyBinding
env.editor.keyBinding = keyboardBindings(env);
env.editor.setKeyboardHandler(handler)
utils.normalMode(env)
} else {
env.editor.setKeyboardHandler(null)
utils.insertMode(env)
env.editor.keyBinding = defaultKeyboardBindings;
}
}
}
Expand Down

0 comments on commit eb30b87

Please sign in to comment.