Skip to content

Commit

Permalink
Brought back DocumentNodeSelection after accidentally deleting it dur…
Browse files Browse the repository at this point in the history
…ing a rebase
  • Loading branch information
matthew-carroll committed Jul 19, 2022
1 parent 34e56ba commit 3c01bfe
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,66 @@ class SingleColumnLayoutSelectionStyler extends SingleColumnLayoutStylePhase {
///
/// If you don't want to display anything for this selection, return `null`.
typedef NonPrimarySelectionStyler = SelectionStyles? Function(NonPrimarySelection nonPrimarySelection);

/// Description of a selection within a specific node in a document.
///
/// The [nodeSelection] only describes the selection in the particular node
/// that [nodeId] points to. The document might have a selection that spans
/// multiple nodes but this only regards the part of that total selection that
/// affects the single node.
///
/// The [SelectionType] is a generic subtype of [NodeSelection], e.g., a
/// [TextNodeSelection] that describes which characters of text are
/// selected within the text node.
class DocumentNodeSelection<SelectionType extends NodeSelection> {
DocumentNodeSelection({
required this.nodeId,
required this.nodeSelection,
this.isBase = false,
this.isExtent = false,
this.highlightWhenEmpty = false,
});

/// The ID of the node that's selected.
final String nodeId;

/// The selection within the given node.
final SelectionType? nodeSelection;

/// Whether this [DocumentNodeSelection] forms the base position of a larger
/// document selection, `false` otherwise.
///
/// [isBase] is `true` iff [nodeId] is the same as [DocumentSelection.base.nodeId].
final bool isBase;

/// Whether this [DocumentNodeSelection] forms the extent position of a
/// larger document selection, `false` otherwise.
///
/// [isExtent] is `true` iff [nodeId] is the same as [DocumentSelection.extent.nodeId].
final bool isExtent;

/// Whether the component rendering this [DocumentNodeSelection] should
/// paint a highlight even when the given node has no content, `false`
/// otherwise.
///
/// For example: the user selects across multiple paragraphs. One of those
/// inner paragraphs is empty. We want to paint a small highlight where that
/// empty paragraph sits.
final bool highlightWhenEmpty;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is DocumentNodeSelection &&
runtimeType == other.runtimeType &&
nodeId == other.nodeId &&
nodeSelection == other.nodeSelection;

@override
int get hashCode => nodeId.hashCode ^ nodeSelection.hashCode;

@override
String toString() {
return '[DocumentNodeSelection] - node: "$nodeId", selection: ($nodeSelection)';
}
}

0 comments on commit 3c01bfe

Please sign in to comment.