Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
1920e374
Commit
1920e374
authored
Dec 05, 2022
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Dec 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert text-range to TS
parent
19486a61
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
97 deletions
+84
-97
text-range-test.js
src/annotator/anchoring/test/text-range-test.js
+11
-12
text-range.ts
src/annotator/anchoring/text-range.ts
+73
-85
No files found.
src/annotator/anchoring/test/text-range-test.js
View file @
1920e374
import
{
TextPosition
,
TextRange
,
RESOLVE_FORWARDS
,
RESOLVE_BACKWARDS
,
}
from
'../text-range'
;
import
{
TextPosition
,
TextRange
,
ResolveDirection
}
from
'../text-range'
;
import
{
assertNodesEqual
}
from
'../../../test-util/compare-dom'
;
...
...
@@ -114,13 +109,15 @@ describe('annotator/anchoring/text-range', () => {
});
});
describe
(
'when
`direction` is `RESOLVE_
FORWARDS`'
,
()
=>
{
describe
(
'when
resolve `direction` is `
FORWARDS`'
,
()
=>
{
it
(
'resolves to next text node if needed'
,
()
=>
{
const
el
=
document
.
createElement
(
'div'
);
el
.
innerHTML
=
'<b></b>bar'
;
const
pos
=
new
TextPosition
(
el
.
querySelector
(
'b'
),
0
);
const
resolved
=
pos
.
resolve
({
direction
:
RESOLVE_FORWARDS
});
const
resolved
=
pos
.
resolve
({
direction
:
ResolveDirection
.
FORWARDS
,
});
assert
.
equal
(
resolved
.
node
,
el
.
childNodes
[
1
]);
assert
.
equal
(
resolved
.
offset
,
0
);
...
...
@@ -130,18 +127,20 @@ describe('annotator/anchoring/text-range', () => {
const
el
=
document
.
createElement
(
'div'
);
const
pos
=
new
TextPosition
(
el
,
0
);
assert
.
throws
(()
=>
{
pos
.
resolve
({
direction
:
R
ESOLVE_
FORWARDS
});
pos
.
resolve
({
direction
:
R
esolveDirection
.
FORWARDS
});
});
});
});
describe
(
'when
`direction` is `RESOLVE_
BACKWARDS`'
,
()
=>
{
describe
(
'when
resolve `direction` is `
BACKWARDS`'
,
()
=>
{
it
(
'resolves to previous text node if needed'
,
()
=>
{
const
el
=
document
.
createElement
(
'div'
);
el
.
innerHTML
=
'bar<b></b>'
;
const
pos
=
new
TextPosition
(
el
.
querySelector
(
'b'
),
0
);
const
resolved
=
pos
.
resolve
({
direction
:
RESOLVE_BACKWARDS
});
const
resolved
=
pos
.
resolve
({
direction
:
ResolveDirection
.
BACKWARDS
,
});
assert
.
equal
(
resolved
.
node
,
el
.
childNodes
[
0
]);
assert
.
equal
(
resolved
.
offset
,
el
.
childNodes
[
0
].
data
.
length
);
...
...
@@ -151,7 +150,7 @@ describe('annotator/anchoring/text-range', () => {
const
el
=
document
.
createElement
(
'div'
);
const
pos
=
new
TextPosition
(
el
,
0
);
assert
.
throws
(()
=>
{
pos
.
resolve
({
direction
:
R
ESOLVE_
BACKWARDS
});
pos
.
resolve
({
direction
:
R
esolveDirection
.
BACKWARDS
});
});
});
});
...
...
src/annotator/anchoring/text-range.
j
s
→
src/annotator/anchoring/text-range.
t
s
View file @
1920e374
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment