summaryrefslogtreecommitdiff
path: root/ext/fg/js/source-range.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-07-25 20:07:54 -0700
committerAlex Yatskov <alex@foosoft.net>2016-07-25 20:07:54 -0700
commitf88f8dc97fa4baa354a7e04c125dd6968a22c85f (patch)
treed8e6cb61234aa5bb5b55e329fad764933062657e /ext/fg/js/source-range.js
parentd26ecab0b521e8da19c01521e5a5a3e3ada331eb (diff)
Sentence and URL support
Diffstat (limited to 'ext/fg/js/source-range.js')
-rw-r--r--ext/fg/js/source-range.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/ext/fg/js/source-range.js b/ext/fg/js/source-range.js
index fbab45f9..879b949c 100644
--- a/ext/fg/js/source-range.js
+++ b/ext/fg/js/source-range.js
@@ -22,20 +22,26 @@ class TextSourceRange {
this.rng = range;
}
+ clone() {
+ return new TextSourceRange(this.rng.cloneRange());
+ }
+
text() {
return this.rng.toString();
}
setEndOffset(length) {
- const end = TextSourceRange.seekForward(this.rng.startContainer, this.rng.startOffset + length);
- this.rng.setEnd(end.node, end.offset);
- return length - end.length;
+ const lengthAdj = length + this.rng.startOffset;
+ const state = TextSourceRange.seekForward(this.rng.startContainer, lengthAdj);
+ this.rng.setEnd(state.node, state.offset);
+ return length - state.length;
}
setStartOffset(length) {
- const start = TextSourceRange.seekBackward(this.rng.startContainer, length + (this.rng.startContainer.length - this.rng.startOffset));
- this.rng.setStart(start.node, start.offset);
- return length - start.length;
+ const lengthAdj = length + (this.rng.startContainer.length - this.rng.startOffset);
+ const state = TextSourceRange.seekBackward(this.rng.startContainer, lengthAdj);
+ this.rng.setStart(state.node, state.offset);
+ return length - state.length;
}
containsPoint(point) {
@@ -48,10 +54,10 @@ class TextSourceRange {
}
getPaddedRect() {
- const range = this.rng.cloneRange();
+ const range = this.rng.cloneRange();
const startOffset = range.startOffset;
- const endOffset = range.endOffset;
- const node = range.startContainer;
+ const endOffset = range.endOffset;
+ const node = range.startContainer;
range.setStart(node, Math.max(0, startOffset - 1));
range.setEnd(node, Math.min(node.length, endOffset + 1));