vim: change cursor shape when only one cursor
In vim mode, change the cursor shape depending on the mode. This is only applicable if `enable_terminal_cursor` is set to true and there is only one cursor in the editor.
This commit is contained in:
parent
b115d55097
commit
d4b7a6ab9b
6 changed files with 14 additions and 2 deletions
|
@ -765,7 +765,11 @@ pub const Editor = struct {
|
|||
fn render_terminal_cursor(self: *const Self, cursor_: *const Cursor) !void {
|
||||
if (self.screen_cursor(cursor_)) |cursor| {
|
||||
const y, const x = self.plane.rel_yx_to_abs(@intCast(cursor.row), @intCast(cursor.col));
|
||||
tui.current().rdr.cursor_enable(y, x) catch {};
|
||||
const shape = if (tui.current().input_mode) |mode|
|
||||
mode.cursor_shape
|
||||
else
|
||||
.block;
|
||||
tui.current().rdr.cursor_enable(y, x, shape) catch {};
|
||||
} else {
|
||||
tui.current().rdr.cursor_disable();
|
||||
}
|
||||
|
@ -774,6 +778,8 @@ pub const Editor = struct {
|
|||
fn render_cursors(self: *Self, theme: *const Widget.Theme) !void {
|
||||
const frame = tracy.initZone(@src(), .{ .name = "editor render cursors" });
|
||||
defer frame.deinit();
|
||||
if (self.cursels.items.len == 1 and self.enable_terminal_cursor)
|
||||
return self.render_terminal_cursor(&self.get_primary().cursor);
|
||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel|
|
||||
try self.render_cursor(&cursel.cursor, theme);
|
||||
if (self.enable_terminal_cursor)
|
||||
|
|
|
@ -35,6 +35,7 @@ pub fn create(a: Allocator) !tui.Mode {
|
|||
.name = "INSERT",
|
||||
.description = "vim",
|
||||
.line_numbers = if (tui.current().config.vim_insert_gutter_line_numbers_relative) .relative else .absolute,
|
||||
.cursor_shape = .beam,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ pub fn create(a: Allocator) !tui.Mode {
|
|||
.description = "vim",
|
||||
.line_numbers = if (tui.current().config.vim_normal_gutter_line_numbers_relative) .relative else .absolute,
|
||||
.keybind_hints = &hints,
|
||||
.cursor_shape = .block,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ pub fn create(a: Allocator) !tui.Mode {
|
|||
.description = "vim",
|
||||
.line_numbers = if (tui.current().config.vim_visual_gutter_line_numbers_relative) .relative else .absolute,
|
||||
.keybind_hints = &hints,
|
||||
.cursor_shape = .underline,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -717,6 +717,7 @@ pub const Mode = struct {
|
|||
description: []const u8,
|
||||
line_numbers: enum { absolute, relative } = .absolute,
|
||||
keybind_hints: ?*const KeybindHints = null,
|
||||
cursor_shape: renderer.CursorShape = .block,
|
||||
|
||||
fn deinit(self: *Mode) void {
|
||||
self.handler.deinit();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue