mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: binary search selection supports searching child nodes
This commit is contained in:
parent
2f84d7e54e
commit
1ece5cfd9e
@ -43,7 +43,7 @@ class NodeIterator implements Iterator<Node> {
|
|||||||
if (nextOfParent == null) {
|
if (nextOfParent == null) {
|
||||||
_currentNode = null;
|
_currentNode = null;
|
||||||
} else {
|
} else {
|
||||||
_currentNode = _findLeadingChild(node);
|
_currentNode = _findLeadingChild(nextOfParent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,11 +110,17 @@ class _CheckboxNodeWidgetState extends State<CheckboxNodeWidget>
|
|||||||
.map(
|
.map(
|
||||||
(child) => widget.editorState.service.renderPluginService
|
(child) => widget.editorState.service.renderPluginService
|
||||||
.buildPluginWidget(
|
.buildPluginWidget(
|
||||||
NodeWidgetContext(
|
child is TextNode
|
||||||
context: context,
|
? NodeWidgetContext<TextNode>(
|
||||||
node: child,
|
context: context,
|
||||||
editorState: widget.editorState,
|
node: child,
|
||||||
),
|
editorState: widget.editorState,
|
||||||
|
)
|
||||||
|
: NodeWidgetContext<Node>(
|
||||||
|
context: context,
|
||||||
|
node: child,
|
||||||
|
editorState: widget.editorState,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
|
@ -527,6 +527,7 @@ class _FlowySelectionState extends State<FlowySelection>
|
|||||||
/// currently only single-level nesting is supported
|
/// currently only single-level nesting is supported
|
||||||
// find the first node's rect.bottom <= offset.dy
|
// find the first node's rect.bottom <= offset.dy
|
||||||
Node _lowerBound(List<Node> sortedNodes, Offset offset, int start, int end) {
|
Node _lowerBound(List<Node> sortedNodes, Offset offset, int start, int end) {
|
||||||
|
assert(start >= 0 && end < sortedNodes.length);
|
||||||
var min = start;
|
var min = start;
|
||||||
var max = end;
|
var max = end;
|
||||||
while (min <= max) {
|
while (min <= max) {
|
||||||
@ -537,7 +538,12 @@ class _FlowySelectionState extends State<FlowySelection>
|
|||||||
max = mid - 1;
|
max = mid - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sortedNodes[min];
|
final node = sortedNodes[min];
|
||||||
|
if (node.children.isNotEmpty && node.children.first.rect.top <= offset.dy) {
|
||||||
|
final children = node.children.toList(growable: false);
|
||||||
|
return _lowerBound(children, offset, 0, children.length - 1);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: Supports multi-level nesting,
|
/// TODO: Supports multi-level nesting,
|
||||||
@ -549,6 +555,7 @@ class _FlowySelectionState extends State<FlowySelection>
|
|||||||
int start,
|
int start,
|
||||||
int end,
|
int end,
|
||||||
) {
|
) {
|
||||||
|
assert(start >= 0 && end < sortedNodes.length);
|
||||||
var min = start;
|
var min = start;
|
||||||
var max = end;
|
var max = end;
|
||||||
while (min <= max) {
|
while (min <= max) {
|
||||||
@ -559,7 +566,12 @@ class _FlowySelectionState extends State<FlowySelection>
|
|||||||
max = mid - 1;
|
max = mid - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sortedNodes[max];
|
final node = sortedNodes[max];
|
||||||
|
if (node.children.isNotEmpty && node.children.first.rect.top <= offset.dy) {
|
||||||
|
final children = node.children.toList(growable: false);
|
||||||
|
return _lowerBound(children, offset, 0, children.length - 1);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user