aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/range.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-24 11:04:24 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-24 11:04:24 -0700
commit709094455e77d8ceba199316631381fcad47ef5d (patch)
treeb4423fd57ce0731ee92fc78263cb5e8c288734a2 /ext/fg/js/range.js
parent75d5d84811354cc6dc92c635fb77ad62b4c0aafe (diff)
Improvements
Diffstat (limited to 'ext/fg/js/range.js')
-rw-r--r--ext/fg/js/range.js24
1 files changed, 10 insertions, 14 deletions
diff --git a/ext/fg/js/range.js b/ext/fg/js/range.js
index 75decc20..9a98fb1a 100644
--- a/ext/fg/js/range.js
+++ b/ext/fg/js/range.js
@@ -40,11 +40,15 @@ class Range {
}
containsPoint(point) {
- const rect = this.getBoundingClientRect();
+ const rect = this.getPaddedRect();
return point.x >= rect.left && point.x <= rect.right;
}
- getBoundingClientRect() {
+ getRect() {
+ return this.rng.getBoundingClientRect();
+ }
+
+ getPaddedRect() {
const range = this.rng.cloneRange();
const startOffset = range.startOffset;
const endOffset = range.endOffset;
@@ -56,13 +60,9 @@ class Range {
return range.getBoundingClientRect();
}
- select(length) {
- const range = this.rng.cloneRange();
- range.setEnd(range.startContainer, range.startOffset + length);
-
+ select() {
const selection = window.getSelection();
- selection.removeAllRanges();
- selection.addRange(range);
+ selection.addRange(this.rng);
}
deselect() {
@@ -70,12 +70,8 @@ class Range {
selection.removeAllRanges();
}
- equals(range) {
- const equal =
- range.rng.compareBoundaryPoints(Range.END_TO_END, this.rng) === 0 &&
- range.rng.compareBoundaryPoints(Range.START_TO_START, this.rng) === 0;
-
- return equal;
+ compareOrigin(range) {
+ return range.rng.compareBoundaryPoints(Range.END_TO_END, this.rng);
}