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': { 'meta': {
prop: DEFAULT_PROP, prop: DEFAULT_PROP,
replace: [ replace: [
{
substr: '<',
newSubstr: ' tag start '
},
{
substr: '>',
newSubstr: ' tag end '
},
{ {
substr: '</', substr: '</',
newSubstr: ' closing tag ' newSubstr: ' closing tag '
@ -312,6 +304,14 @@ var rules = {
{ {
substr: '/>', substr: '/>',
newSubstr: ' close tag ' newSubstr: ' close tag '
},
{
substr: '<',
newSubstr: ' tag start '
},
{
substr: '>',
newSubstr: ' tag end '
} }
] ]
} }
@ -334,7 +334,8 @@ var expand = function(value, replaceRules) {
var newValue = value; var newValue = value;
for (var i = 0; i < replaceRules.length; i++) { for (var i = 0; i < replaceRules.length; i++) {
var replaceRule = replaceRules[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; 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. * Initialize the theme.
* @param {Object} editor Editor to use. * @param {Object} editor Editor to use.
*/ */
var init = function(editor) { var init = function(editor) {
cvoxAce.editor = editor; onFocus();
lastCursor = editor.selection.getCursor();
/* Construct maps. */ /* Construct maps. */
SHORTCUTS.forEach(function(shortcut) { SHORTCUTS.forEach(function(shortcut) {
keyCodeToShortcutMap[shortcut.keyCode] = shortcut; keyCodeToShortcutMap[shortcut.keyCode] = shortcut;
cmdToShortcutMap[shortcut.cmd] = shortcut; cmdToShortcutMap[shortcut.cmd] = shortcut;
}); });
/* Set up listeners. */ editor.on('focus', onFocus);
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);
/* Assume we start in command mode if vim. */ /* Assume we start in command mode if vim. */
if (isVimMode()) { if (isVimMode()) {
cvox.Api.setKeyEcho(false); cvox.Api.setKeyEcho(false);
} }
initContextMenu(); initContextMenu();
cvoxAce.editor.focus();
}; };
/** /**