summaryrefslogtreecommitdiff
path: root/ext/js/dom/text-source-range.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2022-09-27 20:17:59 -0400
committerGitHub <noreply@github.com>2022-09-27 20:17:59 -0400
commitf76c7d74d076b53d2f17ef4d234d4fa894bbf611 (patch)
tree516a54ee9133958a6e90a564e31b1ffe1ea1d835 /ext/js/dom/text-source-range.js
parentbe7855bad2e3b452ca0700246a376f107a75e79e (diff)
Cleanup and refactoring (#2239)
* Remove unused ignoreSelectors * Remove unused isMouseButtonPressed * Update getWritingMode to use the immediate element if possible * Move static functions to DocumentUtil * Fix documentation
Diffstat (limited to 'ext/js/dom/text-source-range.js')
-rw-r--r--ext/js/dom/text-source-range.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/ext/js/dom/text-source-range.js b/ext/js/dom/text-source-range.js
index a0225748..bbc22599 100644
--- a/ext/js/dom/text-source-range.js
+++ b/ext/js/dom/text-source-range.js
@@ -124,7 +124,7 @@ class TextSourceRange {
* @param {boolean} fromEnd Whether to move the offset from the current end position (if `true`) or the start position (if `false`).
* @param {boolean} layoutAwareScan Whether or not HTML layout information should be used to generate
* the string content when scanning.
- * @returns {number} The actual number of characters (not codepoints) that were read.
+ * @returns {number} The actual number of codepoints that were read.
*/
setEndOffset(length, fromEnd, layoutAwareScan) {
let node;
@@ -147,7 +147,7 @@ class TextSourceRange {
* @param {number} length The maximum number of codepoints to move by.
* @param {boolean} layoutAwareScan Whether or not HTML layout information should be used to generate
* the string content when scanning.
- * @returns {number} The actual number of characters (not codepoints) that were read.
+ * @returns {number} The actual number of codepoints that were read.
*/
setStartOffset(length, layoutAwareScan) {
const state = new DOMTextScanner(this._range.startContainer, this._range.startOffset, !layoutAwareScan, layoutAwareScan).seek(-length);
@@ -172,8 +172,9 @@ class TextSourceRange {
* @returns {string} The rects.
*/
getWritingMode() {
- const node = this._isImposterDisconnected() ? this._imposterSourceElement : this._range.startContainer;
- return DocumentUtil.getElementWritingMode(node !== null ? node.parentElement : null);
+ let node = this._isImposterDisconnected() ? this._imposterSourceElement : this._range.startContainer;
+ if (node !== null && node.nodeType !== Node.ELEMENT_NODE) { node = node.parentElement; }
+ return DocumentUtil.getElementWritingMode(node);
}
/**