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
9f675daa
Commit
9f675daa
authored
Mar 28, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Mar 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate selection-observer module to TypeScript
parent
f6c017e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
13 deletions
+15
-13
selection-observer.ts
src/annotator/selection-observer.ts
+15
-13
No files found.
src/annotator/selection-observer.
j
s
→
src/annotator/selection-observer.
t
s
View file @
9f675daa
import
{
ListenerCollection
}
from
'../shared/listener-collection'
;
/**
* Return the current selection or `null` if there is no selection or it is empty.
*
* @param {Document} document
* @return {Range|null}
* Return the current selection or `null` if there is no selection, or it is empty.
*/
export
function
selectedRange
(
document
)
{
export
function
selectedRange
(
document
:
Document
):
Range
|
null
{
const
selection
=
document
.
getSelection
();
if
(
!
selection
||
selection
.
rangeCount
===
0
)
{
return
null
;
...
...
@@ -22,15 +19,21 @@ export function selectedRange(document) {
* An observer that watches for and buffers changes to the document's current selection.
*/
export
class
SelectionObserver
{
private
_pendingCallback
:
number
|
null
;
private
_document
:
Document
;
private
_listeners
:
ListenerCollection
;
/**
* Start observing changes to the current selection in the document.
*
* @param {(range: Range|null) => void} callback -
* Callback invoked with the selected region of the document when it has
* changed.
* @param {Document} document_ - Test seam
* @param callback - Callback invoked with the selected region of the document
* when it has changed.
* @param document_ - Test seam
*/
constructor
(
callback
,
document_
=
document
)
{
constructor
(
callback
:
(
range
:
Range
|
null
)
=>
void
,
document_
:
Document
=
document
)
{
let
isMouseDown
=
false
;
this
.
_pendingCallback
=
null
;
...
...
@@ -41,8 +44,7 @@ export class SelectionObserver {
},
delay
);
};
/** @param {Event} event */
const
eventHandler
=
event
=>
{
const
eventHandler
=
(
event
:
Event
)
=>
{
if
(
event
.
type
===
'mousedown'
)
{
isMouseDown
=
true
;
}
...
...
@@ -93,7 +95,7 @@ export class SelectionObserver {
this
.
_cancelPendingCallback
();
}
_cancelPendingCallback
()
{
private
_cancelPendingCallback
()
{
if
(
this
.
_pendingCallback
)
{
clearTimeout
(
this
.
_pendingCallback
);
this
.
_pendingCallback
=
null
;
...
...
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