refactor: simplify Plane/Widget usage
This commit is contained in:
parent
62cd53c0f3
commit
4145460012
15 changed files with 64 additions and 50 deletions
|
@ -115,7 +115,7 @@ pub fn Create(options: type) type {
|
|||
}
|
||||
if (tui.current().mini_mode) |*mini_mode| {
|
||||
mini_mode.text = self.file_path.items;
|
||||
mini_mode.cursor = tui.current().stdplane().egc_chunk_width(self.file_path.items, 0, 8);
|
||||
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 8);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ pub fn Create(options: type) type {
|
|||
defer {
|
||||
if (tui.current().mini_mode) |*mini_mode| {
|
||||
mini_mode.text = self.file_path.items;
|
||||
mini_mode.cursor = tui.current().stdplane().egc_chunk_width(self.file_path.items, 0, 8);
|
||||
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 8);
|
||||
}
|
||||
}
|
||||
var count: usize = undefined;
|
||||
|
@ -243,7 +243,7 @@ pub fn Create(options: type) type {
|
|||
fn update_mini_mode_text(self: *Self) void {
|
||||
if (tui.current().mini_mode) |*mini_mode| {
|
||||
mini_mode.text = self.file_path.items;
|
||||
mini_mode.cursor = tui.current().stdplane().egc_chunk_width(self.file_path.items, 0, 8);
|
||||
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,7 +273,7 @@ pub fn Create(options: type) type {
|
|||
pub fn mini_mode_delete_backwards(self: *Self, _: Ctx) Result {
|
||||
if (self.file_path.items.len > 0) {
|
||||
self.complete_trigger_count = 0;
|
||||
self.file_path.shrinkRetainingCapacity(self.file_path.items.len - tui.current().stdplane().egc_last(self.file_path.items).len);
|
||||
self.file_path.shrinkRetainingCapacity(self.file_path.items.len - tui.egc_last(self.file_path.items).len);
|
||||
}
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ fn load_history(self: *Self, pos: usize) void {
|
|||
fn update_mini_mode_text(self: *Self) void {
|
||||
if (tui.current().mini_mode) |*mini_mode| {
|
||||
mini_mode.text = self.input.items;
|
||||
mini_mode.cursor = tui.current().stdplane().egc_chunk_width(self.input.items, 0, 8);
|
||||
mini_mode.cursor = tui.egc_chunk_width(self.input.items, 0, 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ const cmds = struct {
|
|||
pub const mini_mode_insert_bytes_meta = .{ .arguments = &.{.string} };
|
||||
|
||||
pub fn mini_mode_delete_backwards(self: *Self, _: Ctx) Result {
|
||||
self.input.resize(self.input.items.len - tui.current().stdplane().egc_last(self.input.items).len) catch {};
|
||||
self.input.resize(self.input.items.len - tui.egc_last(self.input.items).len) catch {};
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_delete_backwards_meta = .{ .description = "Delete backwards" };
|
||||
|
|
|
@ -83,7 +83,7 @@ fn start_query(self: *Self) !void {
|
|||
fn update_mini_mode_text(self: *Self) void {
|
||||
if (tui.current().mini_mode) |*mini_mode| {
|
||||
mini_mode.text = self.input;
|
||||
mini_mode.cursor = tui.current().stdplane().egc_chunk_width(self.input, 0, 8);
|
||||
mini_mode.cursor = tui.egc_chunk_width(self.input, 0, 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ const cmds = struct {
|
|||
pub const mini_mode_insert_bytes_meta = .{ .arguments = &.{.string} };
|
||||
|
||||
pub fn mini_mode_delete_backwards(self: *Self, _: Ctx) Result {
|
||||
self.input = self.input[0 .. self.input.len - tui.current().stdplane().egc_last(self.input).len];
|
||||
self.input = self.input[0 .. self.input.len - tui.egc_last(self.input).len];
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_delete_backwards_meta = .{ .description = "Delete backwards" };
|
||||
|
|
|
@ -54,7 +54,7 @@ fn update_mini_mode_text(self: *Self) void {
|
|||
(fmt.bufPrint(&self.buf, "{d}", .{linenum}) catch "")
|
||||
else
|
||||
"";
|
||||
mini_mode.cursor = tui.current().stdplane().egc_chunk_width(mini_mode.text, 0, 8);
|
||||
mini_mode.cursor = tui.egc_chunk_width(mini_mode.text, 0, 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ pub fn create(allocator: std.mem.Allocator) !tui.Mode {
|
|||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.modal = try ModalBackground.create(*Self, allocator, tui.current().mainview, .{ .ctx = self }),
|
||||
.menu = try Menu.create(*Self, allocator, tui.current().mainview, .{
|
||||
.menu = try Menu.create(*Self, allocator, tui.plane(), .{
|
||||
.ctx = self,
|
||||
.on_render = on_render_menu,
|
||||
.on_resize = on_resize_menu,
|
||||
|
@ -231,14 +231,14 @@ fn delete_word(self: *Self) !void {
|
|||
} else {
|
||||
self.inputbox.text.shrinkRetainingCapacity(0);
|
||||
}
|
||||
self.inputbox.cursor = tui.current().stdplane().egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
return self.start_query();
|
||||
}
|
||||
|
||||
fn delete_code_point(self: *Self) !void {
|
||||
if (self.inputbox.text.items.len > 0) {
|
||||
self.inputbox.text.shrinkRetainingCapacity(self.inputbox.text.items.len - tui.current().stdplane().egc_last(self.inputbox.text.items).len);
|
||||
self.inputbox.cursor = tui.current().stdplane().egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
self.inputbox.text.shrinkRetainingCapacity(self.inputbox.text.items.len - tui.egc_last(self.inputbox.text.items).len);
|
||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
}
|
||||
return self.start_query();
|
||||
}
|
||||
|
@ -247,13 +247,13 @@ fn insert_code_point(self: *Self, c: u32) !void {
|
|||
var buf: [6]u8 = undefined;
|
||||
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
|
||||
try self.inputbox.text.appendSlice(buf[0..bytes]);
|
||||
self.inputbox.cursor = tui.current().stdplane().egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
return self.start_query();
|
||||
}
|
||||
|
||||
fn insert_bytes(self: *Self, bytes: []const u8) !void {
|
||||
try self.inputbox.text.appendSlice(bytes);
|
||||
self.inputbox.cursor = tui.current().stdplane().egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
return self.start_query();
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ pub fn Create(options: type) type {
|
|||
.ctx = self,
|
||||
.on_click = mouse_palette_menu_cancel,
|
||||
}),
|
||||
.menu = try Menu.create(*Self, allocator, tui.current().mainview, .{
|
||||
.menu = try Menu.create(*Self, allocator, tui.plane(), .{
|
||||
.ctx = self,
|
||||
.on_render = if (@hasDecl(options, "on_render_menu")) options.on_render_menu else on_render_menu,
|
||||
.on_resize = on_resize_menu,
|
||||
|
@ -307,15 +307,15 @@ pub fn Create(options: type) type {
|
|||
} else {
|
||||
self.inputbox.text.shrinkRetainingCapacity(0);
|
||||
}
|
||||
self.inputbox.cursor = tui.current().stdplane().egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
self.view_pos = 0;
|
||||
return self.start_query(0);
|
||||
}
|
||||
|
||||
fn delete_code_point(self: *Self) !void {
|
||||
if (self.inputbox.text.items.len > 0) {
|
||||
self.inputbox.text.shrinkRetainingCapacity(self.inputbox.text.items.len - tui.current().stdplane().egc_last(self.inputbox.text.items).len);
|
||||
self.inputbox.cursor = tui.current().stdplane().egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
self.inputbox.text.shrinkRetainingCapacity(self.inputbox.text.items.len - tui.egc_last(self.inputbox.text.items).len);
|
||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
}
|
||||
self.view_pos = 0;
|
||||
return self.start_query(0);
|
||||
|
@ -325,14 +325,14 @@ pub fn Create(options: type) type {
|
|||
var buf: [6]u8 = undefined;
|
||||
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
|
||||
try self.inputbox.text.appendSlice(buf[0..bytes]);
|
||||
self.inputbox.cursor = tui.current().stdplane().egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
self.view_pos = 0;
|
||||
return self.start_query(0);
|
||||
}
|
||||
|
||||
fn insert_bytes(self: *Self, bytes: []const u8) !void {
|
||||
try self.inputbox.text.appendSlice(bytes);
|
||||
self.inputbox.cursor = tui.current().stdplane().egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||
self.view_pos = 0;
|
||||
return self.start_query(0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue