Support for multiple editors, reorder rules, and use replace all.

This commit is contained in:
Peter Xiao 2013-08-14 13:57:38 -07:00
commit 5708ef899e

View file

@ -297,14 +297,6 @@ var rules = {
'meta': {
prop: DEFAULT_PROP,
replace: [
{
substr: '<',
newSubstr: ' tag start '
},
{
substr: '>',
newSubstr: ' tag end '
},
{
substr: '</',
newSubstr: ' closing tag '
@ -312,6 +304,14 @@ var rules = {
{
substr: '/>',
newSubstr: ' close tag '
},
{
substr: '<',
newSubstr: ' tag start '
},
{
substr: '>',
newSubstr: ' tag end '
}
]
}
@ -334,7 +334,8 @@ var expand = function(value, replaceRules) {
var newValue = value;
for (var i = 0; i < replaceRules.length; i++) {
var replaceRule = replaceRules[i];
newValue = newValue.replace(replaceRule.substr, replaceRule.newSubstr);
var regexp = new RegExp(replaceRule.substr, 'g');
newValue = newValue.replace(regexp, replaceRule.newSubstr);
}
return newValue;
};
@ -865,34 +866,43 @@ var SHORTCUTS = [
}
];
/**
* Event handler for focus events.
*/
var onFocus = function() {
cvoxAce.editor = editor;
/* Set up listeners. */
editor.getSession().selection.on('changeCursor', onCursorChange);
editor.getSession().on('change', onChange);
editor.getSession().on('changeAnnotation', onAnnotationChange);
editor.on('changeStatus', onChangeStatus);
editor.on('findSearchBox', onFindSearchbox);
editor.container.addEventListener('keydown', onKeyDown);
lastCursor = editor.selection.getCursor();
};
/**
* Initialize the theme.
* @param {Object} editor Editor to use.
*/
var init = function(editor) {
cvoxAce.editor = editor;
lastCursor = editor.selection.getCursor();
onFocus();
/* Construct maps. */
SHORTCUTS.forEach(function(shortcut) {
keyCodeToShortcutMap[shortcut.keyCode] = shortcut;
cmdToShortcutMap[shortcut.cmd] = shortcut;
});
/* Set up listeners. */
cvoxAce.editor.getSession().selection.on('changeCursor', onCursorChange);
cvoxAce.editor.getSession().on('change', onChange);
cvoxAce.editor.getSession().on('changeAnnotation', onAnnotationChange);
cvoxAce.editor.on('changeStatus', onChangeStatus);
cvoxAce.editor.on('findSearchBox', onFindSearchbox);
editor.container.addEventListener('keydown', onKeyDown);
editor.on('focus', onFocus);
/* Assume we start in command mode if vim. */
if (isVimMode()) {
cvox.Api.setKeyEcho(false);
}
initContextMenu();
cvoxAce.editor.focus();
};
/**