Fix half and whole page movements
This commit is contained in:
parent
5300e3346d
commit
a21f0e6ac5
3 changed files with 91 additions and 6 deletions
|
@ -103,6 +103,24 @@ pub fn move_page_down(self: *Self, root: Buffer.Root, view: *const View, metrics
|
|||
self.move_right_no_target(root, metrics) catch return;
|
||||
}
|
||||
|
||||
pub fn move_half_page_up(self: *Self, root: Buffer.Root, view: *const View, metrics: Metrics) void {
|
||||
const half_view_rows = @divTrunc(view.rows, 2);
|
||||
self.row = if (self.row > half_view_rows) self.row - half_view_rows else 0;
|
||||
self.follow_target(root, metrics);
|
||||
self.move_left_no_target(root, metrics) catch return;
|
||||
self.move_right_no_target(root, metrics) catch return;
|
||||
}
|
||||
|
||||
pub fn move_half_page_down(self: *Self, root: Buffer.Root, view: *const View, metrics: Metrics) void {
|
||||
const half_view_rows = @divTrunc(view.rows, 2);
|
||||
if (root.lines() > self.row + half_view_rows) {
|
||||
self.row += half_view_rows;
|
||||
} else self.move_buffer_last(root, metrics);
|
||||
self.follow_target(root, metrics);
|
||||
self.move_left_no_target(root, metrics) catch return;
|
||||
self.move_right_no_target(root, metrics) catch return;
|
||||
}
|
||||
|
||||
pub fn move_to(self: *Self, root: Buffer.Root, row: usize, col: usize, metrics: Metrics) !void {
|
||||
if (row < root.lines()) {
|
||||
self.row = row;
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
"press": [
|
||||
["ctrl+b", "move_scroll_page_up"],
|
||||
["ctrl+f", "move_scroll_page_down"],
|
||||
["ctrl+u", "page_cursor_half_up"],
|
||||
["ctrl+d", "page_cursor_half_down"],
|
||||
["ctrl+u", "move_scroll_half_page_up"],
|
||||
["ctrl+d", "move_scroll_half_page_down"],
|
||||
["ctrl+c", "toggle_comment"],
|
||||
["ctrl+i", "jump_forward"],
|
||||
["ctrl+o", "jump_back"],
|
||||
|
@ -253,10 +253,10 @@
|
|||
"line_numbers": "relative",
|
||||
"cursor": "block",
|
||||
"press": [
|
||||
["ctrl+b", "move_scroll_page_up"],
|
||||
["ctrl+f", "move_scroll_page_down"],
|
||||
["ctrl+u", "page_cursor_half_up"],
|
||||
["ctrl+d", "page_cursor_half_down"],
|
||||
["ctrl+b", "select_page_up"],
|
||||
["ctrl+f", "select_page_down"],
|
||||
["ctrl+u", "select_half_page_up"],
|
||||
["ctrl+d", "select_half_page_down"],
|
||||
|
||||
["ctrl+c", "toggle_comment"],
|
||||
|
||||
|
|
|
@ -1955,6 +1955,14 @@ pub const Editor = struct {
|
|||
cursor.move_page_down(root, view, metrics);
|
||||
}
|
||||
|
||||
fn move_cursor_half_page_up(root: Buffer.Root, cursor: *Cursor, view: *const View, metrics: Buffer.Metrics) !void {
|
||||
cursor.move_half_page_up(root, view, metrics);
|
||||
}
|
||||
|
||||
fn move_cursor_half_page_down(root: Buffer.Root, cursor: *Cursor, view: *const View, metrics: Buffer.Metrics) !void {
|
||||
cursor.move_half_page_down(root, view, metrics);
|
||||
}
|
||||
|
||||
pub fn primary_click(self: *Self, y: c_int, x: c_int) !void {
|
||||
if (self.fast_scroll)
|
||||
try self.push_cursor()
|
||||
|
@ -2889,6 +2897,30 @@ pub const Editor = struct {
|
|||
}
|
||||
pub const move_scroll_page_down_meta = .{ .description = "Move and scroll page down" };
|
||||
|
||||
pub fn move_scroll_half_page_up(self: *Self, _: Context) Result {
|
||||
if (self.screen_cursor(&self.get_primary().cursor)) |cursor| {
|
||||
const root = try self.buf_root();
|
||||
self.with_cursors_and_view_const(root, move_cursor_half_page_up, &self.view) catch {};
|
||||
const new_cursor_row = self.get_primary().cursor.row;
|
||||
self.update_scroll_dest_abs(if (cursor.row > new_cursor_row) 0 else new_cursor_row - cursor.row);
|
||||
} else {
|
||||
return self.move_half_page_up(.{});
|
||||
}
|
||||
}
|
||||
pub const move_scroll_half_page_up_meta = .{ .description = "Move and scroll half a page up" };
|
||||
|
||||
pub fn move_scroll_half_page_down(self: *Self, _: Context) Result {
|
||||
if (self.screen_cursor(&self.get_primary().cursor)) |cursor| {
|
||||
const root = try self.buf_root();
|
||||
self.with_cursors_and_view_const(root, move_cursor_half_page_down, &self.view) catch {};
|
||||
const new_cursor_row = self.get_primary().cursor.row;
|
||||
self.update_scroll_dest_abs(if (cursor.row > new_cursor_row) 0 else new_cursor_row - cursor.row);
|
||||
} else {
|
||||
return self.move_half_page_down(.{});
|
||||
}
|
||||
}
|
||||
pub const move_scroll_half_page_down_meta = .{ .description = "Move and scroll half a page down" };
|
||||
|
||||
pub fn smart_move_begin(self: *Self, _: Context) Result {
|
||||
const root = try self.buf_root();
|
||||
try self.with_cursors_const(root, smart_move_cursor_begin);
|
||||
|
@ -2927,6 +2959,23 @@ pub const Editor = struct {
|
|||
}
|
||||
pub const move_page_down_meta = .{ .description = "Move cursor page down" };
|
||||
|
||||
pub fn move_half_page_up(self: *Self, _: Context) Result {
|
||||
try self.send_editor_jump_source();
|
||||
const root = try self.buf_root();
|
||||
try self.with_cursors_and_view_const(root, move_cursor_page_up, &self.view);
|
||||
self.clamp();
|
||||
}
|
||||
pub const move_half_page_up_meta = .{ .description = "Move cursor half a page up" };
|
||||
|
||||
pub fn move_half_page_down(self: *Self, _: Context) Result {
|
||||
try self.send_editor_jump_source();
|
||||
const root = try self.buf_root();
|
||||
try self.with_cursors_and_view_const(root, move_cursor_page_down, &self.view);
|
||||
self.clamp();
|
||||
try self.send_editor_jump_destination();
|
||||
}
|
||||
pub const move_half_page_down_meta = .{ .description = "Move cursor half a page down" };
|
||||
|
||||
pub fn move_buffer_begin(self: *Self, _: Context) Result {
|
||||
try self.send_editor_jump_source();
|
||||
self.cancel_all_selections();
|
||||
|
@ -3095,6 +3144,24 @@ pub const Editor = struct {
|
|||
}
|
||||
pub const select_page_down_meta = .{ .description = "Select page down" };
|
||||
|
||||
pub fn select_half_page_up(self: *Self, _: Context) Result {
|
||||
try self.send_editor_jump_source();
|
||||
const root = try self.buf_root();
|
||||
try self.with_selections_and_view_const(root, move_cursor_half_page_up, &self.view);
|
||||
self.clamp();
|
||||
try self.send_editor_jump_destination();
|
||||
}
|
||||
pub const select_half_page_up_meta = .{ .description = "Select half a page up" };
|
||||
|
||||
pub fn select_half_page_down(self: *Self, _: Context) Result {
|
||||
try self.send_editor_jump_source();
|
||||
const root = try self.buf_root();
|
||||
try self.with_selections_and_view_const(root, move_cursor_half_page_down, &self.view);
|
||||
self.clamp();
|
||||
try self.send_editor_jump_destination();
|
||||
}
|
||||
pub const select_half_page_down_meta = .{ .description = "Select half a page down" };
|
||||
|
||||
pub fn select_all(self: *Self, _: Context) Result {
|
||||
try self.send_editor_jump_source();
|
||||
self.cancel_all_selections();
|
||||
|
|
Loading…
Add table
Reference in a new issue