Merge pull request #252 from slap-editor/issue-242

fix(find): closes #242
This commit is contained in:
Dan Kaplun 2015-12-23 20:49:50 -05:00
commit 708f5ba74c

View File

@ -8,6 +8,8 @@ var Slap = require('./Slap');
var BaseFindForm = require('./BaseFindForm');
FindForm._label = " find (/.*/ for regex): ";
FindForm._regExpRegExp = /^\/(.+)\/(\w*)$/i;
FindForm._invalidRegExpMessageRegExp = /^(Invalid regular expression:|Invalid flags supplied to RegExp constructor)/;
function FindForm (opts) {
var self = this;
@ -52,10 +54,17 @@ FindForm.prototype._initHandlers = function () {
self.on('find', lodash.throttle(function (pattern, direction) {
direction = direction || 0;
editor.destroyMarkers({type: 'findMatch'});
var regExpMatch = pattern.match(util.text._regExpRegExp);
pattern = regExpMatch
? new RegExp(regExpMatch[1], regExpMatch[2])
: new RegExp(_.escapeRegExp(pattern), 'img');
try {
var regExpMatch = pattern.match(FindForm._regExpRegExp);
pattern = new RegExp(regExpMatch[1], regExpMatch[2].replace('g', '') + 'g');
} catch (e) {
if (e.message.match(FindForm._invalidRegExpMessageRegExp)) {
header.message(e.message, 'error');
self.resetEditor();
return;
}
pattern = new RegExp(_.escapeRegExp(pattern), 'img');
}
var selectionRange = selection.getRange();
var matches = [];