-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: make find menu widget * feat: service for find menu * feat: add find menu shortcut event * feat: create a search service * docs: explain search service * fix: unhighlight method takes searched word * fix: unhighlight before each search * feat: navigate between matches * feat: forget highlighting from undo stack * feat: replace logic and ui * feat: replace shortcut handler and widget * test: find functionality * test: replace menu tests * refactor: separate class for search algo * refactor: suggested changes * refactor: remove unhighlight method * feat: add find highlight color * refactor: name of the search algo class * test: unit tests for search algorithm * chore: simplify syntax * test: renamed test group * refactor: move to editor * refactor: add shortcut for find * refactor: use new api * refactor: add abstrac class search algo * fix: avoid multiple instances of find dialog * refactor: xazin's suggestions * chore: separately build input decor * test: search algorithm * chore: unhighlight properly * refactor: replace handler * refactor: move tests into new * test: find menu widget test * test: replace menu * fix: localizations + resolve scroll bug partially * fix: without update selection on highlight * fix: do not select words when highlighting * test: update expected selection * fix: matches and styling * feat: separate attribute for highlighting * feat: unique color for selected match * test: unique color for selected match * refactor: cleaning the code * fix: navigate to first match * fix: tests and replace logic --------- Co-authored-by: Mathias Mogensen <[email protected]> Co-authored-by: Mathias Mogensen <[email protected]>
- Loading branch information
1 parent
953249f
commit f5c6dc2
Showing
26 changed files
with
1,630 additions
and
25 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
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
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
117 changes: 117 additions & 0 deletions
117
...itor/editor_component/service/shortcuts/command_shortcut_events/find_replace_command.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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import 'package:appflowy_editor/appflowy_editor.dart'; | ||
import 'package:appflowy_editor/src/editor/find_replace_menu/find_menu_service.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
List<CommandShortcutEvent> findAndReplaceCommands({ | ||
required FindReplaceLocalizations localizations, | ||
required BuildContext context, | ||
FindReplaceStyle? style, | ||
}) => | ||
[ | ||
openFindDialog( | ||
localizations: localizations, | ||
context: context, | ||
style: style ?? FindReplaceStyle(), | ||
), | ||
openReplaceDialog( | ||
localizations: localizations, | ||
context: context, | ||
style: style ?? FindReplaceStyle(), | ||
), | ||
]; | ||
|
||
class FindReplaceStyle { | ||
FindReplaceStyle({ | ||
this.selectedHighlightColor = const Color(0xFFFFB931), | ||
this.unselectedHighlightColor = const Color(0x60ECBC5F), | ||
}); | ||
|
||
//selected highlight color is used as background color on the selected found pattern. | ||
final Color selectedHighlightColor; | ||
//unselected highlight color is used on every other found pattern which can be selected. | ||
final Color unselectedHighlightColor; | ||
} | ||
|
||
class FindReplaceLocalizations { | ||
FindReplaceLocalizations({ | ||
required this.find, | ||
required this.previousMatch, | ||
required this.nextMatch, | ||
required this.close, | ||
required this.replace, | ||
required this.replaceAll, | ||
}); | ||
|
||
final String find; | ||
final String previousMatch; | ||
final String nextMatch; | ||
final String close; | ||
final String replace; | ||
final String replaceAll; | ||
} | ||
|
||
/// Show the slash menu | ||
/// | ||
/// - support | ||
/// - desktop | ||
/// - web | ||
/// | ||
CommandShortcutEvent openFindDialog({ | ||
required FindReplaceLocalizations localizations, | ||
required BuildContext context, | ||
required FindReplaceStyle style, | ||
}) => | ||
CommandShortcutEvent( | ||
key: 'show the find dialog', | ||
command: 'ctrl+f', | ||
macOSCommand: 'cmd+f', | ||
handler: (editorState) => _showFindAndReplaceDialog( | ||
context, | ||
editorState, | ||
localizations: localizations, | ||
style: style, | ||
), | ||
); | ||
|
||
CommandShortcutEvent openReplaceDialog({ | ||
required FindReplaceLocalizations localizations, | ||
required BuildContext context, | ||
required FindReplaceStyle style, | ||
}) => | ||
CommandShortcutEvent( | ||
key: 'show the find and replace dialog', | ||
command: 'ctrl+h', | ||
macOSCommand: 'cmd+h', | ||
handler: (editorState) => _showFindAndReplaceDialog( | ||
context, | ||
editorState, | ||
localizations: localizations, | ||
style: style, | ||
openReplace: true, | ||
), | ||
); | ||
|
||
FindReplaceService? _findReplaceService; | ||
KeyEventResult _showFindAndReplaceDialog( | ||
BuildContext context, | ||
EditorState editorState, { | ||
required FindReplaceLocalizations localizations, | ||
required FindReplaceStyle style, | ||
bool openReplace = false, | ||
}) { | ||
if (PlatformExtension.isMobile) { | ||
return KeyEventResult.ignored; | ||
} | ||
|
||
_findReplaceService = FindReplaceMenu( | ||
context: context, | ||
editorState: editorState, | ||
replaceFlag: openReplace, | ||
localizations: localizations, | ||
style: style, | ||
); | ||
|
||
_findReplaceService?.show(); | ||
|
||
return KeyEventResult.handled; | ||
} |
Oops, something went wrong.