Compare commits

...

3 commits

3 changed files with 37 additions and 12 deletions

View file

@ -92,22 +92,23 @@ inline fn to_cursor_bottom(self: *const Self, root: Buffer.Root) Cursor {
return .{ .row = bottom, .col = 0 }; return .{ .row = bottom, .col = 0 };
} }
fn clamp_row(self: *Self, cursor: *const Cursor, abs: bool) void { fn clamp_row(self: *Self, cursor: *const Cursor, abs: bool, bottom_offset: usize) void {
const min_border_distance: usize = if (abs) scroll_cursor_min_border_distance_mouse else scroll_cursor_min_border_distance; const top_min_border_distance: usize = if (abs) scroll_cursor_min_border_distance_mouse else scroll_cursor_min_border_distance;
if (cursor.row < min_border_distance) { const bottom_min_border_distance: usize = top_min_border_distance + bottom_offset;
if (cursor.row < top_min_border_distance) {
self.row = 0; self.row = 0;
return; return;
} }
if (self.row > 0 and cursor.row >= min_border_distance) { if (self.row > 0 and cursor.row >= top_min_border_distance) {
if (cursor.row < self.row + min_border_distance) { if (cursor.row < self.row + top_min_border_distance) {
self.row = cursor.row - min_border_distance; self.row = cursor.row - top_min_border_distance;
return; return;
} }
} }
if (cursor.row < self.row) { if (cursor.row < self.row) {
self.row = 0; self.row = 0;
} else if (cursor.row > self.row + self.rows - min_border_distance) { } else if (cursor.row > self.row + self.rows - bottom_min_border_distance) {
self.row = cursor.row + min_border_distance - self.rows; self.row = cursor.row + bottom_min_border_distance - self.rows;
} }
} }
@ -120,7 +121,12 @@ fn clamp_col(self: *Self, cursor: *const Cursor, _: bool) void {
} }
pub fn clamp(self: *Self, cursor: *const Cursor, abs: bool) void { pub fn clamp(self: *Self, cursor: *const Cursor, abs: bool) void {
self.clamp_row(cursor, abs); self.clamp_row(cursor, abs, 0);
self.clamp_col(cursor, abs);
}
pub fn clamp_offset(self: *Self, cursor: *const Cursor, abs: bool, offset: usize) void {
self.clamp_row(cursor, abs, offset);
self.clamp_col(cursor, abs); self.clamp_col(cursor, abs);
} }

View file

@ -1914,17 +1914,25 @@ pub const Editor = struct {
_ = try self.handlers.msg(.{ "E", "eol_mode", eol_mode, utf8_sanitized, indent_mode }); _ = try self.handlers.msg(.{ "E", "eol_mode", eol_mode, utf8_sanitized, indent_mode });
} }
fn clamp_abs(self: *Self, abs: bool) void { fn clamp_abs_offset(self: *Self, abs: bool, offset: usize) void {
var dest: View = self.view; var dest: View = self.view;
dest.clamp(&self.get_primary().cursor, abs); dest.clamp_offset(&self.get_primary().cursor, abs, offset);
self.update_scroll_dest_abs(dest.row); self.update_scroll_dest_abs(dest.row);
self.view.col = dest.col; self.view.col = dest.col;
} }
fn clamp_abs(self: *Self, abs: bool) void {
self.clamp_abs_offset(abs, 0);
}
pub inline fn clamp(self: *Self) void { pub inline fn clamp(self: *Self) void {
self.clamp_abs(false); self.clamp_abs(false);
} }
inline fn clamp_offset(self: *Self, offset: usize) void {
self.clamp_abs_offset(false, offset);
}
fn clamp_mouse(self: *Self) void { fn clamp_mouse(self: *Self) void {
self.clamp_abs(true); self.clamp_abs(true);
} }
@ -6005,11 +6013,14 @@ pub const Editor = struct {
pub const references_meta: Meta = .{ .description = "Language: Find all references" }; pub const references_meta: Meta = .{ .description = "Language: Find all references" };
pub fn completion(self: *Self, _: Context) Result { pub fn completion(self: *Self, _: Context) Result {
const mv = tui.mainview() orelse return;
const file_path = self.file_path orelse return; const file_path = self.file_path orelse return;
const root = self.buf_root() catch return; const root = self.buf_root() catch return;
const primary = self.get_primary(); const primary = self.get_primary();
const col = try root.get_line_width_to_pos(primary.cursor.row, primary.cursor.col, self.metrics); const col = try root.get_line_width_to_pos(primary.cursor.row, primary.cursor.col, self.metrics);
self.completions.clearRetainingCapacity(); self.completions.clearRetainingCapacity();
if (!mv.is_any_panel_view_showing())
self.clamp_offset(mv.get_panel_height());
return project_manager.completion(file_path, primary.cursor.row, col); return project_manager.completion(file_path, primary.cursor.row, col);
} }
pub const completion_meta: Meta = .{ .description = "Language: Show completions at cursor" }; pub const completion_meta: Meta = .{ .description = "Language: Show completions at cursor" };

View file

@ -276,6 +276,10 @@ fn bottom_bar_primary_drag(self: *Self, y: usize) tp.result {
} }
} }
pub fn get_panel_height(self: *Self) usize {
return self.panel_height orelse self.box().h / 5;
}
fn toggle_panel_view(self: *Self, view: anytype, mode: enum { toggle, enable, disable }) !void { fn toggle_panel_view(self: *Self, view: anytype, mode: enum { toggle, enable, disable }) !void {
if (self.panels) |panels| { if (self.panels) |panels| {
if (self.get_panel(@typeName(view))) |w| { if (self.get_panel(@typeName(view))) |w| {
@ -291,7 +295,7 @@ fn toggle_panel_view(self: *Self, view: anytype, mode: enum { toggle, enable, di
try panels.add(try view.create(self.allocator, self.widgets.plane)); try panels.add(try view.create(self.allocator, self.widgets.plane));
} }
} else if (mode != .disable) { } else if (mode != .disable) {
const panels = try WidgetList.createH(self.allocator, self.widgets.plane, "panel", .{ .static = self.panel_height orelse self.box().h / 5 }); const panels = try WidgetList.createH(self.allocator, self.widgets.plane, "panel", .{ .static = self.get_panel_height() });
try self.widgets.add(panels.widget()); try self.widgets.add(panels.widget());
try panels.add(try view.create(self.allocator, self.widgets.plane)); try panels.add(try view.create(self.allocator, self.widgets.plane));
self.panels = panels; self.panels = panels;
@ -315,6 +319,10 @@ fn is_panel_view_showing(self: *Self, comptime view: type) bool {
return self.get_panel_view(view) != null; return self.get_panel_view(view) != null;
} }
pub fn is_any_panel_view_showing(self: *Self) bool {
return self.panels != null;
}
fn close_all_panel_views(self: *Self) void { fn close_all_panel_views(self: *Self) void {
if (self.panels) |panels| { if (self.panels) |panels| {
self.widgets.remove(panels.widget()); self.widgets.remove(panels.widget());