@mirus/tiptap-editor 2.1.5 → 2.1.6

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.
@@ -21969,8 +21969,13 @@ function _w(t, e, n, r) {
21969
21969
  return t.descendants((u, f) => {
21970
21970
  if (u.isText) {
21971
21971
  let p;
21972
- for (; p = s.exec(u.text); )
21973
- c(f + p.index, f + p.index + p[0].length, p[0]);
21972
+ for (; p = s.exec(u.text); ) {
21973
+ const d = i.filter((v) => v.value === p[0]), h = f + p.index;
21974
+ let m = !1;
21975
+ d.forEach((v) => {
21976
+ v.length && v.offset >= 0 && (m = !0, h - 1 === v.offset && c(h, h + p[0].length, p[0]));
21977
+ }), m || c(h, h + p[0].length, p[0]);
21978
+ }
21974
21979
  }
21975
21980
  }), { highlights: a, on: l };
21976
21981
  }
@@ -22281,9 +22286,6 @@ const Z6 = {
22281
22286
  length: t.length
22282
22287
  }));
22283
22288
  },
22284
- getInitialCharacterCount() {
22285
- return this.initialCharacterCount;
22286
- },
22287
22289
  upHandler() {
22288
22290
  this.navigatedOptionIndex = (this.navigatedOptionIndex + this.currentOptions.length - 1) % this.currentOptions.length;
22289
22291
  },
@@ -22326,7 +22328,10 @@ const Z6 = {
22326
22328
  warnings: function(t, e) {
22327
22329
  if (this.editor) {
22328
22330
  const n = this.editor.view.state.selection;
22329
- this.editor.commands.setContent(this.currentValue), this.editor.commands.setTextSelection(n.from, n.to), this.initialCharacterCount = this.currentCharacterCount;
22331
+ this.editor.commands.setTextSelection({
22332
+ from: n.from,
22333
+ to: n.to
22334
+ }), this.initialCharacterCount = this.currentCharacterCount;
22330
22335
  }
22331
22336
  }
22332
22337
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirus/tiptap-editor",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "description": "custom setup for the tiptap editor",
5
5
  "repository": "https://github.com/mirusresearch/tiptap-editor",
6
6
  "bugs": {
@@ -319,9 +319,6 @@ export default {
319
319
  length: err.length,
320
320
  }));
321
321
  },
322
- getInitialCharacterCount() {
323
- return this.initialCharacterCount;
324
- },
325
322
  upHandler() {
326
323
  this.navigatedOptionIndex =
327
324
  (this.navigatedOptionIndex + this.currentOptions.length - 1) %
@@ -385,8 +382,11 @@ export default {
385
382
  if (this.editor) {
386
383
  // preserve selection after updating warnings
387
384
  const oldSelection = this.editor.view.state.selection;
388
- this.editor.commands.setContent(this.currentValue);
389
- this.editor.commands.setTextSelection(oldSelection.from, oldSelection.to);
385
+ // this.editor.commands.setContent(this.currentValue);
386
+ this.editor.commands.setTextSelection({
387
+ from: oldSelection.from,
388
+ to: oldSelection.to,
389
+ });
390
390
 
391
391
  // record length of text that was used to generate the list of warnings
392
392
  this.initialCharacterCount = this.currentCharacterCount;
package/src/warnings.js CHANGED
@@ -64,7 +64,20 @@ function lint(doc, position, prev, getErrorWords) {
64
64
  // Scan text nodes for bad words
65
65
  let m;
66
66
  while ((m = badWordsRegex.exec(node.text))) {
67
- record(pos + m.index, pos + m.index + m[0].length, m[0]);
67
+ const matchingErrorWords = words.filter((word) => word.value === m[0]);
68
+ const indexOfMatchedWord = pos + m.index;
69
+ let errorHasOffsetData = false;
70
+ matchingErrorWords.forEach((word) => {
71
+ if (word.length && word.offset >= 0) {
72
+ errorHasOffsetData = true;
73
+ if (indexOfMatchedWord - 1 === word.offset) {
74
+ record(indexOfMatchedWord, indexOfMatchedWord + m[0].length, m[0]);
75
+ }
76
+ }
77
+ });
78
+ if (!errorHasOffsetData) {
79
+ record(indexOfMatchedWord, indexOfMatchedWord + m[0].length, m[0]);
80
+ }
68
81
  }
69
82
  }
70
83
  });