mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: adding number feature to toolbar (#2077)
This commit is contained in:
parent
34799dfdf5
commit
ddca659c77
@ -249,6 +249,22 @@ List<ToolbarItem> defaultToolbarItems = [
|
|||||||
),
|
),
|
||||||
handler: (editorState, context) => formatBulletedList(editorState),
|
handler: (editorState, context) => formatBulletedList(editorState),
|
||||||
),
|
),
|
||||||
|
ToolbarItem(
|
||||||
|
id: 'appflowy.toolbar.number_list',
|
||||||
|
type: 3,
|
||||||
|
tooltipsMessage: AppFlowyEditorLocalizations.current.numberedList,
|
||||||
|
iconBuilder: (isHighlight) => FlowySvg(
|
||||||
|
name: 'toolbar/number_list',
|
||||||
|
color: isHighlight ? Colors.lightBlue : null,
|
||||||
|
),
|
||||||
|
validator: _onlyShowInSingleTextSelection,
|
||||||
|
highlightCallback: (editorState) => _allSatisfy(
|
||||||
|
editorState,
|
||||||
|
BuiltInAttributeKey.subtype,
|
||||||
|
(value) => value == BuiltInAttributeKey.numberList,
|
||||||
|
),
|
||||||
|
handler: (editorState, context) => formatNumberedList(editorState),
|
||||||
|
),
|
||||||
ToolbarItem(
|
ToolbarItem(
|
||||||
id: 'appflowy.toolbar.link',
|
id: 'appflowy.toolbar.link',
|
||||||
type: 4,
|
type: 4,
|
||||||
|
@ -91,6 +91,13 @@ void formatBulletedList(EditorState editorState) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void formatNumberedList(EditorState editorState) {
|
||||||
|
formatTextNodes(editorState, {
|
||||||
|
BuiltInAttributeKey.subtype: BuiltInAttributeKey.numberList,
|
||||||
|
BuiltInAttributeKey.number: 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// Format the current selection with the given attributes.
|
/// Format the current selection with the given attributes.
|
||||||
///
|
///
|
||||||
/// If the selected nodes are not text nodes, this method will do nothing.
|
/// If the selected nodes are not text nodes, this method will do nothing.
|
||||||
|
@ -302,6 +302,33 @@ void main() async {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
group('toolbar, number list' , (() {
|
||||||
|
testWidgets('Select Text, Click Toolbar and set style for number list',
|
||||||
|
(tester) async {
|
||||||
|
final editor = tester.editor..insertTextNode(singleLineText);
|
||||||
|
await editor.startTesting();
|
||||||
|
|
||||||
|
final numberList = Selection(
|
||||||
|
start: Position(path: [0],offset: 0),
|
||||||
|
end: Position(path: [0], offset: singleLineText.length));
|
||||||
|
|
||||||
|
await editor.updateSelection(numberList);
|
||||||
|
await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
||||||
|
expect(find.byType(ToolbarWidget), findsOneWidget);
|
||||||
|
final numberListButton = find.byWidgetPredicate((widget) {
|
||||||
|
if (widget is ToolbarItemWidget) {
|
||||||
|
return widget.item.id == 'appflowy.toolbar.number_list';
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
expect(numberListButton, findsOneWidget);
|
||||||
|
await tester.tap(numberListButton);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
final node = editor.nodeAtPath([0]) as TextNode;
|
||||||
|
expect(node.subtype, 'number-list');
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
group('toolbar, highlight', (() {
|
group('toolbar, highlight', (() {
|
||||||
testWidgets('Select Text, Click Toolbar and set style for highlighted text',
|
testWidgets('Select Text, Click Toolbar and set style for highlighted text',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user