diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/default_key_event_handlers.dart b/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/default_key_event_handlers.dart index f99caab04a..e617804a77 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/default_key_event_handlers.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/default_key_event_handlers.dart @@ -8,6 +8,7 @@ import 'package:flowy_editor/src/service/internal_key_event_handlers/slash_handl import 'package:flowy_editor/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart'; import 'package:flowy_editor/src/service/internal_key_event_handlers/whitespace_handler.dart'; import 'package:flowy_editor/src/service/internal_key_event_handlers/select_all_handler.dart'; +import 'package:flowy_editor/src/service/internal_key_event_handlers/page_up_down_handler.dart'; import 'package:flowy_editor/src/service/keyboard_service.dart'; List defaultKeyEventHandlers = [ @@ -21,4 +22,5 @@ List defaultKeyEventHandlers = [ updateTextStyleByCommandXHandler, whiteSpaceHandler, selectAllHandler, + pageUpDownHandler, ]; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/page_up_down_handler.dart b/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/page_up_down_handler.dart new file mode 100644 index 0000000000..5acdcdcb0d --- /dev/null +++ b/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/page_up_down_handler.dart @@ -0,0 +1,31 @@ +import 'package:flowy_editor/flowy_editor.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +double? getEditorHeight(EditorState editorState) { + final renderObj = + editorState.service.scrollServiceKey.currentContext?.findRenderObject(); + if (renderObj is RenderBox) { + return renderObj.size.height; + } + return null; +} + +FlowyKeyEventHandler pageUpDownHandler = (editorState, event) { + if (event.logicalKey == LogicalKeyboardKey.pageUp) { + final scrollHeight = getEditorHeight(editorState); + final scrollService = editorState.service.scrollService; + if (scrollHeight != null && scrollService != null) { + scrollService.scrollTo(scrollService.dy - scrollHeight); + } + return KeyEventResult.handled; + } else if (event.logicalKey == LogicalKeyboardKey.pageDown) { + final scrollHeight = getEditorHeight(editorState); + final scrollService = editorState.service.scrollService; + if (scrollHeight != null && scrollService != null) { + scrollService.scrollTo(scrollService.dy + scrollHeight); + } + return KeyEventResult.handled; + } + return KeyEventResult.ignored; +};