summaryrefslogtreecommitdiff
path: root/ext/mixed/js/text-scanner.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-05-05 00:13:43 +0300
committerGitHub <noreply@github.com>2020-05-05 00:13:43 +0300
commit7d7ff165ced305bc269b24aa0ce8664272d86fa6 (patch)
treeacfba82a6b71770263dae23ce2f1ecb2a617f256 /ext/mixed/js/text-scanner.js
parent77b744e675f8abf17ff5e8433f4f1717e0c9ffb5 (diff)
Extract textSource text inside TextScanner (#500)
* extract text inside TextScanner * clone textSource before text extraction
Diffstat (limited to 'ext/mixed/js/text-scanner.js')
-rw-r--r--ext/mixed/js/text-scanner.js27
1 files changed, 15 insertions, 12 deletions
diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js
index d74a04f8..9dcf6009 100644
--- a/ext/mixed/js/text-scanner.js
+++ b/ext/mixed/js/text-scanner.js
@@ -318,21 +318,24 @@ class TextScanner extends EventDispatcher {
}
}
- setTextSourceScanLength(textSource, length) {
- textSource.setEndOffset(length);
- if (this.ignoreNodes === null || !textSource.range) {
- return;
- }
+ getTextSourceContent(textSource, length) {
+ const clonedTextSource = textSource.clone();
+
+ clonedTextSource.setEndOffset(length);
- length = textSource.text().length;
- while (textSource.range && length > 0) {
- const nodes = TextSourceRange.getNodesInRange(textSource.range);
- if (!TextSourceRange.anyNodeMatchesSelector(nodes, this.ignoreNodes)) {
- break;
+ if (this.ignoreNodes !== null && clonedTextSource.range) {
+ length = clonedTextSource.text().length;
+ while (clonedTextSource.range && length > 0) {
+ const nodes = TextSourceRange.getNodesInRange(clonedTextSource.range);
+ if (!TextSourceRange.anyNodeMatchesSelector(nodes, this.ignoreNodes)) {
+ break;
+ }
+ --length;
+ clonedTextSource.setEndOffset(length);
}
- --length;
- textSource.setEndOffset(length);
}
+
+ return clonedTextSource.text();
}
clearSelection(passive) {