Compare commits
5 commits
bca4dbf777
...
fc6f2e2cde
| Author | SHA1 | Date | |
|---|---|---|---|
| fc6f2e2cde | |||
| db8bd0840f | |||
| 8c0eac80cf | |||
| f49d6a7423 | |||
| f3440d4f83 |
2 changed files with 21 additions and 24 deletions
|
|
@ -2626,7 +2626,7 @@ pub const Editor = struct {
|
|||
self.view.row = row;
|
||||
}
|
||||
|
||||
fn update_scroll_dest_abs(self: *Self, dest: usize) void {
|
||||
pub fn update_scroll_dest_abs(self: *Self, dest: usize) void {
|
||||
const root = self.buf_root() catch return;
|
||||
const max_view = if (root.lines() <= scroll_cursor_min_border_distance) 0 else root.lines() - scroll_cursor_min_border_distance;
|
||||
self.scroll_dest = @min(dest, max_view);
|
||||
|
|
@ -5713,32 +5713,27 @@ pub const Editor = struct {
|
|||
|
||||
pub fn focus_on_range(self: *Self, ctx: Context) Result {
|
||||
var sel: Selection = .{};
|
||||
var pos_type: PosType = .column;
|
||||
if (!try ctx.args.match(.{
|
||||
tp.extract(&sel.begin.row),
|
||||
tp.extract(&sel.begin.col),
|
||||
tp.extract(&sel.end.row),
|
||||
tp.extract(&sel.end.col),
|
||||
tp.extract(&pos_type),
|
||||
})) return error.InvalidFocusOnRangeArgument;
|
||||
|
||||
self.cancel_all_selections();
|
||||
const root = self.buf_root() catch return;
|
||||
if (pos_type == .byte)
|
||||
sel = sel.from_pos(root, self.metrics) catch return;
|
||||
const primary = self.get_primary();
|
||||
try primary.cursor.move_to(
|
||||
root,
|
||||
sel.begin.row,
|
||||
sel.begin.col,
|
||||
self.metrics,
|
||||
);
|
||||
primary.selection = sel;
|
||||
if (self.view.is_visible(&primary.cursor))
|
||||
self.clamp()
|
||||
self.cancel_all_matches();
|
||||
self.add_match_internal(sel.begin.row + 1, sel.begin.col, sel.end.row + 1, sel.end.col);
|
||||
const cursor = sel.begin;
|
||||
const range_height = sel.end.row - sel.begin.row + 1;
|
||||
const view_height = self.view.rows;
|
||||
const offset = if (range_height > view_height - @min(view_height, scroll_cursor_min_border_distance * 2))
|
||||
scroll_cursor_min_border_distance
|
||||
else
|
||||
try self.scroll_view_center(.{});
|
||||
self.need_render();
|
||||
(view_height / 2) - (range_height / 2);
|
||||
const row = if (cursor.row > offset)
|
||||
cursor.row - offset
|
||||
else
|
||||
0;
|
||||
self.update_scroll_dest_abs(row);
|
||||
}
|
||||
pub const focus_on_range_meta: Meta = .{ .arguments = &.{ .integer, .integer, .integer, .integer } };
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ pub const Entry = struct {
|
|||
|
||||
pub const ValueType = struct {
|
||||
start: ed.CurSel = .{},
|
||||
view: ed.View = .{},
|
||||
column_size: [3]u8 = undefined,
|
||||
};
|
||||
pub const defaultValue: ValueType = .{};
|
||||
|
|
@ -99,6 +100,7 @@ pub fn load_entries(palette: *Type) !usize {
|
|||
var max_label_len: usize = 0;
|
||||
|
||||
palette.value.start = editor.get_primary().*;
|
||||
palette.value.view = editor.view;
|
||||
var iter: []const u8 = mv.symbols.items;
|
||||
init_col_sizes(palette);
|
||||
while (iter.len > 0) {
|
||||
|
|
@ -194,8 +196,6 @@ fn find_closest(palette: *Type) ?usize {
|
|||
var previous: usize = 0;
|
||||
for (palette.entries.items, 0..) |entry, idx| {
|
||||
_, _, _, const sel = get_values(entry.cbor);
|
||||
if (cursor.within(sel))
|
||||
return idx + 1;
|
||||
if (cursor.row < sel.begin.row) return previous + 1;
|
||||
previous = idx;
|
||||
}
|
||||
|
|
@ -203,6 +203,8 @@ fn find_closest(palette: *Type) ?usize {
|
|||
}
|
||||
|
||||
fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void {
|
||||
const editor = tui.get_active_editor() orelse return;
|
||||
editor.clear_matches();
|
||||
_, _, _, const sel = get_values(button.opts.label);
|
||||
tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
|
||||
tp.self_pid().send(.{ "cmd", "goto_line_and_column", .{ sel.begin.row + 1, sel.begin.col + 1 } }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
|
||||
|
|
@ -211,13 +213,13 @@ fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void {
|
|||
pub fn updated(palette: *Type, button_: ?*Type.ButtonType) !void {
|
||||
const button = button_ orelse return cancel(palette);
|
||||
_, _, _, const sel = get_values(button.opts.label);
|
||||
tp.self_pid().send(.{ "cmd", "focus_on_range", .{ sel.begin.row, sel.begin.col, sel.end.row, sel.end.col, ed.PosType.byte } }) catch {};
|
||||
tp.self_pid().send(.{ "cmd", "focus_on_range", .{ sel.begin.row, sel.begin.col, sel.end.row, sel.end.col } }) catch {};
|
||||
}
|
||||
|
||||
pub fn cancel(palette: *Type) !void {
|
||||
tp.self_pid().send(.{ "cmd", "goto_line_and_column", .{ palette.value.start.cursor.row + 1, palette.value.start.cursor.col + 1 } }) catch return;
|
||||
const editor = tui.get_active_editor() orelse return;
|
||||
editor.get_primary().selection = palette.value.start.selection;
|
||||
editor.clear_matches();
|
||||
editor.update_scroll_dest_abs(palette.value.view.row);
|
||||
}
|
||||
|
||||
const SymbolKind = enum(u8) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue