dsh-quote-annotate-pro 0.2.8 → 0.2.9

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
@@ -2,6 +2,13 @@
2
2
 
3
3
  本项目的所有重要变更都记在这里。版本号遵循 [SemVer](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## 0.2.9 — 编辑框定位再修:排除"贴文档原点"的退化矩形
6
+
7
+ - 0.2.8 只拦了"尺寸为 0"的矩形;实测选区被打断后 `getBoundingClientRect()` 会返回**贴文档原点、但高度非 0** 的退化矩形,仍会算出 `left≈12 / top≈8`(窗口左上角)
8
+ - 现在取值优先级为:**当前还活着的选区** → 存下来的矩形(需通过 `plausibleRect()`:有限值、有尺寸、**不在原点附近**、不越出视口)→ **视口底部居中**
9
+ - 新增诊断 `editor:anchor`(只记来源与矩形,不记内容),便于下次一眼定位
10
+ - 文本与模型侧行为不变
11
+
5
12
  ## 0.2.8 — 修复"批注编辑框跑到窗口左上角 / 引用不了"
6
13
 
7
14
  - **现象**:选中文字点「批注」后,编辑框出现在窗口左上角(压住侧边栏),看起来像引用功能坏了
package/lib/client.js CHANGED
@@ -683,7 +683,11 @@ window.__ModuleLoader__.load({
683
683
  anchorKey: sel.anchorKey,
684
684
  turn: sel.turn,
685
685
  kind: sel.kind,
686
- }, safeRect(sel.rect))
686
+ }, anchorRect(sel.rect))
687
+ try {
688
+ const r = anchorRect(sel.rect)
689
+ report('editor:anchor', { src: r.__dshq === 'fallback' ? 'fallback' : (liveSelectionRect() ? 'live' : 'stored'), rect: [Math.round(r.left), Math.round(r.top), Math.round(r.right - r.left), Math.round(r.bottom - r.top)] })
690
+ } catch (e) { /* ignore */ }
687
691
  finish()
688
692
  }
689
693
  return React.createElement('div', { className: 'dshq-toolbar', style: { left, top } },
@@ -705,28 +709,46 @@ window.__ModuleLoader__.load({
705
709
 
706
710
  // ============ 组件三:悬浮批注编辑框(评论输入框元素永久驻留,复用时输入法上下文不重建) ============
707
711
  /**
708
- * 选区矩形兜底。矩形失效(节点被装饰/重渲染替换后 getBoundingClientRect 会全 0)时,
709
- * 直接用它会算出 left=12 / top=8 —— 编辑框就跑到窗口左上角(用户反馈的现象)。
710
- * 处理:无效 → 用当前选区重算 → 仍无效 → 退回视口底部居中。
712
+ * 选区矩形兜底。矩形失效(节点被装饰/重渲染替换后 getBoundingClientRect 会返回"文档原点附近"的退化矩形)
713
+ * 时,直接用它会算出 left≈12 / top≈8 —— 编辑框就跑到窗口左上角(用户反馈的现象)。
714
+ * 取值优先级:**当前还活着的选区** → 存下来的矩形(且看着正常)→ 视口底部居中。
711
715
  */
712
- function safeRect(rect) {
713
- const ok = (r) => !!(r
714
- && Number.isFinite(r.left) && Number.isFinite(r.top)
715
- && Number.isFinite(r.right) && Number.isFinite(r.bottom)
716
- && ((r.right - r.left) > 0 || (r.bottom - r.top) > 0))
717
- if (ok(rect)) return rect
716
+ function liveSelectionRect() {
718
717
  try {
719
718
  const s = typeof window !== 'undefined' ? window.getSelection() : null
720
- if (s && s.rangeCount > 0) {
721
- const r = s.getRangeAt(0).getBoundingClientRect()
722
- if (ok(r)) return r
723
- }
724
- } catch (e) { /* ignore */ }
719
+ if (!s || s.rangeCount === 0 || s.isCollapsed) return null
720
+ const r = s.getRangeAt(0).getBoundingClientRect()
721
+ return plausibleRect(r) ? r : null
722
+ } catch (e) { return null }
723
+ }
724
+ /** 排除"贴文档原点"的退化矩形:那是选区失效后的典型产物 */
725
+ function plausibleRect(r) {
726
+ if (!r) return false
727
+ if (!(Number.isFinite(r.left) && Number.isFinite(r.top) && Number.isFinite(r.right) && Number.isFinite(r.bottom))) return false
728
+ const w = r.right - r.left
729
+ const h = r.bottom - r.top
730
+ if (!(w > 0 || h > 0)) return false
731
+ if (r.left < 24 && r.top < 24) return false // 原点附近 → 视为失效
732
+ const vw = typeof window !== 'undefined' ? window.innerWidth : 1024
733
+ const vh = typeof window !== 'undefined' ? window.innerHeight : 768
734
+ if (r.left > vw || r.top > vh) return false
735
+ return true
736
+ }
737
+ function bottomCenterRect() {
725
738
  const vw = typeof window !== 'undefined' ? window.innerWidth : 1024
726
739
  const vh = typeof window !== 'undefined' ? window.innerHeight : 768
727
740
  const left = Math.max(12, Math.round(vw / 2 - 140))
728
741
  const top = Math.max(12, Math.round(vh - 200))
729
- return { left, right: left + 280, top, bottom: top + 24, width: 280, height: 24 }
742
+ return { left, right: left + 280, top, bottom: top + 24, width: 280, height: 24, __dshq: 'fallback' }
743
+ }
744
+ function anchorRect(stored) {
745
+ const live = liveSelectionRect()
746
+ if (live) return live
747
+ if (plausibleRect(stored)) return stored
748
+ return bottomCenterRect()
749
+ }
750
+ function safeRect(rect) {
751
+ return anchorRect(rect)
730
752
  }
731
753
 
732
754
  const AnnotationEditor = () => {
@@ -746,7 +768,10 @@ window.__ModuleLoader__.load({
746
768
  const vw = typeof window !== 'undefined' ? window.innerWidth : 1024
747
769
  const vh = typeof window !== 'undefined' ? window.innerHeight : 768
748
770
  const item = state.item
749
- const rect = open ? safeRect(state.rect) : null
771
+ const rect = open ? anchorRect(state.rect) : null
772
+ if (rect && rect.__dshq === 'fallback') {
773
+ try { report('editor:anchor', { src: 'fallback' }) } catch (e) { /* ignore */ }
774
+ }
750
775
  let left = -9999
751
776
  let top = -9999
752
777
  let w = 200
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-quote-annotate-pro",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "选区引用与锚点批注(增强 fork):划词 → 批注 → 带精确锚点的引用;输入框上方只显示原文片段,点一下跳回原文;发送时把轮次/角色写入引用块,让模型精确知道你指的是哪一处。",
5
5
  "keywords": ["dsh", "dsh-plugin", "deepseek-harness", "quote", "annotate", "selection", "reference", "anchor"],
6
6
  "license": "MIT",