Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions lib/src/_code_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,38 @@ class _CodeLineEditingControllerImpl extends ValueNotifier<CodeLineEditingValue>

@override
void moveCursorToPageUp() {
// TODO
_moveCursorByPage(false);
}

@override
void moveCursorToPageDown() {
// TODO
_moveCursorByPage(true);
}

/// Moves the cursor a screen up or down.
///
/// The page is measured from the viewport: as many lines as fit on screen,
/// less one kept as an overlap so that the reader can connect what was on
/// screen with what is there now. With word wrap on, a wrapped line still
/// counts as one, so the jump may be longer than a screen.
void _moveCursorByPage(bool forward) {
final _CodeFieldRender? render = _render;
if (render == null || !render.hasSize || render.lineHeight <= 0) {
// Nothing is laid out yet, so there is no page to measure. Moving by a
// single line is still better than standing still.
moveCursor(forward ? AxisDirection.down : AxisDirection.up);
return;
}

final int page = max(1, (render.size.height / render.lineHeight).floor() - 1);
final CodeLinePosition current = selection.extent;
final int index = min(max(0, current.index + (forward ? page : -page)), codeLines.length - 1);

selection = CodeLineSelection.collapsed(
index: index,
offset: min(codeLines[index].length, current.offset)
);
makeCursorVisible();
}

@override
Expand Down
12 changes: 12 additions & 0 deletions lib/src/code_shortcuts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ const Map<CodeShortcutType, List<ShortcutActivator>> _kDefaultMacCodeShortcutsAc
SingleActivator(LogicalKeyboardKey.arrowDown, meta: true),
SingleActivator(LogicalKeyboardKey.end, control: true)
],
CodeShortcutType.cursorMovePageUp: [
SingleActivator(LogicalKeyboardKey.pageUp)
],
CodeShortcutType.cursorMovePageDown: [
SingleActivator(LogicalKeyboardKey.pageDown)
],
CodeShortcutType.cursorMoveWordBoundaryBackward: [
SingleActivator(LogicalKeyboardKey.arrowLeft, alt: true)
],
Expand Down Expand Up @@ -535,6 +541,12 @@ const Map<CodeShortcutType, List<ShortcutActivator>> _kDefaultCommonCodeShortcut
// NumLockedSingleActivator(LogicalKeyboardKey.numpad1, shift: true, control: true),
// NumUnlockedSingleActivator(LogicalKeyboardKey.numpad1, control: true),
],
CodeShortcutType.cursorMovePageUp: [
SingleActivator(LogicalKeyboardKey.pageUp),
],
CodeShortcutType.cursorMovePageDown: [
SingleActivator(LogicalKeyboardKey.pageDown),
],
CodeShortcutType.cursorMoveWordBoundaryBackward: [
SingleActivator(LogicalKeyboardKey.arrowLeft, control: true),
// NumLockedSingleActivator(LogicalKeyboardKey.numpad4, shift: true, control: true),
Expand Down