Skip to content

Commit 3e75b1a

Browse files
authored
fix: convert markdown symbol to styled text fails (#1090)
* fix: convert markdown symbol to styled text fails * docs: update customzing.md * chore: disable macOS titlebar * chore: specify the built-in language as en_US * docs: update documentation * docs: update documentation
1 parent 5896855 commit 3e75b1a

File tree

17 files changed

+139
-86
lines changed

17 files changed

+139
-86
lines changed

frontend/app_flowy/packages/appflowy_editor/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ and the Flutter guide for
2727
</p>
2828

2929
<div align="center">
30-
<img src="https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/documentation/images/appflowy-editor-example.gif?raw=true" width = "700" style = "padding: 100"/>
30+
<img src="https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/documentation/images/appflowy_editor_example.mp4?raw=true" width = "700" style = "padding: 100"/>
3131
</div>
3232

3333
## Key Features
@@ -58,8 +58,6 @@ final editorStyle = EditorStyle.defaultStyle();
5858
final editorState = EditorState.empty(); // an empty state
5959
final editor = AppFlowyEditor(
6060
editorState: editorState,
61-
shortcutEvents: const [],
62-
customBuilders: const {},
6361
editorStyle: editorStyle,
6462
);
6563
```
@@ -72,8 +70,6 @@ final editorStyle = EditorStyle.defaultStyle();
7270
final editorState = EditorState(StateTree.fromJson(data));
7371
final editor = AppFlowyEditor(
7472
editorState: editorState,
75-
shortcutEvents: const [],
76-
customBuilders: const {},
7773
editorStyle: editorStyle,
7874
);
7975
```
@@ -113,7 +109,7 @@ Please refer to our documentation on customizing AppFlowy for a detailed discuss
113109

114110
Below are some examples of shortcut event customizations:
115111

116-
* [BIUS](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart) demonstrates how to make text bold/italic/underline/strikethrough through shortcut keys
112+
* [BIUS](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/format_style_handler.dart) demonstrates how to make text bold/italic/underline/strikethrough through shortcut keys
117113
* [Paste HTML](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart) gives you an idea on how to handle pasted styles through shortcut keys
118114
* Need more examples? Check out [Internal key event handlers](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers)
119115

frontend/app_flowy/packages/appflowy_editor/documentation/customizing.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Widget build(BuildContext context) {
2727

2828
At this point, nothing magic will happen after typing `_xxx_`.
2929

30-
![Before](./images/customizing_a_shortcut_event_before.gif)
30+
![Before](./images/customize_a_shortcut_event_before.gif)
3131

3232
To implement our shortcut event we will create a `ShortcutEvent` instance to handle an underscore input.
3333

@@ -39,11 +39,10 @@ We need to define `key` and `command` in a ShortCutEvent object to customize hot
3939
```dart
4040
import 'package:appflowy_editor/appflowy_editor.dart';
4141
import 'package:flutter/material.dart';
42-
import 'package:flutter/services.dart';
4342
4443
ShortcutEvent underscoreToItalicEvent = ShortcutEvent(
4544
key: 'Underscore to italic',
46-
command: 'underscore',
45+
command: 'shift+underscore',
4746
handler: _underscoreToItalicHandler,
4847
);
4948
@@ -82,25 +81,33 @@ ShortcutEventHandler _underscoreToItalicHandler = (editorState, event) {
8281
8382
final textNode = textNodes.first;
8483
final text = textNode.toRawString();
85-
// Determine if an 'underscore' already exists in the text node
86-
final previousUnderscore = text.indexOf('_');
87-
if (previousUnderscore == -1) {
84+
// Determine if an 'underscore' already exists in the text node and only once.
85+
final firstUnderscore = text.indexOf('_');
86+
final lastUnderscore = text.lastIndexOf('_');
87+
if (firstUnderscore == -1 ||
88+
firstUnderscore != lastUnderscore ||
89+
firstUnderscore == selection.start.offset - 1) {
8890
return KeyEventResult.ignored;
8991
}
9092
9193
// Delete the previous 'underscore',
9294
// update the style of the text surrounded by the two underscores to 'italic',
9395
// and update the cursor position.
9496
TransactionBuilder(editorState)
95-
..deleteText(textNode, previousUnderscore, 1)
97+
..deleteText(textNode, firstUnderscore, 1)
9698
..formatText(
9799
textNode,
98-
previousUnderscore,
99-
selection.end.offset - previousUnderscore - 1,
100-
{'italic': true},
100+
firstUnderscore,
101+
selection.end.offset - firstUnderscore - 1,
102+
{
103+
BuiltInAttributeKey.italic: true,
104+
},
101105
)
102106
..afterSelection = Selection.collapsed(
103-
Position(path: textNode.path, offset: selection.end.offset - 1),
107+
Position(
108+
path: textNode.path,
109+
offset: selection.end.offset - 1,
110+
),
104111
)
105112
..commit();
106113
@@ -121,17 +128,17 @@ Widget build(BuildContext context) {
121128
editorStyle: EditorStyle.defaultStyle(),
122129
customBuilders: const {},
123130
shortcutEvents: [
124-
_underscoreToItalicHandler,
131+
underscoreToItalic,
125132
],
126133
),
127134
),
128135
);
129136
}
130137
```
131138

132-
![After](./images/customizing_a_shortcut_event_after.gif)
139+
![After](./images/customize_a_shortcut_event_after.gif)
133140

134-
Check out the [complete code](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/underscore_to_italic_key_event_handler.dart) file of this example.
141+
Check out the [complete code](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/underscore_to_italic.dart) file of this example.
135142

136143

137144
## Customizing a Component
@@ -297,7 +304,7 @@ return AppFlowyEditor(
297304
);
298305
```
299306

300-
![Whew!](./images/customizing_a_component.gif)
307+
![Whew!](./images/customize_a_component.gif)
301308

302309
Check out the [complete code](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/network_image_node_widget.dart) file of this example.
303310

Binary file not shown.
Binary file not shown.
1.74 MB
Loading
367 KB
Loading
358 KB
Loading
Binary file not shown.

0 commit comments

Comments
 (0)