dsh-chat-link-actions 0.2.15 → 0.2.17

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.
Files changed (2) hide show
  1. package/client.js +32 -2
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -170,6 +170,20 @@ window.__ModuleLoader__.load({
170
170
  /* ── resolving a file path out of the clicked node ──────────────────── */
171
171
 
172
172
  /** Trim a candidate down to the bare file path a link carries. */
173
+ /** Drop sentence punctuation that followed the path in prose. */
174
+ function trimProsePunctuation(value) {
175
+ var text = value.replace(/[.,;:!?]+$/u, "");
176
+ while (text.length > 1 && (text.charAt(text.length - 1) === ")" || text.charAt(text.length - 1) === "]")) {
177
+ var open = text.charAt(text.length - 1) === ")" ? "(" : "[";
178
+ var close = text.charAt(text.length - 1);
179
+ var opens = text.split(open).length - 1;
180
+ var closes = text.split(close).length - 1;
181
+ if (closes <= opens) break;
182
+ text = text.slice(0, -1);
183
+ }
184
+ return text;
185
+ }
186
+
173
187
  function normalizeCandidate(value) {
174
188
  if (typeof value !== "string") return null;
175
189
  var candidate = value.trim();
@@ -189,6 +203,7 @@ window.__ModuleLoader__.load({
189
203
  }
190
204
  if (/^[A-Za-z]:(?![\\/])/u.test(candidate)) candidate = candidate.slice(0, 2) + "/" + candidate.slice(2);
191
205
  if (!/^(?:[A-Za-z]:[\\/]?|[\\/]{1,2})$/u.test(candidate)) candidate = candidate.replace(/[\\/]+$/u, "");
206
+ candidate = trimProsePunctuation(candidate);
192
207
  return looksAbsolute(candidate) ? candidate : null;
193
208
  }
194
209
 
@@ -248,10 +263,12 @@ window.__ModuleLoader__.load({
248
263
  }
249
264
 
250
265
  /** An absolute path written as plain text inside the clicked element. */
266
+ var proseCandidate = false;
267
+
251
268
  var PATH_IN_TEXT = /(?:^|[\s"'“”「」()()\[\]<>])(@?"?(?:\/|[A-Za-z]:[\\/]|\\\\[^\\\s]+\\|~\/(?!\/))[^\s"'“”「」<>,。;:!?()【】《》]*)/u;
252
269
 
253
270
  /** 路径结尾成立的样子:有扩展名,或以分隔符收尾。 */
254
- var PATH_TAIL = /(?:\.[A-Za-z0-9]{1,8}(?:#L\d+(?:-L?\d+)?(?::\d+)?)?|#L\d+(?::\d+)?|[\\/])$/u;
271
+ var PATH_TAIL = /(?:\.[A-Za-z0-9]{1,8}(?:#L\d+(?:-L?\d+)?(?::\d+)?)?[.,;:!?)\]]*|#L\d+(?:-L?\d+)?(?::\d+)?|[\\/])$/u;
255
272
 
256
273
  /** 一段词像不像同一路径的下一段:不以分隔符或盘符开头,也不带句子标点。 */
257
274
  function continuesPath(word) {
@@ -445,7 +462,10 @@ window.__ModuleLoader__.load({
445
462
  if (fromFiber !== null) return fromFiber;
446
463
  if (point !== null && point !== undefined && point.allowProse !== false) {
447
464
  var fromCaret = pathFromCaret(point.x, point.y);
448
- if (fromCaret !== null) return fromCaret;
465
+ if (fromCaret !== null) {
466
+ proseCandidate = true;
467
+ return fromCaret;
468
+ }
449
469
  }
450
470
  return null;
451
471
  }
@@ -972,13 +992,23 @@ window.__ModuleLoader__.load({
972
992
  }
973
993
  }
974
994
 
995
+ /** Prose needs a real path shape: /help and skill chips must stay native. */
996
+ function looksLikePath(value) {
997
+ var rest = value.replace(/^(?:[A-Za-z]:)?[\\/]+/u, "");
998
+ if (rest === "") return false;
999
+ if (/[\\/]/u.test(rest)) return true;
1000
+ return /\.[A-Za-z0-9]{1,8}$/u.test(rest);
1001
+ }
1002
+
975
1003
  function onContextMenu(event) {
976
1004
  if (!(event.target instanceof Element)) return;
977
1005
  var target = event.target;
978
1006
  try {
979
1007
  var inField = editableField(target);
1008
+ proseCandidate = false;
980
1009
  var path = pathFromNode(target, { x: event.clientX, y: event.clientY, allowProse: !inField });
981
1010
  if (path === null) return;
1011
+ if (proseCandidate && !looksLikePath(path)) return;
982
1012
  openMenu(path, event.clientX, event.clientY, { inField: inField, directory: directoryHint(target) });
983
1013
  event.preventDefault();
984
1014
  event.stopPropagation();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-chat-link-actions",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
4
4
  "description": "Right-click actions on file links in the DSH transcript: quote the path into the composer, or reveal the file in the OS file manager. Menus are drawn in the app's own style, never the system one.",
5
5
  "type": "module",
6
6
  "main": "index.js",