@filipc77/cowrite 0.4.0 → 0.4.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@filipc77/cowrite",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Live commenting plugin for coding agent sessions",
5
5
  "type": "module",
6
6
  "bin": {
package/ui/client.js CHANGED
@@ -156,22 +156,31 @@ document.addEventListener("mouseup", (e) => {
156
156
  });
157
157
 
158
158
  function computeOffset(selection, text) {
159
- // For plain text: use data-offset on span.line elements
160
- const anchor = selection.anchorNode;
161
- if (!anchor) return -1;
162
-
163
- // Walk up to find a [data-offset] element
164
- let node = anchor.nodeType === Node.TEXT_NODE ? anchor.parentElement : anchor;
165
- while (node && !node.dataset?.offset && node !== fileContentEl) {
166
- node = node.parentElement;
159
+ const range = selection.getRangeAt(0);
160
+ const startNode = range.startContainer;
161
+ const startCharOffset = range.startOffset;
162
+
163
+ // Walk up from the range start to find a [data-offset] element
164
+ let lineEl = startNode.nodeType === Node.TEXT_NODE ? startNode.parentElement : startNode;
165
+ while (lineEl && !lineEl.dataset?.offset && lineEl !== fileContentEl) {
166
+ lineEl = lineEl.parentElement;
167
167
  }
168
168
 
169
- if (node?.dataset?.offset !== undefined) {
170
- // Plain text mode: compute from data-offset + text offset within the line
171
- const lineOffset = parseInt(node.dataset.offset, 10);
172
- const nodeText = node.textContent || "";
173
- const idx = nodeText.indexOf(text);
174
- if (idx !== -1) return lineOffset + idx;
169
+ if (lineEl?.dataset?.offset !== undefined) {
170
+ // Compute exact character offset within the line using the range start
171
+ const lineOffset = parseInt(lineEl.dataset.offset, 10);
172
+ // Walk text nodes inside this line element to find the position of startNode
173
+ const walker = document.createTreeWalker(lineEl, NodeFilter.SHOW_TEXT);
174
+ let charsBefore = 0;
175
+ while (walker.nextNode()) {
176
+ if (walker.currentNode === startNode) {
177
+ return lineOffset + charsBefore + startCharOffset;
178
+ }
179
+ charsBefore += walker.currentNode.textContent.length;
180
+ }
181
+ // If the start node wasn't found in this line, the selection might start
182
+ // at the line element boundary itself
183
+ return lineOffset;
175
184
  }
176
185
 
177
186
  // Fallback: search for the text in the raw content
package/ui/styles.css CHANGED
@@ -519,7 +519,7 @@ main {
519
519
  padding: 8px 10px;
520
520
  border-radius: var(--radius-sm);
521
521
  margin-bottom: 10px;
522
- max-height: 88px;
522
+ max-height: 200px;
523
523
  overflow-y: auto;
524
524
  white-space: pre-wrap;
525
525
  border-left: 2px solid var(--yellow);
@@ -713,7 +713,7 @@ main {
713
713
  padding: 10px 12px;
714
714
  border-radius: var(--radius-sm);
715
715
  margin-bottom: 14px;
716
- max-height: 120px;
716
+ max-height: 40vh;
717
717
  overflow-y: auto;
718
718
  white-space: pre-wrap;
719
719
  border-left: 2px solid var(--accent);