fix: selection move direction logic should visit children (#1156)
This commit is contained in:
parent
a1f1c6708a
commit
aacec0801e
2 changed files with 38 additions and 1 deletions
|
|
@ -260,7 +260,10 @@ extension SelectionTransform on EditorState {
|
|||
else if (direction == SelectionMoveDirection.backward &&
|
||||
end != null &&
|
||||
end.offset <= offset) {
|
||||
final nextStart = node.next?.selectable?.start();
|
||||
final nextStart = node
|
||||
.nextNodeWhere((element) => element.selectable != null)
|
||||
?.selectable
|
||||
?.start();
|
||||
if (nextStart != null) {
|
||||
updateSelectionWithReason(
|
||||
Selection.collapsed(nextStart),
|
||||
|
|
|
|||
|
|
@ -38,6 +38,40 @@ extension NodeExtensions on Node {
|
|||
return Rect.zero;
|
||||
}
|
||||
|
||||
Node? nextNodeWhere(bool Function(Node element) test) {
|
||||
for (final child in children) {
|
||||
final matchingNode = child._thisOrDescendantMatching(test);
|
||||
if (matchingNode != null) {
|
||||
return matchingNode;
|
||||
}
|
||||
}
|
||||
|
||||
var next = this.next;
|
||||
while (next != null) {
|
||||
final nextDescendentMatch = next._thisOrDescendantMatching(test);
|
||||
if (nextDescendentMatch != null) {
|
||||
return nextDescendentMatch;
|
||||
}
|
||||
next = next.next;
|
||||
}
|
||||
|
||||
return parent?.next?._thisOrDescendantMatching(test);
|
||||
}
|
||||
|
||||
Node? _thisOrDescendantMatching(bool Function(Node element) test) {
|
||||
if (test(this)) {
|
||||
return this;
|
||||
}
|
||||
for (final child in children) {
|
||||
final matchingNode = child._thisOrDescendantMatching(test);
|
||||
if (matchingNode != null) {
|
||||
return matchingNode;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Returns the first previous node in the subtree that satisfies the given predicate
|
||||
Node? previousNodeWhere(bool Function(Node element) test) {
|
||||
var previous = this.previous;
|
||||
|
|
|
|||
Loading…
Reference in a new issue