1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-09-01 03:11:44 +02:00

Add range comparison methods to Point (#2248)

* Rename compare function in path-utils to compareOfSameSize
To make way for a new function that makes a full comparison

* Add compare function to path-utils that handles paths of different sizes

* Add function isAfterRange to Point

* Add function isBeforeRange to Point

* Add function isAtStartOfRange to Point

* Add function isAtEndOfRange to Point

* Add function isInRange to Point

* Add range comparison methods to the documentation of the Point model

* Remove `compareOfSameSize` in `path-utils.js`
Using `compare` instead

* Add `Point.isBeforePoint`

* Add `Point.isAfterPoint`

* Use own methods internally for range comparisons in `Point`

* Return null if paths don't finally match in `compare` method of `path-utils`
To convey that it is not a normal scenario

* Add first test for `Point` model (testing `isAfterPoint`)

* Add tests for `Point.isAfterPoint`

* Add tests for `Point.isBeforePoint`

* Add tests for `Point.isAfterRange`

* Add tests for `Point.isBeforeRange`

* Add tests for `Point.isAtEndOfRange`

* Add tests for `Point.isAtStartOfRange`

* Add tests for `Point.isInRange`
This commit is contained in:
Dundercover
2018-10-16 00:44:09 +02:00
committed by Ian Storm Taylor
parent 6c2168c8fe
commit 7192a97600
63 changed files with 1675 additions and 7 deletions

View File

@@ -90,6 +90,36 @@ Return a JSON representation of the point.
## Checking Methods
### `isAfterRange`
`isAfterRange(range: Range) => Boolean`
Determine whether the point is after a `range`.
### `isAtEndOfRange`
`isAtEndOfRange(range: Range) => Boolean`
Determine whether the point is at the end of a `range`.
### `isAtStartOfRange`
`isAtStartOfRange(range: Range) => Boolean`
Determine whether the point is at the start of a `range`.
### `isBeforeRange`
`isBeforeRange(range: Range) => Boolean`
Determine whether the point is before a `range`.
### `isInRange`
`isInRange(range: Range) => Boolean`
Determine whether the point is inside a `range`.
### `isAtEndOfNode`
`isAtEndOfNode(node: Node) => Boolean`

View File

@@ -120,6 +120,97 @@ class Point extends Record(DEFAULTS) {
return !this.isSet
}
/**
* Check whether the point is after another `point`.
*
* @return {Boolean}
*/
isAfterPoint(point) {
if (this.isUnset) return false
const is =
(this.key === point.key && this.offset > point.offset) ||
PathUtils.compare(this.path, point.path) === 1
return is
}
/**
* Check whether the point is after a `range`.
*
* @return {Boolean}
*/
isAfterRange(range) {
if (this.isUnset) return false
const is = this.isAfterPoint(range.end)
return is
}
/**
* Check whether the point is at the end of a `range`.
*
* @return {Boolean}
*/
isAtEndOfRange(range) {
if (this.isUnset) return false
const is = this.equals(range.end)
return is
}
/**
* Check whether the point is at the start of a `range`.
*
* @return {Boolean}
*/
isAtStartOfRange(range) {
if (this.isUnset) return false
const is = this.equals(range.start)
return is
}
/**
* Check whether the point is before another `point`.
*
* @return {Boolean}
*/
isBeforePoint(point) {
if (this.isUnset) return false
const is =
(this.key === point.key && this.offset < point.offset) ||
PathUtils.compare(this.path, point.path) === -1
return is
}
/**
* Check whether the point is before a `range`.
*
* @return {Boolean}
*/
isBeforeRange(range) {
if (this.isUnset) return false
const is = this.isBeforePoint(range.start)
return is
}
/**
* Check whether the point is inside a `range`.
*
* @return {Boolean}
*/
isInRange(range) {
if (this.isUnset) return false
const is =
this.equals(range.start) ||
this.equals(range.end) ||
(this.isAfterPoint(range.start) && this.isBeforePoint(range.end))
return is
}
/**
* Check whether the point is at the end of a `node`.
*

View File

@@ -1,18 +1,17 @@
import { List } from 'immutable'
/**
* Compare paths `path` and `b` to see which is before or after.
* Compare paths `path` and `target` to see which is before or after.
*
* @param {List} path
* @param {List} b
* @param {List} target
* @return {Number|Null}
*/
function compare(path, target) {
// PERF: if the paths are not the same size we can exit early.
if (path.size !== target.size) return null
const m = min(path, target)
for (let i = 0; i < path.size; i++) {
for (let i = 0; i < m; i++) {
const pv = path.get(i)
const tv = target.get(i)
@@ -23,8 +22,8 @@ function compare(path, target) {
if (pv > tv) return 1
}
// Otherwise they were equal the whole way, it's the same.
return 0
// Paths should now be equal, otherwise something is wrong
return path.size === target.size ? 0 : null
}
/**

View File

@@ -33,6 +33,14 @@ describe('slate', () => {
assert.deepEqual(actual, expected)
})
fixtures(__dirname, 'models/point', ({ module }) => {
const { input, output } = module
const fn = module.default
const actual = fn(input)
const expected = output
assert.equal(actual, expected)
})
fixtures(__dirname, 'models/text', ({ module }) => {
const { input, output } = module
const fn = module.default

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Point.create({
key: 'b',
path: [2],
offset: 2,
}),
}
export default function({ point, target }) {
return point.isAfterPoint(target)
}
export const output = true

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [0, 1],
offset: 4,
}),
target: Point.create({
key: 'b',
path: [0, 2],
offset: 2,
}),
}
export default function({ point, target }) {
return point.isAfterPoint(target)
}
export const output = false

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [0, 1],
offset: 4,
}),
target: Point.create({
key: 'a',
path: [0, 1],
offset: 3,
}),
}
export default function({ point, target }) {
return point.isAfterPoint(target)
}
export const output = true

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [0, 1],
offset: 1,
}),
target: Point.create({
key: 'a',
path: [0, 1],
offset: 2,
}),
}
export default function({ point, target }) {
return point.isAfterPoint(target)
}
export const output = false

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [0, 1],
offset: 4,
}),
target: Point.create({
key: 'a',
path: [0, 1],
offset: 4,
}),
}
export default function({ point, target }) {
return point.isAfterPoint(target)
}
export const output = false

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [1, 2],
offset: 1,
}),
target: Point.create({
key: 'b',
path: [1],
offset: 1,
}),
}
export default function({ point, target }) {
return point.isAfterPoint(target)
}
export const output = false

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [0, 0],
offset: 0,
}),
target: Point.create({
key: 'b',
path: [0, 0, 1],
offset: 0,
}),
}
export default function({ point, target }) {
return point.isAfterPoint(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAfterRange(target)
}
export const output = true

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 12,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAfterRange(target)
}
export const output = true

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAfterRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 2,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAfterRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [0],
offset: 7,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 4,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAfterRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 2,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 4,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAfterRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [5],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAfterRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 3,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAfterRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 0,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAfterRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtEndOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 12,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtEndOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtEndOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 2,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtEndOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [0],
offset: 7,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 4,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtEndOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 2,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 4,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtEndOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [5],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtEndOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 3,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtEndOfRange(target)
}
export const output = true

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 0,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtEndOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtStartOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 12,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtStartOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtStartOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 2,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtStartOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [0],
offset: 7,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 4,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtStartOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 2,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 4,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtStartOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [5],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtStartOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 3,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtStartOfRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 0,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isAtStartOfRange(target)
}
export const output = true

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Point.create({
key: 'b',
path: [2],
offset: 2,
}),
}
export default function({ point, target }) {
return point.isBeforePoint(target)
}
export const output = false

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [0, 1],
offset: 4,
}),
target: Point.create({
key: 'b',
path: [0, 2],
offset: 2,
}),
}
export default function({ point, target }) {
return point.isBeforePoint(target)
}
export const output = true

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [0, 1],
offset: 4,
}),
target: Point.create({
key: 'a',
path: [0, 1],
offset: 3,
}),
}
export default function({ point, target }) {
return point.isBeforePoint(target)
}
export const output = false

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [0, 1],
offset: 1,
}),
target: Point.create({
key: 'a',
path: [0, 1],
offset: 2,
}),
}
export default function({ point, target }) {
return point.isBeforePoint(target)
}
export const output = true

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [0, 1],
offset: 4,
}),
target: Point.create({
key: 'a',
path: [0, 1],
offset: 4,
}),
}
export default function({ point, target }) {
return point.isBeforePoint(target)
}
export const output = false

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [1, 2],
offset: 1,
}),
target: Point.create({
key: 'b',
path: [1],
offset: 1,
}),
}
export default function({ point, target }) {
return point.isBeforePoint(target)
}
export const output = false

View File

@@ -0,0 +1,20 @@
import Point from '../../../../src/models/point'
export const input = {
point: Point.create({
key: 'a',
path: [0, 0],
offset: 0,
}),
target: Point.create({
key: 'b',
path: [0, 0, 1],
offset: 0,
}),
}
export default function({ point, target }) {
return point.isBeforePoint(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isBeforeRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 12,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isBeforeRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isBeforeRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 2,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isBeforeRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [0],
offset: 7,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 4,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isBeforeRange(target)
}
export const output = true

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 2,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 4,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isBeforeRange(target)
}
export const output = true

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [5],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isBeforeRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 3,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isBeforeRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 0,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isBeforeRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isInRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 12,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isInRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isInRange(target)
}
export const output = true

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 2,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isInRange(target)
}
export const output = true

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [0],
offset: 7,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 4,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isInRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 2,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 4,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isInRange(target)
}
export const output = false

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'a',
path: [4],
offset: 1,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [5],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isInRange(target)
}
export const output = true

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'c',
path: [2],
offset: 3,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isInRange(target)
}
export const output = true

View File

@@ -0,0 +1,28 @@
import Point from '../../../../src/models/point'
import Range from '../../../../src/models/range'
export const input = {
point: Point.create({
key: 'b',
path: [1],
offset: 0,
}),
target: Range.create({
anchor: {
key: 'b',
path: [1],
offset: 0,
},
focus: {
key: 'c',
path: [2],
offset: 3,
},
}),
}
export default function({ point, target }) {
return point.isInRange(target)
}
export const output = true