@@ -45,11 +45,11 @@ export const HTML_RENDER_SELECTION_SCRIPT = String.raw`// Loaded as raw source i
4545 if (document.body) visit(document.body);
4646 return { text, chunks };
4747 };
48- const rect = (range) => {
48+ const rect = (range, entire = false ) => {
4949 // Paragraph selection may include a trailing newline with an empty rect.
5050 const rects = Array.from(range.getClientRects());
5151 const r =
52- rects.findLast((rect) => rect.width > 0 && rect.height > 0) || range.getBoundingClientRect();
52+ (!entire && rects.findLast((rect) => rect.width > 0 && rect.height > 0) ) || range.getBoundingClientRect();
5353 return { left: r.left, top: r.top, width: r.width, height: r.height };
5454 };
5555 const selector = (text, start, end) => {
@@ -113,8 +113,8 @@ export const HTML_RENDER_SELECTION_SCRIPT = String.raw`// Loaded as raw source i
113113 }
114114 if (start === null || !text.slice(start, end).trim()) return null;
115115 // Keep oversized quotes local; the parent can display its normal shorten action.
116- if (end - start > 8000) return { tooLong: true, rect: rect(range), pointer };
117- return { selector: selector(text, start, end), rect: rect(range), pointer };
116+ if (end - start > 8000) return { tooLong: true, rect: rect(range, true ), pointer };
117+ return { selector: selector(text, start, end), rect: rect(range, true ), pointer };
118118 };
119119 const schedule = (delay = 0) => {
120120 clearTimeout(timer);
@@ -188,7 +188,8 @@ export const HTML_RENDER_SELECTION_SCRIPT = String.raw`// Loaded as raw source i
188188 marked = null;
189189 };
190190 const markQuote = (quote, action, changesOnly = false) => {
191- clearMark();
191+ const ownsMark = action === "mark" || !commentQuote;
192+ if (ownsMark) clearMark();
192193 const reply = (target) => {
193194 if (changesOnly && (
194195 target === commentTarget ||
@@ -296,7 +297,7 @@ export const HTML_RENDER_SELECTION_SCRIPT = String.raw`// Loaded as raw source i
296297 // Page CSS can request smooth scrolling; return geometry only after positioning.
297298 if (dx || dy) window.scrollBy({ left: dx, top: dy, behavior: "instant" });
298299 }
299- if (window.CSS?.highlights && window.Highlight)
300+ if (ownsMark && window.CSS?.highlights && window.Highlight)
300301 CSS.highlights.set("t3-html-citation", new Highlight(marked));
301302 reply(rect(marked));
302303 };
@@ -321,6 +322,11 @@ export const HTML_RENDER_SELECTION_SCRIPT = String.raw`// Loaded as raw source i
321322 window.getSelection()?.removeAllRanges();
322323 }
323324 if (action === "dismiss") cancel();
325+ if (action === "untarget" && !commentQuote) clearMark();
326+ if (action === "target") {
327+ markQuote(quote, action);
328+ return;
329+ }
324330 if (action === "unmark") {
325331 commentQuote = null;
326332 commentTarget = null;
0 commit comments