mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: page up down handler
This commit is contained in:
parent
c42f9001c4
commit
716d1f93e7
@ -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,
|
||||
];
|
||||
|
@ -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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user