dsh-chat-link-actions 0.2.16 → 0.2.18

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 (3) hide show
  1. package/README.md +1 -1
  2. package/client.js +19 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  ## 认哪些链接
16
16
 
17
- 右键不是只认一种写法,常见渲染都走同一条解析:`href` / `src` 里的 `?path=`(图片、附件卡片)、`data-path` 之类的绝对路径属性、`title` 里的路径(宿主自绘的文件链接、文件夹链接)、以及直接写在正文里的绝对路径(光标落在路径上才算),包括代码块里的 `file.cjs#L12`、`#L12-L20` 这类带行号的写法(行号不进路径)。只显示「图标 + 文件名」、DOM 里没有路径的芯片(图片链接、Markdown 图片)也能认:路径从渲染它的组件属性里取。Windows 的 `C:\...`、`C:/...`、UNC 共享路径、含空格与中文的路径同样能认;正文里带空格的路径整条引用,芯片写作 `@"…"`。网页链接、`~` 和 `./` 开头的相对路径不当成本机文件。目录链接插入后是文件夹芯片(名字以 `/` 收尾),即使链接末尾没有斜杠。
17
+ 右键不是只认一种写法,常见渲染都走同一条解析:`href` / `src` 里的 `?path=`(图片、附件卡片)、`data-path` 之类的绝对路径属性、`title` 里的路径(宿主自绘的文件链接、文件夹链接)、以及直接写在正文里的绝对路径(光标落在路径上才算),包括代码块里的 `file.cjs#L12`、`#L12-L20` 这类带行号的写法(行号不进路径)。只显示「图标 + 文件名」、DOM 里没有路径的芯片(图片链接、Markdown 图片)也能认:路径从渲染它的组件属性里取。Windows 的 `C:\...`、`C:/...`、UNC 共享路径、含空格与中文的路径同样能认;正文里带空格的路径整条引用,芯片写作 `@"…"`。网页链接、`~` 和 `./` 开头的相对路径不当成本机文件;正文里单独一个词(`/help` 这类斜杠命令)不弹菜单,带扩展名或带层级的路径才算。目录链接插入后是文件夹芯片(名字以 `/` 收尾),即使链接末尾没有斜杠。
18
18
 
19
19
  ## 装
20
20
 
package/client.js CHANGED
@@ -263,6 +263,8 @@ window.__ModuleLoader__.load({
263
263
  }
264
264
 
265
265
  /** An absolute path written as plain text inside the clicked element. */
266
+ var proseCandidate = false;
267
+
266
268
  var PATH_IN_TEXT = /(?:^|[\s"'“”「」()()\[\]<>])(@?"?(?:\/|[A-Za-z]:[\\/]|\\\\[^\\\s]+\\|~\/(?!\/))[^\s"'“”「」<>,。;:!?()【】《》]*)/u;
267
269
 
268
270
  /** 路径结尾成立的样子:有扩展名,或以分隔符收尾。 */
@@ -289,6 +291,8 @@ window.__ModuleLoader__.load({
289
291
  if (word === null) break;
290
292
  remaining = remaining.slice(space[0].length + word[0].length);
291
293
  if (!continuesPath(word[0])) break;
294
+ /* 中文句子在路径后继续说话时,不要把后面的词吞进路径。 */
295
+ if (/^[\u3400-\u9fff]+$/u.test(word[0]) && !/\.[A-Za-z0-9]{1,8}$/u.test(word[0])) break;
292
296
  var joined = best + " " + word[0];
293
297
  if (PATH_TAIL.test(joined)) best = joined;
294
298
  else if (!PATH_TAIL.test(best)) {
@@ -460,7 +464,10 @@ window.__ModuleLoader__.load({
460
464
  if (fromFiber !== null) return fromFiber;
461
465
  if (point !== null && point !== undefined && point.allowProse !== false) {
462
466
  var fromCaret = pathFromCaret(point.x, point.y);
463
- if (fromCaret !== null) return fromCaret;
467
+ if (fromCaret !== null) {
468
+ proseCandidate = true;
469
+ return fromCaret;
470
+ }
464
471
  }
465
472
  return null;
466
473
  }
@@ -987,13 +994,24 @@ window.__ModuleLoader__.load({
987
994
  }
988
995
  }
989
996
 
997
+ /** Prose needs a real path shape: /help and skill chips must stay native. */
998
+ function looksLikePath(value) {
999
+ if (/^[A-Za-z]:[\\/]/u.test(value)) return true;
1000
+ var rest = value.replace(/^(?:[A-Za-z]:)?[\\/]+/u, "");
1001
+ if (rest === "") return false;
1002
+ if (/[\\/]/u.test(rest)) return true;
1003
+ return /\.[A-Za-z0-9]{1,8}$/u.test(rest);
1004
+ }
1005
+
990
1006
  function onContextMenu(event) {
991
1007
  if (!(event.target instanceof Element)) return;
992
1008
  var target = event.target;
993
1009
  try {
994
1010
  var inField = editableField(target);
1011
+ proseCandidate = false;
995
1012
  var path = pathFromNode(target, { x: event.clientX, y: event.clientY, allowProse: !inField });
996
1013
  if (path === null) return;
1014
+ if (proseCandidate && !looksLikePath(path)) return;
997
1015
  openMenu(path, event.clientX, event.clientY, { inField: inField, directory: directoryHint(target) });
998
1016
  event.preventDefault();
999
1017
  event.stopPropagation();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-chat-link-actions",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
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",