Compare commits

..

No commits in common. "34a41e72f89d03ed095beac596c11a84e0bbe201" and "3db934d6f948bce141ac3e38829099d733e4844b" have entirely different histories.

3 changed files with 12 additions and 37 deletions

View file

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

View file

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

View file

@ -276,10 +276,6 @@ 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 {
if (self.panels) |panels| {
if (self.get_panel(@typeName(view))) |w| {
@ -295,7 +291,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));
}
} else if (mode != .disable) {
const panels = try WidgetList.createH(self.allocator, self.widgets.plane, "panel", .{ .static = self.get_panel_height() });
const panels = try WidgetList.createH(self.allocator, self.widgets.plane, "panel", .{ .static = self.panel_height orelse self.box().h / 5 });
try self.widgets.add(panels.widget());
try panels.add(try view.create(self.allocator, self.widgets.plane));
self.panels = panels;
@ -319,10 +315,6 @@ fn is_panel_view_showing(self: *Self, comptime view: type) bool {
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 {
if (self.panels) |panels| {
self.widgets.remove(panels.widget());