feat: adding number feature to toolbar (#2077)

This commit is contained in:
Peterson Nwoko 2023-04-03 06:04:01 +01:00 committed by GitHub
parent 34799dfdf5
commit ddca659c77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 0 deletions

View File

@ -249,6 +249,22 @@ List<ToolbarItem> defaultToolbarItems = [
),
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(
id: 'appflowy.toolbar.link',
type: 4,

View File

@ -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.
///
/// If the selected nodes are not text nodes, this method will do nothing.

View File

@ -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', (() {
testWidgets('Select Text, Click Toolbar and set style for highlighted text',
(tester) async {