novident_editor_selection 1.0.5 copy "novident_editor_selection: ^1.0.5" to clipboard
novident_editor_selection: ^1.0.5 copied to clipboard

Selection rendering layer for Novident Editor — cursor, block selection, remote collaboration indicators. Reusable independently.

Novident Editor Selection #

Selection and cursor rendering infrastructure for the Novident Editor. Cursor widget, block selection areas, remote selections, and the SelectionRenderer API.

pub package

Features #

  • Cursor widgetCursor with three styles (verticalLine, borderLine, cover) and configurable blink timer.
  • BlockSelectionArea — stateful widget that measures and paints the cursor and selection highlights for a single block node. Polls selection rects in post-frame callbacks for zero-lag rendering.
  • BlockSelectionContainerStack-based layout that layers selection highlights, block content, cursor, and remote selections in the correct z-order.
  • RemoteBlockSelectionsArea — renders collaborative cursors and selections from RemoteSelection data.
  • SelectionAreaPaintCustomPaint-backed widget that fills a list of Rects with a configurable colour. Accepts minRectWidth for zero-width rects.
  • AnimatedSelectionAreaPaint — rotating gradient selection highlight with configurable colours, duration, and curve.
  • SelectionRenderer API — 20-method abstract class for full cursor/selection customisation. Override render, movement, transition, lifecycle, and measurement behaviour.
  • BlockSelectionHost — abstract interface (6 methods) that decouples selection rendering from the editor monolith. Any object implementing this interface can host a BlockSelectionArea.

Getting started #

Add to your pubspec.yaml:

dependencies:
  novident_editor_selection: <latest>

Usage #

Cursor widget #

import 'package:novident_editor_selection/novident_editor_selection.dart';

Cursor(
  rect: Rect.fromLTWH(100, 50, 2, 20),
  color: Colors.black,
  cursorStyle: CursorStyle.verticalLine,
  shouldBlink: true,
);

Selection highlight #

SelectionAreaPaint(
  rects: [Rect.fromLTWH(100, 50, 80, 20)],
  selectionColor: const Color(0x33448AFF),
  minRectWidth: 8.0,  // used when rect.width ≤ 0
);

Animated gradient selection #

AnimatedSelectionAreaPaint(
  rects: rects,
  withAnimation: true,
  colors: const [Colors.purple, Colors.pink, Colors.amber],
  duration: const Duration(seconds: 3),
  curve: Curves.easeInOut,
);

Block selection rendering #

BlockSelectionContainer(
  node: node,
  delegate: this,           // SelectableMixin
  listenable: selectionNotifier,
  host: editorState,        // implements BlockSelectionHost
  cursorColor: Colors.black,
  selectionColor: Colors.blue.withValues(alpha: 0.2),
  blockColor: Colors.blue.withValues(alpha: 0.1),
  supportTypes: const [
    BlockSelectionType.cursor,
    BlockSelectionType.selection,
    BlockSelectionType.block,
  ],
  child: myBlockContent,
);

Custom SelectionRenderer #

class MyRenderer extends DefaultSelectionRenderer {
  @override
  Widget buildCursor(CursorPaintContext ctx) {
    return Container(
      width: 4,
      height: ctx.rect.height,
      color: Colors.red,
    );
  }

  @override
  Widget buildSelectionHighlight(SelectionPaintContext ctx) {
    return AnimatedSelectionAreaPaint(
      rects: ctx.rects,
      withAnimation: true,
      colors: const [Colors.orange, Colors.red],
    );
  }
}

// Configure via EditorStyle:
EditorStyle.desktop(selectionRenderer: MyRenderer());

BlockSelectionHost implementation #

class MyHost implements BlockSelectionHost {
  @override bool isBlockSelectionMode() => false;

  @override CursorAppearance? customizeCursor({
    required Node node,
    required Selection? selection,
    required Position position,
  }) => null;

  @override EdgeInsets? blockSelectionMargin(Node node) => null;

  @override String? selectionDragModeValue() => null;

  @override SelectionRenderer? get selectionRenderer => myRenderer;
}

Additional information #

This package is extracted from novident_editor (the full rich-text editor widget). Use it to render cursors and selections on any surface that works with Node, Position, and SelectableMixin.

0
likes
150
points
231
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Selection rendering layer for Novident Editor — cursor, block selection, remote collaboration indicators. Reusable independently.

Homepage
Repository (GitHub)
View/report issues

License

MPL-2.0 (license)

Dependencies

collection, flutter, novident_editor_core, novident_editor_document

More

Packages that depend on novident_editor_selection