NabuSelection
Utilitaire réactif pour gérer la sélection de texte avec Svelte 5 runes
Note Not exported by name: you reach it through nabu.selection.
Related guide: Extensions →
Import
import { NabuSelection } from '@aionbuilders/nabu/extend';Constructor
new NabuSelection(nabu: Nabu)| Parameter | Type | Description |
|---|---|---|
nabu | Nabu | n/a |
Properties
anchorBlock
anchorBlock: Block | null | undefinedblocks
blocks: Set<Block>The blocks the selection covers (flagged selected: highlighted, marked, …). A selection that does not lie entirely in
one block leaves out the blocks that isolate their text (Block#isolatesSelection): a title is not part of a range.
Nor does it hold the HIDDEN content of a block that hides its children (the body of a collapsed toggle, hidesChildren):
a mark or a highlight never reaches text nobody sees (P-112). Deleting a range still removes such a body with its owner:
the deletion walks the tree itself (container.utils.js), it does not read this set.
end
end: {
block: Block;
direction: 'none' | 'forward' | 'backward';
from: number;
to: number;
} | null | undefinedendBlock
endBlock: Block | null | undefinedfocusBlock
focusBlock: Block | null | undefinedisRange
isRange: booleanTrue while the selection is a non-collapsed range across several blocks. The editor mirrors it as data-nabu-range on its
root, which the stylesheet uses to not highlight isolated blocks (the model leaves them out of the range, see blocks).
start
start: {
block: Block;
direction: 'none' | 'forward' | 'backward';
from: number;
to: number;
} | null | undefinedstartBlock
startBlock: Block | null | undefinedMethods
selectBetween()
selectBetween(first: Block, last: Block): booleanSelects the text of the document between two blocks (first block start -> last block end).
| Parameter | Type | Description |
|---|---|---|
first | Block | n/a |
last | Block | n/a |
selectBlockText()
selectBlockText(block: Block): booleanSelects exactly the text of block (Select All inside an isolated field).
| Parameter | Type | Description |
|---|---|---|
block | Block | n/a |
Returns boolean
False when the block has no DOM point to select
setCursor()
setCursor(block: Block, offset: number): voidDéfinit le curseur à un endroit précis du document (Modèle -> DOM)
| Parameter | Type | Description |
|---|---|---|
block | Block | n/a |
offset | number | n/a |
Inherited
From SvelteSelection anchorNode, anchorOffset, endOffset, focusNode, focusOffset, is, isCollapsed, startOffset, text, range, sync
Examples
const selection = new SvelteSelection();
// Utiliser selection.text, selection.isCollapsed, etc. dans vos composantsSource: src/lib/blocks/selection.svelte.js:12