Class: TextSelectionPlugin
Represents a plugin that can be registered, activated, and deactivated.
Extends
Implements
Constructors
Constructor
new TextSelectionPlugin(
documentView):TextSelectionPlugin
Parameters
documentView
Returns
TextSelectionPlugin
Overrides
Properties
id
id:
string='text-selection-plugin'
Unique identifier for the plugin.
Implementation of
Accessors
active
Get Signature
get active():
boolean
Returns
boolean
Set Signature
set active(
v):void
Parameters
v
boolean
Returns
void
cursorPosition
Get Signature
get cursorPosition():
CursorPosition
Returns
debugMode
Get Signature
get debugMode():
boolean
Returns
boolean
Set Signature
set debugMode(
v):void
Parameters
v
boolean
Returns
void
documentView
Get Signature
get documentView():
DocumentView
The document view associated with the plugin.
Returns
Set Signature
set documentView(
v):void
The document view associated with the plugin.
Parameters
v
Returns
void
The document view associated with the plugin.
Implementation of
selectionColor
Get Signature
get selectionColor():
string
Returns
string
Set Signature
set selectionColor(
v):void
Parameters
v
string
Returns
void
Methods
activate()
activate():
void
Activates the plugin.
Returns
void
Implementation of
addEventListener()
addEventListener<
K>(type,listener):void
Register a function that will be called whenever the specified event is delivered.
Type Parameters
K
K extends keyof TextSelectionPluginEventMap
A generic type representing the key of the event type.
Parameters
type
K
String representing the event type to listen for.
listener
(…e) => void
The function that will be executed when an event of the specified type occurs.
Returns
void
Inherited from
clearSelection()
clearSelection():
void
Clears the current text selection.
Returns
void
deactivate()
deactivate():
void
Deactivates the plugin.
Returns
void
Implementation of
dispatchEvent()
dispatchEvent<
K>(type,args):void
Dispatches an event to all registered listeners.
Type Parameters
K
K extends keyof TextSelectionPluginEventMap
A generic type representing the key of the event type.
Parameters
type
K
String representing the event type to dispatch.
args
Parameters<TextSelectionPluginEventMap[K]>
The data associated with the event.
Returns
void
Inherited from
getCursorGeometry()
getCursorGeometry(
position):Promise<CursorGeometry>
Gets the geometry of a cursor at a given position for rendering. This geometry specifies the cursor’s position using the top coordinate, bottom coordinate, and a page number.
Parameters
position
The cursor position to retrieve geometry. This geometry specifies the cursor’s position using the top coordinate, bottom coordinate, and a page number.
Returns
Promise<CursorGeometry>
The cursor geometry or null if the position is invalid.
getNextPosition()
getNextPosition(
position):Promise<CursorPosition>
Experimental
Calculates the next cursor position (one glyph to the right).
Parameters
position
The current cursor position.
Returns
Promise<CursorPosition>
The next position, or null if at the end of the document. This method is experimental and may change in future versions.
getNextWordPosition()
getNextWordPosition(
position):Promise<CursorPosition>
Experimental
Calculates the cursor position at the start of the next word.
Parameters
position
The current cursor position.
Returns
Promise<CursorPosition>
The next word position, or null if at end of document.
This method is experimental and may change in future versions.
getPositionAbove()
getPositionAbove(
position):Promise<CursorPosition>
Experimental
Calculates the cursor position one line above (visually) while maintaining the horizontal position as closely as possible.
Parameters
position
The current cursor position.
Returns
Promise<CursorPosition>
The position above, or null if at the top of the document. This method is experimental and may change in future versions.
getPositionBelow()
getPositionBelow(
position):Promise<CursorPosition>
Experimental
Calculates the cursor position one line below (visually) while maintaining the horizontal position as closely as possible.
Parameters
position
The current cursor position.
Returns
Promise<CursorPosition>
The position below, or null if at the bottom of the document. This method is experimental and may change in future versions.
getPreviousPosition()
getPreviousPosition(
position):Promise<CursorPosition>
Experimental
Calculates the previous cursor position (one glyph to the left).
Parameters
position
The current cursor position.
Returns
Promise<CursorPosition>
The previous position, or null if at the start of the document. This method is experimental and may change in future versions.
getPreviousWordPosition()
getPreviousWordPosition(
position):Promise<CursorPosition>
Experimental
Calculates the cursor position at the start of the previous word.
Parameters
position
The current cursor position.
Returns
Promise<CursorPosition>
The previous word position, or null if at start of document.
This method is experimental and may change in future versions.
getSelection()
getSelection():
TextSelection
Gets the current text selection with geometry information. Useful for creating annotations or positioning UI elements.
Returns
The current selection or null if nothing selected.
getTextFragments()
getTextFragments(
pageNumber):Promise<TextFragment[]>
Gets the text fragments for a given page. Useful for implementing custom cursor navigation logic.
Parameters
pageNumber
number
The page number to get fragments for.
Returns
Promise<TextFragment[]>
Array of text fragments on the page.
removeAllListeners()
removeAllListeners<
K>(type):void
Remove all listeners for a given event.
Type Parameters
K
K extends keyof TextSelectionPluginEventMap
A generic type representing the key of the event type.
Parameters
type
K
String representing the event for which to remove all listeners.
Returns
void
Inherited from
EventEmitter.removeAllListeners
removeEventListener()
removeEventListener<
K>(type,listener):void
Removes an event listener previously registered with addEventListener.
Type Parameters
K
K extends keyof TextSelectionPluginEventMap
A generic type representing the key of the event type.
Parameters
type
K
String representing the event for which to remove an event listener.
listener
(…e) => void
The event listener function of the event handler to remove from the event target.
Returns
void
Inherited from
EventEmitter.removeEventListener
selectToNextWord()
selectToNextWord(
anchor):Promise<CursorPosition>
Experimental
Extends the selection from the anchor position to the next word. Useful for implementing Shift+Ctrl+Right keyboard navigation.
Parameters
anchor
The anchor position where the selection started.
Returns
Promise<CursorPosition>
The new cursor position, or null if at end of document.
This method is experimental and may change in future versions.
selectToPreviousWord()
selectToPreviousWord(
anchor):Promise<CursorPosition>
Experimental
Extends the selection from the anchor position to the previous word. Useful for implementing Shift+Ctrl+Left keyboard navigation.
Parameters
anchor
The anchor position where the selection started.
Returns
Promise<CursorPosition>
The new cursor position, or null if at start of document.
This method is experimental and may change in future versions.
setCursorPosition()
setCursorPosition(
position):Promise<void>
Sets the cursor position programmatically. Useful for restoring a previously saved cursor position.
Parameters
position
The cursor position to set, or null to remove the cursor.
Returns
Promise<void>
setSelectionRange()
setSelectionRange(
anchor,cursor):Promise<void>
Sets the text selection between two cursor positions. Useful for implementing keyboard-based text selection (Shift+Arrow).
Parameters
anchor
The anchor position where the selection started.
cursor
The cursor position where the selection currently ends.
Returns
Promise<void>