Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #9

Open
wants to merge 8 commits into
base: documentation/flowy_editor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/app_flowy/packages/appflowy_editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ and the Flutter guide for

## Key Features

* Allow you to build rich, intuitive editors like those in Notion
* Allow you to build rich, intuitive editors
* Customize to your needs by customizing components, shortcut events, and many more coming soon including menu options and themes
* [Test-covered](https://github.com/LucasXu0/AppFlowy/blob/documentation/appflowy_editor/frontend/app_flowy/packages/appflowy_editor/documentation/testing.md) and maintained by AppFlowy's core team along with a community of more than 1,000 builders

Expand Down Expand Up @@ -87,4 +87,4 @@ Please refer to [customizing a shortcut event](documentation/customizing.md#cust
Please refer to the API documentation (link).

## Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated. Please look at [CONTRIBUTING.md](documentation/contributing.md) for details.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated. Please look at [CONTRIBUTING.md](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/contributing-to-appflowy) for details.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# How to customizing ...
# How to customize ...

## Customizing a shortcut event
we will use a simple example to describe how to quickly extend shortcut event.
## Customize a shortcut event

We will use a simple example to illustrate how to quickly add a shortcut event.

For example, typing `_xxx_` will be converted into _xxx_.

To start with, we build the simplest example, just a blank document.
Let's start with a blank document.

```dart
@override
Expand All @@ -22,11 +23,11 @@ Widget build(BuildContext context) {
}
```

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

![Before](./images/customizing_a_shortcut_event_before.gif)

Next, we will create a function to handler underscore input.
Next, we will create a function to handle an underscore input.

```dart
import 'package:appflowy_editor/appflowy_editor.dart';
Expand All @@ -42,15 +43,15 @@ FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) {
};
```

Then, we need to determine if the currently selected node is `TextNode` and is a single-select case, because for the multi-select case, underscore input should be considered as replacement.
Then, we need to determine if the currently selected node is `TextNode` and the selection is collapsed.

```dart
// ...
FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) {
// ...

// Obtaining the selection and selected nodes of the current document through `selectionService`.
// And determine whether it is a single selection and whether the selected node is a text node.
// And determine whether the selection is collapsed and whether the selected node is a text node.
final selectionService = editorState.service.selectionService;
final selection = selectionService.currentSelection.value;
final textNodes = selectionService.currentSelectedNodes.whereType<TextNode>();
Expand All @@ -59,7 +60,11 @@ FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) {
}
```

Now, we start working on underscore logic by looking for the position of the previous underscore and returning if not found. If found, the text wrapped in the two underscores will be converted info italic.
Now, we start dealing with underscore.

Look for the position of the previous underscore and
1. return, if not found.
2. if found, the text wrapped in between two underscores will be displayed in italic.

```dart
// ...
Expand Down Expand Up @@ -94,7 +99,7 @@ FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) {
};
```

So far, the 'underscore handler' function has completed and only needs to be injected info AppFlowyEditor.
So far, the 'underscore handler' function is done and the only task left is to inject it into the AppFlowyEditor.

```dart
@override
Expand All @@ -117,12 +122,12 @@ Widget build(BuildContext context) {

[Complete code example]()

## Customizing a component
we will use a simple example to describe how to quickly extend custom component.
## Customize a component
We will use a simple example to showcase how to quickly add a custom component.

For example, we want to render an image from network.
For example, we want to render an image from the network.

To start with, we build the simplest example, just a blank document.
To start with, let's create an empty document by running commands as follows:

```dart
@override
Expand All @@ -139,7 +144,7 @@ Widget build(BuildContext context) {
}
```

Next, we choose a unique string for the type of the custom node and use `network_image` in this case. And we add `network_image_src` to the `attributes` to describe the link of the image.
Next, we choose a unique string for your custom node's type. We use `network_image` in this case. And we add `network_image_src` to the `attributes` to describe the link of the image.

> For the definition of the [Node](), please refer to this [link]().

Expand All @@ -152,7 +157,9 @@ Next, we choose a unique string for the type of the custom node and use `network
}
```

Then, we create a class that inherits [NodeWidgetBuilder](). As shown in the autoprompt, we need to implement two functions, one that returns a widget and the other that verifies the correctness of the [Node]().
Then, we create a class that inherits [NodeWidgetBuilder](). As shown in the autoprompt, we need to implement two functions:
1. one returns a widget
2. the other verifies the correctness of the [Node]().


```dart
Expand Down Expand Up @@ -276,4 +283,4 @@ return AppFlowyEditor(

![](./images/customizing_a_component.gif)

[Complete code example]()
[Here you can check out the complete code file of this example]()
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Testing

> The directory structure of test files is consistent with the code files, makes it easy for us to judge the test status of the new added files and to retrieve the test code path of the corresponding file.
> The directory structure of test files is consistent with the code files, making it easy for us to map a file with the corresponding test and check if the test is updated

## Testing Functions

**Construct document for testing**
**Construct a document for testing**
```dart
const text = 'Welcome to Appflowy 😁';
// Get the instance of editor.
Expand Down Expand Up @@ -35,15 +35,14 @@ editor.insertTextNode(
await editor.startTesting();
```

**Get the number of nodes in document**
**Get the number of nodes in the document**
```dart
final length = editor.documentLength;
print(length);
```

**Get the node of the specified path**
**Get the node of a defined path**
```dart
// 获取上述文档结构中的第一个文本节点
final firstTextNode = editor.nodeAtPath([0]) as TextNode;
```

Expand All @@ -60,7 +59,7 @@ final selection = editor.documentSelection;
print(selection);
```

**Simulate shortcut event input**
**Simulate shortcut event inputs**
```dart
// Command + A.
await editor.pressLogicKey(LogicalKeyboardKey.keyA, isMetaPressed: true);
Expand All @@ -72,7 +71,7 @@ await editor.pressLogicKey(
);
```

**Simulate text input**
**Simulate a text input**
```dart
// Insert 'Hello World' at the beginning of the first node.
editor.insertText(firstTextNode, 'Hello World', 0);
Expand All @@ -89,9 +88,9 @@ print(attributes);
```

## Example
For example, we are going to test the file `select_all_handler.dart`
For example, we are going to test `select_all_handler.dart`


**Full code example**
```dart
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -126,4 +125,4 @@ void main() async {
}
```

For the rest of the information on testing, such as simulated clicks, please refer to [An introduction to widget testing](https://docs.flutter.dev/cookbook/testing/widget/introduction)
For more information about testing, such as simulating a click, please refer to [An introduction to widget testing](https://docs.flutter.dev/cookbook/testing/widget/introduction)