@progress/kendo-editor-common 1.12.3-develop.7 → 1.12.3-develop.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,16 +4,12 @@ export const findAt = (doc, searchOptions, start, end, exit) => {
4
4
  let exec, text, from, to, childText, nextSibling;
5
5
  const nodes = [];
6
6
  const { matchCase, matchWord, useRegExp } = searchOptions;
7
- let searchText = searchOptions.text;
8
- if (useRegExp && (/^\\$/.test(searchText) || /[^\\]\\$/.test(searchText))) {
9
- // lookbehind doesn't work in Edge -> /((?<!\\)\\)$/.test(searchText)
10
- searchText = searchText.substring(0, searchText.length - 1);
11
- }
7
+ const searchText = searchOptions.text;
12
8
  if (!searchText) {
13
9
  return result;
14
10
  }
15
11
  const flags = matchCase ? 'g' : 'gi';
16
- const regExp = useRegExp ? new RegExp(searchText, flags) : createRegExp(searchText, flags);
12
+ const regExp = useRegExp ? new RegExp(searchText, flags) : new RegExp(escapeRegExp(searchText), flags);
17
13
  doc.nodesBetween(start, end, (node, pos) => {
18
14
  if (exit(result)) {
19
15
  return false;
@@ -37,13 +33,18 @@ export const findAt = (doc, searchOptions, start, end, exit) => {
37
33
  text = nodes.map(t => t.text).join('');
38
34
  exec = regExp.exec(text);
39
35
  while (exec !== null) {
40
- from = nodes[0].start + exec.index;
41
- to = from + exec[0].length;
42
- if (start <= from && end >= to && shouldMatchWord(exec, matchWord)) {
43
- result.push(TextSelection.create(doc, from, to));
36
+ if (exec[0].length > 0) {
37
+ from = nodes[0].start + exec.index;
38
+ to = from + exec[0].length;
39
+ if (start <= from && end >= to && shouldMatchWord(exec, matchWord)) {
40
+ result.push(TextSelection.create(doc, from, to));
41
+ }
42
+ if (exit(result)) {
43
+ break;
44
+ }
44
45
  }
45
- if (exit(result)) {
46
- break;
46
+ else {
47
+ regExp.lastIndex++;
47
48
  }
48
49
  exec = regExp.exec(text);
49
50
  }
@@ -110,10 +111,6 @@ const shouldMatchWord = (exec, matchWord) => {
110
111
  return matchWord(exec);
111
112
  }
112
113
  };
113
- const createRegExp = (inputString, flags) => {
114
- const escaped = inputString
115
- .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
116
- .replace(/-/g, '\\x2d')
117
- .replace(/\s/g, '\\s');
118
- return new RegExp(escaped, flags);
114
+ const escapeRegExp = (text) => {
115
+ return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
119
116
  };
@@ -7,16 +7,12 @@ const findAt = (doc, searchOptions, start, end, exit) => {
7
7
  let exec, text, from, to, childText, nextSibling;
8
8
  const nodes = [];
9
9
  const { matchCase, matchWord, useRegExp } = searchOptions;
10
- let searchText = searchOptions.text;
11
- if (useRegExp && (/^\\$/.test(searchText) || /[^\\]\\$/.test(searchText))) {
12
- // lookbehind doesn't work in Edge -> /((?<!\\)\\)$/.test(searchText)
13
- searchText = searchText.substring(0, searchText.length - 1);
14
- }
10
+ const searchText = searchOptions.text;
15
11
  if (!searchText) {
16
12
  return result;
17
13
  }
18
14
  const flags = matchCase ? 'g' : 'gi';
19
- const regExp = useRegExp ? new RegExp(searchText, flags) : createRegExp(searchText, flags);
15
+ const regExp = useRegExp ? new RegExp(searchText, flags) : new RegExp(escapeRegExp(searchText), flags);
20
16
  doc.nodesBetween(start, end, (node, pos) => {
21
17
  if (exit(result)) {
22
18
  return false;
@@ -40,13 +36,18 @@ const findAt = (doc, searchOptions, start, end, exit) => {
40
36
  text = nodes.map(t => t.text).join('');
41
37
  exec = regExp.exec(text);
42
38
  while (exec !== null) {
43
- from = nodes[0].start + exec.index;
44
- to = from + exec[0].length;
45
- if (start <= from && end >= to && shouldMatchWord(exec, matchWord)) {
46
- result.push(prosemirror_state_1.TextSelection.create(doc, from, to));
39
+ if (exec[0].length > 0) {
40
+ from = nodes[0].start + exec.index;
41
+ to = from + exec[0].length;
42
+ if (start <= from && end >= to && shouldMatchWord(exec, matchWord)) {
43
+ result.push(prosemirror_state_1.TextSelection.create(doc, from, to));
44
+ }
45
+ if (exit(result)) {
46
+ break;
47
+ }
47
48
  }
48
- if (exit(result)) {
49
- break;
49
+ else {
50
+ regExp.lastIndex++;
50
51
  }
51
52
  exec = regExp.exec(text);
52
53
  }
@@ -118,10 +119,6 @@ const shouldMatchWord = (exec, matchWord) => {
118
119
  return matchWord(exec);
119
120
  }
120
121
  };
121
- const createRegExp = (inputString, flags) => {
122
- const escaped = inputString
123
- .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
124
- .replace(/-/g, '\\x2d')
125
- .replace(/\s/g, '\\s');
126
- return new RegExp(escaped, flags);
122
+ const escapeRegExp = (text) => {
123
+ return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
127
124
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@progress/kendo-editor-common",
3
3
  "description": "Kendo UI TypeScript package exporting functions for Editor component",
4
- "version": "1.12.3-develop.7",
4
+ "version": "1.12.3-develop.9",
5
5
  "keywords": [
6
6
  "Kendo UI"
7
7
  ],