Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion to move Vim mode into ace #574

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.dryice.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ project.assumeAllFilesLoaded();
source: [
copy.source.commonjs({
project: cloneProject(project),
require: [ 'ace/keyboard/keybinding/' + keybinding ]
require: [ 'ace/keyboard/' + keybinding ]
})
],
filter: [ copy.filter.moduleDefines, copy.filter.uglifyjs, filterTextPlugin ],
Expand Down
4 changes: 2 additions & 2 deletions demo/kitchen-sink/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ var theme = require("ace/theme/textmate");
var EditSession = require("ace/edit_session").EditSession;
var UndoManager = require("ace/undomanager").UndoManager;

var vim = require("ace/keyboard/keybinding/vim").Vim;
var emacs = require("ace/keyboard/keybinding/emacs").Emacs;
var vim = require("ace/keyboard/vim").handler;
var emacs = require("ace/keyboard/emacs").handler;
var HashHandler = require("ace/keyboard/hash_handler").HashHandler;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

define(function(require, exports, module) {

var StateHandler = require("../state_handler").StateHandler;
var matchCharacterOnly = require("../state_handler").matchCharacterOnly;
var StateHandler = require("./state_handler").StateHandler;
var matchCharacterOnly = require("./state_handler").matchCharacterOnly;

var emacsState = {
start: [
Expand Down Expand Up @@ -144,6 +144,6 @@ var emacsState = {
]
};

exports.Emacs = new StateHandler(emacsState);
exports.handler = new StateHandler(emacsState);

});
11 changes: 10 additions & 1 deletion lib/ace/keyboard/keybinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,28 @@ var KeyBinding = function(editor) {
if (this.$handlers[this.$handlers.length - 1] == keyboardHandler)
return;
this.$data = { };
this.$handlers = keyboardHandler ? [this, keyboardHandler] : [this];
for (var i = 0; i < this.$handlers.length; i++)
this.$handlers[i].detach && this.$handlers[i].detach(this.$editor);

this.$handlers = [this];
if (keyboardHandler) {
this.$handlers.push(keyboardHandler);
keyboardHandler.attach && keyboardHandler.attach(this.$editor);
}
};

this.addKeyboardHandler = function(keyboardHandler) {
this.removeKeyboardHandler(keyboardHandler);
this.$handlers.push(keyboardHandler);
keyboardHandler.attach && keyboardHandler.attach(this.$editor);
};

this.removeKeyboardHandler = function(keyboardHandler) {
var i = this.$handlers.indexOf(keyboardHandler);
if (i == -1)
return false;
this.$handlers.splice(i, 1);
keyboardHandler.detach && keyboardHandler.detach(this.$editor);
return true;
};

Expand Down
137 changes: 0 additions & 137 deletions lib/ace/keyboard/keybinding/vim.js

This file was deleted.

27 changes: 27 additions & 0 deletions lib/ace/keyboard/vim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
define(function(require, exports, module) {

"never use strict";

var commands = require("./vim/commands");
var util = require("./vim/maps/util");

exports.handler = require("./vim/keyboard").handler;

exports.onCursorMove = function(e) {
commands.onCursorMove(e.editor);
exports.onCursorMove.scheduled = false;
};

exports.handler.attach = function(editor) {
editor.on("click", exports.onCursorMove);
if (util.currentMode !== "insert")
commands.coreCommands.stop.exec(editor);
};

exports.handler.detach = function(editor) {
editor.removeListener("click", exports.onCursorMove);
commands.coreCommands.start.exec(editor);
util.currentMode = "normal";
};

});