@atlaskit/editor-plugin-autocomplete 4.1.2 → 4.1.3

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-autocomplete
2
2
 
3
+ ## 4.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`5cd6c10a9394f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5cd6c10a9394f) -
8
+ Fix autocomplete context extraction when inline formatting inserts leaf nodes before the cursor,
9
+ preventing misaligned ghost-text suggestions that can surface as stray spaces.
10
+
3
11
  ## 4.1.2
4
12
 
5
13
  ### Patch Changes
@@ -38,6 +38,7 @@ var MAX_INGESTED_CONTEXT_TEXTS = 50;
38
38
  // non-comment editors (where parentCommentContent never arrives) don't refetch
39
39
  // on every word boundary for the plugin's lifetime.
40
40
  var MAX_CONTEXT_REFRESH_ATTEMPTS = 5;
41
+ var INLINE_LEAF_TEXT = ' ';
41
42
 
42
43
  // eslint-disable-next-line require-unicode-regexp
43
44
  var TRAILING_NON_BOUNDARY_TOKEN_REGEX = /([^\s.,;:!?]*)$/;
@@ -63,7 +64,8 @@ var getTextBeforeCursor = function getTextBeforeCursor(state) {
63
64
  var maxChars = 200;
64
65
  var blockNode = $from.parent;
65
66
  var offsetInBlock = $from.parentOffset;
66
- var blockText = blockNode.textContent.slice(0, offsetInBlock);
67
+ // PM offsets count inline leaf nodes; textContent indices do not.
68
+ var blockText = blockNode.textBetween(0, offsetInBlock, undefined, INLINE_LEAF_TEXT);
67
69
  if (blockText.length >= maxChars) {
68
70
  return blockText.slice(-maxChars);
69
71
  }
@@ -76,7 +78,7 @@ var getTextBeforeCursor = function getTextBeforeCursor(state) {
76
78
  var indexInParent = $from.index(depth);
77
79
  for (var i = indexInParent - 1; i >= 0 && fullText.length < maxChars; i--) {
78
80
  var sibling = parentNode.child(i);
79
- var siblingText = sibling.textContent;
81
+ var siblingText = sibling.textBetween(0, sibling.content.size, '\n', INLINE_LEAF_TEXT);
80
82
  fullText = siblingText + '\n' + fullText;
81
83
  }
82
84
  depth--;
@@ -24,6 +24,7 @@ const MAX_INGESTED_CONTEXT_TEXTS = 50;
24
24
  // non-comment editors (where parentCommentContent never arrives) don't refetch
25
25
  // on every word boundary for the plugin's lifetime.
26
26
  const MAX_CONTEXT_REFRESH_ATTEMPTS = 5;
27
+ const INLINE_LEAF_TEXT = ' ';
27
28
 
28
29
  // eslint-disable-next-line require-unicode-regexp
29
30
  const TRAILING_NON_BOUNDARY_TOKEN_REGEX = /([^\s.,;:!?]*)$/;
@@ -47,7 +48,8 @@ const getTextBeforeCursor = state => {
47
48
  const maxChars = 200;
48
49
  const blockNode = $from.parent;
49
50
  const offsetInBlock = $from.parentOffset;
50
- const blockText = blockNode.textContent.slice(0, offsetInBlock);
51
+ // PM offsets count inline leaf nodes; textContent indices do not.
52
+ const blockText = blockNode.textBetween(0, offsetInBlock, undefined, INLINE_LEAF_TEXT);
51
53
  if (blockText.length >= maxChars) {
52
54
  return blockText.slice(-maxChars);
53
55
  }
@@ -60,7 +62,7 @@ const getTextBeforeCursor = state => {
60
62
  const indexInParent = $from.index(depth);
61
63
  for (let i = indexInParent - 1; i >= 0 && fullText.length < maxChars; i--) {
62
64
  const sibling = parentNode.child(i);
63
- const siblingText = sibling.textContent;
65
+ const siblingText = sibling.textBetween(0, sibling.content.size, '\n', INLINE_LEAF_TEXT);
64
66
  fullText = siblingText + '\n' + fullText;
65
67
  }
66
68
  depth--;
@@ -31,6 +31,7 @@ var MAX_INGESTED_CONTEXT_TEXTS = 50;
31
31
  // non-comment editors (where parentCommentContent never arrives) don't refetch
32
32
  // on every word boundary for the plugin's lifetime.
33
33
  var MAX_CONTEXT_REFRESH_ATTEMPTS = 5;
34
+ var INLINE_LEAF_TEXT = ' ';
34
35
 
35
36
  // eslint-disable-next-line require-unicode-regexp
36
37
  var TRAILING_NON_BOUNDARY_TOKEN_REGEX = /([^\s.,;:!?]*)$/;
@@ -56,7 +57,8 @@ var getTextBeforeCursor = function getTextBeforeCursor(state) {
56
57
  var maxChars = 200;
57
58
  var blockNode = $from.parent;
58
59
  var offsetInBlock = $from.parentOffset;
59
- var blockText = blockNode.textContent.slice(0, offsetInBlock);
60
+ // PM offsets count inline leaf nodes; textContent indices do not.
61
+ var blockText = blockNode.textBetween(0, offsetInBlock, undefined, INLINE_LEAF_TEXT);
60
62
  if (blockText.length >= maxChars) {
61
63
  return blockText.slice(-maxChars);
62
64
  }
@@ -69,7 +71,7 @@ var getTextBeforeCursor = function getTextBeforeCursor(state) {
69
71
  var indexInParent = $from.index(depth);
70
72
  for (var i = indexInParent - 1; i >= 0 && fullText.length < maxChars; i--) {
71
73
  var sibling = parentNode.child(i);
72
- var siblingText = sibling.textContent;
74
+ var siblingText = sibling.textBetween(0, sibling.content.size, '\n', INLINE_LEAF_TEXT);
73
75
  fullText = siblingText + '\n' + fullText;
74
76
  }
75
77
  depth--;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-autocomplete",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
4
4
  "description": "Client-side text autocomplete plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -47,6 +47,7 @@ const MAX_INGESTED_CONTEXT_TEXTS = 50;
47
47
  // non-comment editors (where parentCommentContent never arrives) don't refetch
48
48
  // on every word boundary for the plugin's lifetime.
49
49
  const MAX_CONTEXT_REFRESH_ATTEMPTS = 5;
50
+ const INLINE_LEAF_TEXT = ' ';
50
51
 
51
52
  // eslint-disable-next-line require-unicode-regexp
52
53
  const TRAILING_NON_BOUNDARY_TOKEN_REGEX = /([^\s.,;:!?]*)$/;
@@ -82,7 +83,8 @@ const getTextBeforeCursor = (state: EditorState): string => {
82
83
 
83
84
  const blockNode = $from.parent;
84
85
  const offsetInBlock = $from.parentOffset;
85
- const blockText = blockNode.textContent.slice(0, offsetInBlock);
86
+ // PM offsets count inline leaf nodes; textContent indices do not.
87
+ const blockText = blockNode.textBetween(0, offsetInBlock, undefined, INLINE_LEAF_TEXT);
86
88
 
87
89
  if (blockText.length >= maxChars) {
88
90
  return blockText.slice(-maxChars);
@@ -99,7 +101,7 @@ const getTextBeforeCursor = (state: EditorState): string => {
99
101
 
100
102
  for (let i = indexInParent - 1; i >= 0 && fullText.length < maxChars; i--) {
101
103
  const sibling = parentNode.child(i);
102
- const siblingText = sibling.textContent;
104
+ const siblingText = sibling.textBetween(0, sibling.content.size, '\n', INLINE_LEAF_TEXT);
103
105
  fullText = siblingText + '\n' + fullText;
104
106
  }
105
107
  depth--;