@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 +1 -1
- package/ui/client.js +23 -14
- package/ui/styles.css +2 -2
package/package.json
CHANGED
package/ui/client.js
CHANGED
|
@@ -156,22 +156,31 @@ document.addEventListener("mouseup", (e) => {
|
|
|
156
156
|
});
|
|
157
157
|
|
|
158
158
|
function computeOffset(selection, text) {
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// Walk up to find a [data-offset] element
|
|
164
|
-
let
|
|
165
|
-
while (
|
|
166
|
-
|
|
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 (
|
|
170
|
-
//
|
|
171
|
-
const lineOffset = parseInt(
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
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:
|
|
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:
|
|
716
|
+
max-height: 40vh;
|
|
717
717
|
overflow-y: auto;
|
|
718
718
|
white-space: pre-wrap;
|
|
719
719
|
border-left: 2px solid var(--accent);
|