Inline Comment 0.2.0 - initial public release

Thunderbird/Betterbird add-on (Manifest V3): typing inside a quote splits
the quote and inserts your own text with a marker such as [OH]:.

- English and German user interface
- Licensed under the Mozilla Public License 2.0
- English documentation, JSDoc lint gate, 87 tests (node:test + jsdom)
This commit is contained in:
Oliver_Herb committed 2026-11-24 12:07:09 +01:00
commit 9053327486
57 files changed
+9849

No files matched your search

+100
View File
@@ -0,0 +1,100 @@
/*
* Copyright 2026 Oliver Herb
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
"use strict";
/*
* Shared helpers for the DOM tests. They create jsdom documents, place the
* caret or a selection the way a user would in the compose editor, and read
* text back in a form that is easy to compare in assertions.
*/
const { JSDOM } = require("jsdom");
/**
* Creates a new jsdom document whose body contains the given markup.
* @param {string} bodyHtml Markup placed inside <body>.
* @param {import("jsdom").ConstructorOptions} [options] Options passed to the
* JSDOM constructor, e.g. { runScripts: "outside-only" }.
* @returns {{ dom: JSDOM, window: Window, doc: Document }} The JSDOM instance,
* its window and its document.
*/
function createDocument(bodyHtml, options = {}) {
const dom = new JSDOM(
`<!doctype html><html><body>${bodyHtml}</body></html>`,
options,
);
return { dom, window: dom.window, doc: dom.window.document };
}
/**
* Places the caret (a collapsed selection) at node/offset and makes it the
* only range of the document selection.
* @param {Document} doc Document whose selection is changed.
* @param {Node} node Container node of the caret.
* @param {number} offset Character offset in a text node, or child index in
* an element.
* @returns {Range} The collapsed range that was added to the selection.
*/
function setCaret(doc, node, offset) {
const range = doc.createRange();
range.setStart(node, offset);
range.collapse(true);
const selection = doc.getSelection();
selection.removeAllRanges();
selection.addRange(range);
return range;
}
/**
* Selects the content from (startNode, startOffset) to (endNode, endOffset)
* and makes it the only range of the document selection.
* @param {Document} doc Document whose selection is changed.
* @param {Node} startNode Container node where the selection starts.
* @param {number} startOffset Offset within startNode.
* @param {Node} endNode Container node where the selection ends.
* @param {number} endOffset Offset within endNode.
* @returns {Range} The range that was added to the selection.
*/
function setSelection(doc, startNode, startOffset, endNode, endOffset) {
const range = doc.createRange();
range.setStart(startNode, startOffset);
range.setEnd(endNode, endOffset);
const selection = doc.getSelection();
selection.removeAllRanges();
selection.addRange(range);
return range;
}
/**
* Returns the first text node below the element, in document order.
* @param {Element} element Element to search.
* @returns {Text | null} The first descendant text node, or null if there is
* none.
*/
function firstText(element) {
const walker = element.ownerDocument.createTreeWalker(element, 4);
return walker.nextNode();
}
/**
* Returns the text content of a node with normalized whitespace: no-break
* spaces become plain spaces, runs of whitespace collapse to one space, and
* leading and trailing whitespace is removed.
* @param {Node} node Node to read.
* @returns {string} The normalized text.
*/
function text(node) {
return node.textContent
.replace(/\u00a0/g, " ")
.replace(/\s+/g, " ")
.trim();
}
module.exports = { createDocument, setCaret, setSelection, firstText, text };