mirror of
https://github.com/slap-editor/slap.git
synced 2024-10-26 05:03:00 +03:00
fix(find): closes #242
This commit is contained in:
parent
c38b9c4355
commit
e8fdc3a49e
@ -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 = [];
|
||||
|
Loading…
Reference in New Issue
Block a user