mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: #827
This commit is contained in:
parent
c53df59b48
commit
f708afe673
@ -46,6 +46,8 @@ class Selection {
|
|||||||
(start.path <= end.path && !pathEquals(start.path, end.path)) ||
|
(start.path <= end.path && !pathEquals(start.path, end.path)) ||
|
||||||
(isSingle && start.offset < end.offset);
|
(isSingle && start.offset < end.offset);
|
||||||
|
|
||||||
|
Selection get reversed => copyWith(start: end, end: start);
|
||||||
|
|
||||||
Selection collapse({bool atStart = false}) {
|
Selection collapse({bool atStart = false}) {
|
||||||
if (atStart) {
|
if (atStart) {
|
||||||
return Selection(start: start, end: start);
|
return Selection(start: start, end: start);
|
||||||
|
@ -20,14 +20,17 @@ extension TextNodeExtension on TextNode {
|
|||||||
|
|
||||||
bool allSatisfyInSelection(String styleKey, Selection selection) {
|
bool allSatisfyInSelection(String styleKey, Selection selection) {
|
||||||
final ops = delta.whereType<TextInsert>();
|
final ops = delta.whereType<TextInsert>();
|
||||||
|
final startOffset =
|
||||||
|
selection.isBackward ? selection.start.offset : selection.end.offset;
|
||||||
|
final endOffset =
|
||||||
|
selection.isBackward ? selection.end.offset : selection.start.offset;
|
||||||
var start = 0;
|
var start = 0;
|
||||||
for (final op in ops) {
|
for (final op in ops) {
|
||||||
if (start >= selection.end.offset) {
|
if (start >= endOffset) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
final length = op.length;
|
final length = op.length;
|
||||||
if (start < selection.end.offset &&
|
if (start < endOffset && start + length > startOffset) {
|
||||||
start + length > selection.start.offset) {
|
|
||||||
if (op.attributes == null ||
|
if (op.attributes == null ||
|
||||||
!op.attributes!.containsKey(styleKey) ||
|
!op.attributes!.containsKey(styleKey) ||
|
||||||
op.attributes![styleKey] == false) {
|
op.attributes![styleKey] == false) {
|
||||||
|
@ -43,7 +43,7 @@ bool insertTextNodeAfterSelection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
final node = nodes.first;
|
final node = nodes.first;
|
||||||
if (node is TextNode && node.delta.length == 0) {
|
if (node is TextNode && node.delta.isEmpty) {
|
||||||
formatTextNodes(editorState, attributes);
|
formatTextNodes(editorState, attributes);
|
||||||
} else {
|
} else {
|
||||||
final next = selection.end.path.next;
|
final next = selection.end.path.next;
|
||||||
@ -157,11 +157,18 @@ bool formatRichTextPartialStyle(EditorState editorState, String styleKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool formatRichTextStyle(EditorState editorState, Attributes attributes) {
|
bool formatRichTextStyle(EditorState editorState, Attributes attributes) {
|
||||||
final selection = editorState.service.selectionService.currentSelection.value;
|
var selection = editorState.service.selectionService.currentSelection.value;
|
||||||
final nodes = editorState.service.selectionService.currentSelectedNodes;
|
var nodes = editorState.service.selectionService.currentSelectedNodes;
|
||||||
final textNodes = nodes.whereType<TextNode>().toList();
|
|
||||||
|
|
||||||
if (selection == null || textNodes.isEmpty) {
|
if (selection == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes = selection.isBackward ? nodes : nodes.reversed.toList(growable: false);
|
||||||
|
selection = selection.isBackward ? selection : selection.reversed;
|
||||||
|
|
||||||
|
var textNodes = nodes.whereType<TextNode>().toList();
|
||||||
|
if (textNodes.isEmpty) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,28 +187,20 @@ bool formatRichTextStyle(EditorState editorState, Attributes attributes) {
|
|||||||
} else {
|
} else {
|
||||||
for (var i = 0; i < textNodes.length; i++) {
|
for (var i = 0; i < textNodes.length; i++) {
|
||||||
final textNode = textNodes[i];
|
final textNode = textNodes[i];
|
||||||
|
var index = 0;
|
||||||
|
var length = textNode.toRawString().length;
|
||||||
if (i == 0 && textNode == nodes.first) {
|
if (i == 0 && textNode == nodes.first) {
|
||||||
builder.formatText(
|
index = selection.start.offset;
|
||||||
textNode,
|
length = textNode.toRawString().length - selection.start.offset;
|
||||||
selection.start.offset,
|
|
||||||
textNode.toRawString().length - selection.start.offset,
|
|
||||||
attributes,
|
|
||||||
);
|
|
||||||
} else if (i == textNodes.length - 1 && textNode == nodes.last) {
|
} else if (i == textNodes.length - 1 && textNode == nodes.last) {
|
||||||
builder.formatText(
|
length = selection.end.offset;
|
||||||
textNode,
|
|
||||||
0,
|
|
||||||
selection.end.offset,
|
|
||||||
attributes,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
builder.formatText(
|
|
||||||
textNode,
|
|
||||||
0,
|
|
||||||
textNode.toRawString().length,
|
|
||||||
attributes,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
builder.formatText(
|
||||||
|
textNode,
|
||||||
|
index,
|
||||||
|
length,
|
||||||
|
attributes,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,6 +487,7 @@ class _FlowySelectionState extends State<FlowySelection>
|
|||||||
max = mid - 1;
|
max = mid - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
min = min.clamp(start, end);
|
||||||
final node = sortedNodes[min];
|
final node = sortedNodes[min];
|
||||||
if (node.children.isNotEmpty && node.children.first.rect.top <= offset.dy) {
|
if (node.children.isNotEmpty && node.children.first.rect.top <= offset.dy) {
|
||||||
final children = node.children.toList(growable: false);
|
final children = node.children.toList(growable: false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user