feat: page up down handler

This commit is contained in:
Vincent Chan 2022-08-11 17:21:02 +08:00
parent c42f9001c4
commit 716d1f93e7
2 changed files with 33 additions and 0 deletions

View File

@ -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<FlowyKeyEventHandler> defaultKeyEventHandlers = [
@ -21,4 +22,5 @@ List<FlowyKeyEventHandler> defaultKeyEventHandlers = [
updateTextStyleByCommandXHandler,
whiteSpaceHandler,
selectAllHandler,
pageUpDownHandler,
];

View File

@ -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;
};