@adecore/editor 0.44.2 → 0.44.4

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.
@@ -800,8 +800,10 @@ export class InputController {
800
800
  : selections.map((selection) => model.slice(Math.min(selection.anchor, selection.head), Math.max(selection.anchor, selection.head))).join('\n');
801
801
  event.clipboardData?.setData('text/plain', text);
802
802
  lineClip = empty ? text : null;
803
- emit(this.copyListeners, { text, wholeLines: empty, cut });
804
- if (!cut || this.blockedByReadOnly()) {
803
+ const blocked = cut && this.blockedByReadOnly();
804
+ // A cut that a read-only editor refuses took nothing out, so it is told as the copy it came to.
805
+ emit(this.copyListeners, { text, wholeLines: empty, cut: cut && !blocked });
806
+ if (!cut || blocked) {
805
807
  return;
806
808
  }
807
809
  this.historyGroup++;
package/dist/outline.js CHANGED
@@ -91,6 +91,16 @@ function toBlock(entry, document) {
91
91
  ...(entry.kind === undefined ? {} : { kind: entry.kind })
92
92
  };
93
93
  }
94
+ /* Where the name stands in a line as a whole identifier, so `on` is not found inside `function`; -1 where it does not. */
95
+ function identifierIndex(text, name) {
96
+ const isPart = (character) => character !== undefined && /[\w$]/.test(character);
97
+ for (let at = text.indexOf(name); at >= 0; at = text.indexOf(name, at + 1)) {
98
+ if (!isPart(text[at - 1]) && !isPart(text[at + name.length])) {
99
+ return at;
100
+ }
101
+ }
102
+ return -1;
103
+ }
94
104
  /*
95
105
  * The blocks the editor knows the document by: its own reading of the structure, or the host's
96
106
  * where it has better, such as a language server's symbols. Ends are offsets, so an edit keeps
@@ -147,7 +157,7 @@ export class Outline {
147
157
  return [];
148
158
  }
149
159
  const header = document.getLine(document.positionAt(entry.from).line);
150
- return [header.start + Math.max(0, header.text.indexOf(entry.name))];
160
+ return [header.start + Math.max(0, identifierIndex(header.text, entry.name))];
151
161
  });
152
162
  }
153
163
  /* Outermost first. Of two blocks that start on one line, only the larger one. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/editor",
3
- "version": "0.44.2",
3
+ "version": "0.44.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -54,7 +54,7 @@
54
54
  "test": "bun test --conditions=source"
55
55
  },
56
56
  "dependencies": {
57
- "@adecore/editor-core": "0.44.2",
57
+ "@adecore/editor-core": "0.44.4",
58
58
  "linkedom": "^0.18.14",
59
59
  "shiki": "^4.5.0"
60
60
  },
package/src/controller.ts CHANGED
@@ -1034,9 +1034,12 @@ export class InputController {
1034
1034
 
1035
1035
  event.clipboardData?.setData('text/plain', text);
1036
1036
  lineClip = empty ? text : null;
1037
- emit(this.copyListeners, { text, wholeLines: empty, cut });
1037
+ const blocked = cut && this.blockedByReadOnly();
1038
1038
 
1039
- if (!cut || this.blockedByReadOnly()) {
1039
+ // A cut that a read-only editor refuses took nothing out, so it is told as the copy it came to.
1040
+ emit(this.copyListeners, { text, wholeLines: empty, cut: cut && !blocked });
1041
+
1042
+ if (!cut || blocked) {
1040
1043
  return;
1041
1044
  }
1042
1045
 
package/src/outline.ts CHANGED
@@ -151,6 +151,19 @@ function toBlock(entry: OutlineEntry, document: OutlineDocument): OutlineBlock {
151
151
  };
152
152
  }
153
153
 
154
+ /* Where the name stands in a line as a whole identifier, so `on` is not found inside `function`; -1 where it does not. */
155
+ function identifierIndex(text: string, name: string): number {
156
+ const isPart = (character: string | undefined): boolean => character !== undefined && /[\w$]/.test(character);
157
+
158
+ for (let at = text.indexOf(name); at >= 0; at = text.indexOf(name, at + 1)) {
159
+ if (!isPart(text[at - 1]) && !isPart(text[at + name.length])) {
160
+ return at;
161
+ }
162
+ }
163
+
164
+ return -1;
165
+ }
166
+
154
167
  /*
155
168
  * The blocks the editor knows the document by: its own reading of the structure, or the host's
156
169
  * where it has better, such as a language server's symbols. Ends are offsets, so an edit keeps
@@ -224,7 +237,7 @@ export class Outline {
224
237
 
225
238
  const header = document.getLine(document.positionAt(entry.from).line);
226
239
 
227
- return [header.start + Math.max(0, header.text.indexOf(entry.name))];
240
+ return [header.start + Math.max(0, identifierIndex(header.text, entry.name))];
228
241
  });
229
242
  }
230
243