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
e33027cb
Commit
e33027cb
authored
Jan 03, 2023
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Jan 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add static `trimmedRange` to `TextRange`
parent
aea38355
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
text-range-test.js
src/annotator/anchoring/test/text-range-test.js
+16
-0
text-range.ts
src/annotator/anchoring/text-range.ts
+10
-0
No files found.
src/annotator/anchoring/test/text-range-test.js
View file @
e33027cb
...
...
@@ -452,5 +452,21 @@ describe('annotator/anchoring/text-range', () => {
assert
.
equal
(
textRange
.
end
.
offset
,
10
);
});
});
describe
(
'trimmedRange'
,
()
=>
{
it
(
'adjusts Range start and end positions to remove whitespace'
,
()
=>
{
const
el
=
document
.
createElement
(
'div'
);
el
.
textContent
=
' one two three '
;
const
range
=
new
Range
();
range
.
selectNodeContents
(
el
);
const
textRange
=
TextRange
.
fromRange
(
range
).
toRange
();
const
trimmedRange
=
TextRange
.
trimmedRange
(
range
);
assert
.
equal
(
trimmedRange
.
startOffset
,
textRange
.
startOffset
+
1
);
assert
.
equal
(
trimmedRange
.
endOffset
,
textRange
.
endOffset
-
1
);
});
});
});
});
src/annotator/anchoring/text-range.ts
View file @
e33027cb
import
{
trimRange
}
from
'./trim-range'
;
/**
* Return the combined length of text nodes contained in `node`.
*/
...
...
@@ -314,4 +316,12 @@ export class TextRange {
new
TextPosition
(
root
,
end
)
);
}
/**
* Return a new Range representing `range` trimmed of any leading or trailing
* whitespace
*/
static
trimmedRange
(
range
:
Range
):
Range
{
return
trimRange
(
TextRange
.
fromRange
(
range
).
toRange
());
}
}
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