dsh-gufa-code 1.3.133 → 1.3.173

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.
@@ -52,6 +52,8 @@ function gufaRestoreDockTarget(node, saved) {
52
52
  }
53
53
  }
54
54
 
55
+ G.findConversationRoot = gufaFindConversationRoot
56
+
55
57
  /**
56
58
  * 把会话根浮到停靠区的位置与尺寸;返回是否成功。
57
59
  *
@@ -63,6 +65,7 @@ function gufaRestoreDockTarget(node, saved) {
63
65
  * 用「测实际位置 → 补偿差值」迭代 2 次把会话对齐到停靠区。
64
66
  */
65
67
  function gufaPlaceDockedConversation(root, host, options) {
68
+ try { root.removeAttribute('data-gufa-hide') } catch { /* ignore */ }
66
69
  const rect = host.getBoundingClientRect()
67
70
  if (!(rect.width >= 80 && rect.height >= 80)) return false
68
71
  const target = { left: Math.round(rect.left), top: Math.round(rect.top), width: Math.round(rect.width), height: Math.round(rect.height) }
@@ -88,10 +91,20 @@ function gufaPlaceDockedConversation(root, host, options) {
88
91
  let floatMode = false
89
92
  try { floatMode = document.documentElement.hasAttribute('data-gufa-float') } catch { floatMode = false }
90
93
  if (floatMode) root.style.background = dockBackground === '' ? 'rgba(13, 15, 19, 0.55)' : `color-mix(in srgb, ${dockBackground} 45%, transparent)`
91
- else if (backdropMode && dockBackground !== '') root.style.background = `color-mix(in srgb, ${dockBackground} 34%, transparent)`
94
+ else if (backdropMode) {
95
+ /* 背景模式下必须半透明:解析不到实色时也用 color-mix + 变量兜底,
96
+ 不能掉进不透明实色分支(之前右侧对话背景变实色就是这个原因)。 */
97
+ root.style.background = dockBackground === ''
98
+ ? 'color-mix(in srgb, var(--gufa-solid-bg, #1a1b1f) 34%, transparent)'
99
+ : `color-mix(in srgb, ${dockBackground} 34%, transparent)`
100
+ }
92
101
  else root.style.background = dockBackground === '' ? 'var(--gufa-solid-bg, #1a1b1f)' : dockBackground
93
102
  root.style.borderLeft = '1px solid var(--dsw-alias-border-l1)'
94
103
  root.style.boxSizing = 'border-box'
104
+ /* 注意:不要给会话根加 will-change/contain——实测会增加每次滚动时的样式/布局成本 */
105
+ try {
106
+ root.style.contain = 'layout paint'
107
+ } catch { /* ignore */ }
95
108
  root.style.setProperty('--dsh-chat-user-width', 'calc(100% - 24px)')
96
109
  root.style.setProperty('--dsh-conversation-column-width', `${target.width}px`)
97
110
  root.setAttribute('data-gufa-dock', '1')
@@ -416,6 +429,68 @@ G.__dock = {
416
429
  restore: gufaRestoreDockTarget,
417
430
  }
418
431
 
432
+ /** 从 DSH 会话里的文件引用按钮提取路径/行号,然后在古法编辑器里打开。 */
433
+ function gufaParseMentionButton(button) {
434
+ if (button === null || button === undefined || typeof button.closest !== 'function') return null
435
+ const className = typeof button.className === 'string' ? button.className : ''
436
+ const dataRef = typeof button.getAttribute === 'function' ? (button.getAttribute('data-ref-chip') ?? '') : ''
437
+ const isMention = className.includes('fileMention') || className.includes('fileLink') || dataRef !== ''
438
+ if (!isMention) return null
439
+ const title = typeof button.getAttribute === 'function' ? (button.getAttribute('title') ?? '').trim() : ''
440
+ const text = String(button.textContent ?? '').replace(/\s+/g, ' ').trim()
441
+ const parseRef = (value) => {
442
+ const source = String(value ?? '').trim()
443
+ if (source === '') return null
444
+ const match = /^(.*?)(?::(\d+)(?:\s*[-,]\s*\d+)*|#L(\d+)(?:-L?\d+)?)$/.exec(source)
445
+ if (match === null) return { path: source, line: 0 }
446
+ return { path: match[1].trim(), line: Number(match[2] ?? match[3]) || 0 }
447
+ }
448
+ const titleLooksPath = /[\\/]/.test(title) || /\.[A-Za-z0-9]{1,8}$/.test(title)
449
+ const fromTitle = titleLooksPath ? parseRef(title) : null
450
+ const fromText = parseRef(text)
451
+ /* 关键:title 通常只有完整路径(无行号),行号在按钮文本 `xxx.js:165` 里;
452
+ 两者要合并,不能 title 命中就忽略文本的行号。 */
453
+ let path = fromTitle !== null && fromTitle.path !== '' ? fromTitle.path : (fromText !== null ? fromText.path : '')
454
+ let line = (fromTitle !== null ? fromTitle.line : 0) || (fromText !== null ? fromText.line : 0)
455
+ if (path === '') return null
456
+ if (dataRef !== '') {
457
+ let dataPath = ''
458
+ let dataLine = 0
459
+ if (dataRef.trim().startsWith('{')) {
460
+ try {
461
+ const parsedData = JSON.parse(dataRef)
462
+ dataPath = typeof parsedData?.path === 'string' ? parsedData.path : ''
463
+ dataLine = Number(parsedData?.line) || 0
464
+ } catch {
465
+ /* ignore */
466
+ }
467
+ }
468
+ if (dataPath !== '') {
469
+ path = dataPath
470
+ if (dataLine > 0) line = dataLine
471
+ }
472
+ }
473
+ return { path: path.replace(/^\.\//, ''), line }
474
+ }
475
+
476
+ async function gufaOpenMention(mention) {
477
+ if (mention === null || mention === undefined || typeof mention.path !== 'string' || mention.path === '') return
478
+ const root = typeof G.projectRoot === 'string' ? G.projectRoot.replace(/\\/g, '/').replace(/\/+$/, '') : ''
479
+ if (root === '') return
480
+ let resolved = null
481
+ try {
482
+ resolved = await G.api('code.resolvePath', { root, path: mention.path })
483
+ } catch {
484
+ return
485
+ }
486
+ if (resolved === null || resolved === undefined || typeof resolved.path !== 'string' || resolved.path === '') return
487
+ try {
488
+ G.bus.emit('editor:open-at', { path: resolved.path, line: Math.max(1, Number(mention.line) || 1), column: 1 })
489
+ } catch {
490
+ /* ignore */
491
+ }
492
+ }
493
+
419
494
  /**
420
495
  * 停靠栏:官方会话本体(浮动) + 顶部工具条(新建会话 / 打开完整对话 / 收起)。
421
496
  * props = { project, activeFile, selection, theme, width, onInsertCode, backdrop, active, sessionTitle, sessions, onOpenSession }
@@ -429,11 +504,56 @@ G.ChatDock = function ChatDock(props) {
429
504
  if (followRef.current === null) followRef.current = gufaCreateChatFollowKeeper()
430
505
  const tickRef = useRef(null)
431
506
  const startedRef = useRef(0)
507
+ const mentionRootRef = useRef(null)
508
+ const mentionHandlerRef = useRef(null)
509
+ const detachMentionRef = useRef(null)
432
510
  const [phase, setPhase] = useState('searching')
433
511
  const [error, setError] = useState('')
434
512
  const active = props.active !== false && props.paused !== true
435
513
 
514
+ const detachMention = useCallback(() => {
515
+ const root = mentionRootRef.current
516
+ const handler = mentionHandlerRef.current
517
+ if (root !== null && handler !== null) {
518
+ try { root.removeEventListener('click', handler, true) } catch { /* ignore */ }
519
+ }
520
+ mentionRootRef.current = null
521
+ mentionHandlerRef.current = null
522
+ }, [])
523
+ detachMentionRef.current = detachMention
524
+
525
+ const ensureMentionHandler = useCallback((root) => {
526
+ if (root === null) {
527
+ detachMention()
528
+ return
529
+ }
530
+ if (mentionRootRef.current === root && mentionHandlerRef.current !== null) return
531
+ detachMention()
532
+ const handler = (event) => {
533
+ try {
534
+ if (event.button !== 0 || event.defaultPrevented === true) return
535
+ const target = event.target instanceof Element ? event.target.closest('button, [data-ref-chip]') : null
536
+ if (target === null) return
537
+ const mention = gufaParseMentionButton(target)
538
+ if (mention === null) return
539
+ event.preventDefault()
540
+ event.stopPropagation()
541
+ void gufaOpenMention(mention)
542
+ } catch {
543
+ /* ignore */
544
+ }
545
+ }
546
+ try {
547
+ root.addEventListener('click', handler, true)
548
+ mentionRootRef.current = root
549
+ mentionHandlerRef.current = handler
550
+ } catch {
551
+ /* ignore */
552
+ }
553
+ }, [detachMention])
554
+
436
555
  const undock = useCallback(() => {
556
+ detachMentionRef.current?.()
437
557
  const current = dockRef.current
438
558
  if (current.root !== null) gufaRestoreDockTarget(current.root, current.saved)
439
559
  dockRef.current = { root: null, saved: null }
@@ -459,6 +579,7 @@ G.ChatDock = function ChatDock(props) {
459
579
  dockRef.current = { root, saved: gufaSnapshotDockTarget(root) }
460
580
  }
461
581
  if (gufaPlaceDockedConversation(root, host, { translucent: props.backdrop === true })) {
582
+ ensureMentionHandler(root)
462
583
  try {
463
584
  const scroller = root.querySelector(GUFA_CONVERSATION_SCROLL_SELECTOR)
464
585
  if (scroller !== null && scroller !== undefined) followRef.current?.attach(scroller)
@@ -467,7 +588,7 @@ G.ChatDock = function ChatDock(props) {
467
588
  }
468
589
  setPhase((previous) => (previous === 'docked' ? previous : 'docked'))
469
590
  }
470
- }, [active, undock, props.backdrop])
591
+ }, [active, undock, props.backdrop, ensureMentionHandler])
471
592
 
472
593
  /* 拖拽分割条时的轻量重定位:只改宿主几何,不 getComputedStyle、不读自身 rect、不 setState。
473
594
  完整 tick 每次都会 getComputedStyle + 最多两次 getBoundingClientRect,按帧跑会把拖拽拖卡。 */
@@ -507,13 +628,30 @@ G.ChatDock = function ChatDock(props) {
507
628
  startedRef.current = Date.now()
508
629
  setPhase((previous) => (previous === 'docked' ? previous : 'searching'))
509
630
  let disposed = false
631
+ /* dock 住之后彻底断开 body MutationObserver:Monaco 滚动会不断增删行 DOM,
632
+ observer 即使不跑 tick,浏览器也要为整棵 body 维护/遍历 mutation record,依然拖慢滚动。
633
+ 发现/替换会话根交给 300ms 轮询(未 dock 时才观察)。 */
634
+ let observer = typeof MutationObserver === 'function' ? new MutationObserver(() => { run() }) : null
635
+ let observing = false
636
+ const setObserving = (next) => {
637
+ if (observer === null || observing === next) return
638
+ observing = next
639
+ try {
640
+ if (next) observer.observe(document.body, { childList: true, subtree: true })
641
+ else observer.disconnect()
642
+ } catch {
643
+ /* ignore */
644
+ }
645
+ }
510
646
  const run = () => {
511
- if (!disposed) tickRef.current?.()
647
+ if (disposed) return
648
+ tickRef.current?.()
649
+ const current = dockRef.current.root
650
+ setObserving(!(current !== null && current.isConnected === true))
512
651
  }
652
+ setObserving(true)
513
653
  run()
514
- const timer = window.setInterval(run, 250)
515
- const observer = typeof MutationObserver === 'function' ? new MutationObserver(run) : null
516
- if (observer !== null) observer.observe(document.body, { childList: true, subtree: true })
654
+ const timer = window.setInterval(run, 300)
517
655
  let resizeObserver = null
518
656
  if (typeof ResizeObserver === 'function') {
519
657
  resizeObserver = new ResizeObserver(run)
@@ -215,7 +215,8 @@ G.useSplitter = function useSplitter(options) {
215
215
  return [size, onMouseDown, setSize]
216
216
  }
217
217
 
218
- /** 主界面组件。props 由 slot 框架注入(useSessions 等标准 hook)。 */
218
+
219
+
219
220
  G.GufaApp = function GufaApp(props) {
220
221
  const t = G.useT()
221
222
  const theme = G.useTheme()