-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Search within Embed objects (#2090)
- Loading branch information
1 parent
80ee3f4
commit 40e18b2
Showing
11 changed files
with
388 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Search | ||
|
||
You can search the text of your document using the search toolbar button. | ||
Enter the text and use the up/down buttons to move to the previous/next selection. | ||
Use the 3 vertical dots icon to turn on case-sensitivity or whole word constraints. | ||
|
||
## Search configuration options | ||
|
||
By default, the content of Embed objects are not searched. | ||
You can enable search by setting the [searchEmbedMode] in searchConfigurations: | ||
|
||
```dart | ||
MyQuillEditor( | ||
controller: _controller, | ||
configurations: QuillEditorConfigurations( | ||
searchConfigurations: const QuillSearchConfigurations( | ||
searchEmbedMode: SearchEmbedMode.plainText, | ||
), | ||
), | ||
... | ||
), | ||
``` | ||
|
||
### SearchEmbedMode.none (default option) | ||
|
||
Embed objects will not be included in searches. | ||
|
||
### SearchEmbedMode.rawData | ||
|
||
This is the simplest search option when your Embed objects use simple text that is also displayed to the user. | ||
This option allows searching within custom Embed objects using the node's raw data [Embeddable.data]. | ||
|
||
### SearchEmbedMode.plainText | ||
|
||
This option is best for complex Embeds where the raw data contains text that is not visible to the user and/or contains textual data that is not suitable for searching. | ||
For example, searching for '2024' would not be meaningful if the raw data is the full path of an image object (such as /user/temp/20240125/myimage.png). | ||
In this case the image would be shown as a search hit but the user would not know why. | ||
|
||
This option allows searching within custom Embed objects using an override to the [toPlainText] method. | ||
|
||
```dart | ||
class MyEmbedBuilder extends EmbedBuilder { | ||
@override | ||
String toPlainText(Embed node) { | ||
/// Convert [node] to the text that can be searched. | ||
/// For example: convert to MyEmbeddable and use the | ||
/// properties to return the searchable text. | ||
final m = MyEmbeddable(node.value.data); | ||
return '${m.property1}\t${m.property2}'; | ||
} | ||
... | ||
``` | ||
If [toPlainText] is not overridden, the base class implementation returns [Embed.kObjectReplacementCharacter] which is not searchable. | ||
|
||
### Strategy for mixed complex and simple Embed objects | ||
|
||
Select option [SearchEmbedMode.plainText] and override [toPlainText] to provide the searchable text. For your simple Embed objects provide the following override: | ||
|
||
```dart | ||
class MySimpleEmbedBuilder extends EmbedBuilder { | ||
@override | ||
String toPlainText(Embed node) { | ||
return node.value.data; | ||
} | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:flutter/foundation.dart' show immutable; | ||
|
||
enum SearchEmbedMode { | ||
/// No search within Embed nodes. | ||
none, | ||
// Searches within Embed nodes using the nodes raw data [Embeddable.data.toString()] | ||
rawData, | ||
|
||
/// Searches within Embed nodes using override to [EmbedBuilder.toPlainText] | ||
plainText, | ||
} | ||
|
||
/// The configurations for the quill editor widget of flutter quill | ||
@immutable | ||
class QuillSearchConfigurations { | ||
const QuillSearchConfigurations({ | ||
this.searchEmbedMode = SearchEmbedMode.none, | ||
}); | ||
|
||
/// Search options for embed objects | ||
/// | ||
/// [SearchEmbedMode.none] disables searching within embed objects. | ||
/// [SearchEmbedMode.rawData] searches the Embed node using the raw data. | ||
/// [SearchEmbedMode.plainText] searches the Embed node using the [EmbedBuilder.toPlainText] override. | ||
final SearchEmbedMode searchEmbedMode; | ||
|
||
/// Future search options | ||
/// | ||
/// [rememberLastSearch] - would recall the last search text used. | ||
/// [enableSearchHistory] - would allow selection of previous searches. | ||
QuillSearchConfigurations copyWith({ | ||
SearchEmbedMode? searchEmbedMode, | ||
}) { | ||
return QuillSearchConfigurations( | ||
searchEmbedMode: searchEmbedMode ?? this.searchEmbedMode, | ||
); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
lib/src/editor_toolbar_controller_shared/quill_configurations.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export '../controller/quill_controller_configurations.dart'; | ||
export '../editor/config/editor_configurations.dart'; | ||
export '../editor/config/search_configurations.dart'; | ||
export '../editor_toolbar_shared/config/quill_shared_configurations.dart'; | ||
export '../toolbar/config/simple_toolbar_configurations.dart'; | ||
export '../toolbar/config/toolbar_configurations.dart'; |
Oops, something went wrong.