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
4f9ad082
Commit
4f9ad082
authored
Mar 30, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Mar 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split type guard into two helper functions
parent
fbcd5bf2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
frame-observer.ts
src/annotator/frame-observer.ts
+4
-0
range-util.ts
src/annotator/range-util.ts
+6
-4
No files found.
src/annotator/frame-observer.ts
View file @
4f9ad082
...
@@ -161,6 +161,10 @@ export function onDocumentReady(
...
@@ -161,6 +161,10 @@ export function onDocumentReady(
{
pollInterval
=
10
}:
{
pollInterval
?:
number
}
=
{}
{
pollInterval
=
10
}:
{
pollInterval
?:
number
}
=
{}
):
()
=>
void
{
):
()
=>
void
{
let
pollTimer
:
number
|
undefined
;
let
pollTimer
:
number
|
undefined
;
// Two linting rules are conflicting here, so muting one of them.
// This should be fixable by refactoring the whole function, as there are
// crossed dependencies between local callbacks, that rely on each other
// having been called in a specific order.
// eslint-disable-next-line prefer-const
// eslint-disable-next-line prefer-const
let
pollForDocumentChange
:
()
=>
void
;
let
pollForDocumentChange
:
()
=>
void
;
...
...
src/annotator/range-util.ts
View file @
4f9ad082
...
@@ -52,10 +52,12 @@ export function forEachNodeInRange(range: Range, callback: (n: Node) => void) {
...
@@ -52,10 +52,12 @@ export function forEachNodeInRange(range: Range, callback: (n: Node) => void) {
}
}
function
nodeIsText
(
node
:
Node
):
node
is
Text
{
function
nodeIsText
(
node
:
Node
):
node
is
Text
{
return
node
.
nodeType
===
Node
.
TEXT_NODE
;
}
function
textNodeContainsText
(
textNode
:
Text
):
boolean
{
const
whitespaceOnly
=
/^
\s
*$/
;
const
whitespaceOnly
=
/^
\s
*$/
;
return
(
return
!
textNode
.
textContent
!
.
match
(
whitespaceOnly
);
node
.
nodeType
===
Node
.
TEXT_NODE
&&
!
node
.
textContent
!
.
match
(
whitespaceOnly
)
);
}
}
/**
/**
...
@@ -66,7 +68,7 @@ function nodeIsText(node: Node): node is Text {
...
@@ -66,7 +68,7 @@ function nodeIsText(node: Node): node is Text {
export
function
getTextBoundingBoxes
(
range
:
Range
):
DOMRect
[]
{
export
function
getTextBoundingBoxes
(
range
:
Range
):
DOMRect
[]
{
const
textNodes
:
Text
[]
=
[];
const
textNodes
:
Text
[]
=
[];
forEachNodeInRange
(
range
,
node
=>
{
forEachNodeInRange
(
range
,
node
=>
{
if
(
nodeIsText
(
node
))
{
if
(
nodeIsText
(
node
)
&&
textNodeContainsText
(
node
)
)
{
textNodes
.
push
(
node
);
textNodes
.
push
(
node
);
}
}
});
});
...
...
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