mirror of
https://github.com/slap-editor/slap.git
synced 2024-09-11 04:45:47 +03:00
Merge pull request #252 from slap-editor/issue-242
fix(find): closes #242
This commit is contained in:
commit
708f5ba74c
@ -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