utils/handler_helpers
library
Functions
-
applyStyleProperty<T>(FluentDocument document, T value, {required void modifyLeaf(Fragment leaf, T value), required void setPending(FluentDocument document, T value), String? description})
→ bool
-
Generic helper for applying a style property to the selection or cursor.
When a selection exists,
modifyLeaf is applied to each leaf fragment
and the cursor moves to the end of the modified range.
When collapsed, setPending stores the value for subsequently typed text.
-
deleteSelectionIfExists(FluentDocument document)
→ bool
-
If there's an active selection, deletes it by replacing with empty string.
Returns true if a selection was deleted, false otherwise.
-
deleteWordHelper(FluentDocument document, {required bool forward})
→ bool
-
Deletes a word in the given direction by creating a temporary selection
from the current cursor position to the word boundary, then replacing
it with an empty string.
-
fallbackRepositionCursor(FluentDocument document)
→ void
-
When the cursor still points to a removed fragment, tries moveLeft
then moveRight to find the nearest valid caret stop.
-
mergeAtJunction(FluentDocument document, InlineContainerNode targetContainer, Fragment? junctionFrag, int childrenBeforeCount)
→ void
-
Merges children at the junction point after moving children from one
container to another. Handles fragment merging, cursor positioning,
list index recalculation, and content update.
-
moveCursorToFirstFragment(Cursor cursor, InlineContainerNode container)
→ void
-
Moves
cursor to the start (offset 0) of the first fragment child of
container. Handles Link transparency.
-
moveCursorToLastFragment(Cursor cursor, InlineContainerNode container)
→ void
-
Moves
cursor to the end (text.length) of the last fragment child of
container. Handles Link transparency.
-
notifyTextMutation(FluentDocument document, InlineContainerNode container, String fragmentId, int offset, int delta)
→ void
-
Notifies the comment system of a text mutation when the container is a
Paragraph. No-op for other container types.
-
recalculateAndUpdate(FluentDocument document)
→ void
-
Recalculates list indices and triggers a content update.
-
removeNodeAndReposition(FluentDocument document, FNode node, {bool forward = false})
→ bool
-
Removes
node from the tree and repositions the cursor to the
adjacent caret stop (previous when forward is false, next when true).
Calls document.updateContent and returns true.
-
resolveSelectionFromCursor(FluentDocument document)
→ ResolvedSelection?
-
Resolves the current cursor selection using cached stops and lines.
Returns null if the cursor is collapsed or the selection is invalid.
Caches the result on the document so multiple widgets in the same
cursor-change cycle reuse the same ResolvedSelection.
-
saveAndDeleteNode(FluentDocument document, FNode node, {required String description})
→ void
-
Saves undo state, removes
node from the document, and updates content.
-
splitAndApplyToLeaves(FluentDocument document, ResolvedSelection selection, {List<Fragment>? modifyBatch(List<Fragment> leaves)?, Fragment? modify(Fragment leaf)?})
→ ({Fragment? firstModified, Fragment? lastModified})
-
Splits fragments at selection boundaries, then calls
modify on each
leaf fragment in the resulting range (skipping FluentImage).
Returns the first and last modified fragments, or nulls if none modified.