surface should default to default cursor, blinking should check selected

This commit is contained in:
Mitchell Hashimoto
2023-08-30 08:12:38 -07:00
parent e9f94bab21
commit e2fae7ab2b
3 changed files with 19 additions and 7 deletions

View File

@ -415,7 +415,7 @@ pub fn init(
.renderer_state = .{ .renderer_state = .{
.mutex = mutex, .mutex = mutex,
.cursor = .{ .cursor = .{
.style = .blinking_block, .style = .default,
.visible = true, .visible = true,
}, },
.terminal = &self.io.terminal, .terminal = &self.io.terminal,

View File

@ -475,6 +475,14 @@ pub fn render(
return; return;
} }
// If the terminal state isn't requesting any particular style,
// then use the configured style.
const selected_cursor_style = style: {
if (state.cursor.style != .default) break :style state.cursor.style;
if (self.config.cursor_style != .default) break :style self.config.cursor_style;
break :style .blinking_block;
};
self.cursor_visible = visible: { self.cursor_visible = visible: {
// If the cursor is explicitly not visible in the state, // If the cursor is explicitly not visible in the state,
// then it is not visible. // then it is not visible.
@ -484,7 +492,7 @@ pub fn render(
if (state.preedit != null) break :visible true; if (state.preedit != null) break :visible true;
// If the cursor isn't a blinking style, then never blink. // If the cursor isn't a blinking style, then never blink.
if (!state.cursor.style.blinking()) break :visible true; if (!selected_cursor_style.blinking()) break :visible true;
// Otherwise, adhere to our current state. // Otherwise, adhere to our current state.
break :visible self.cursor_visible; break :visible self.cursor_visible;
@ -499,8 +507,6 @@ pub fn render(
// If we aren't focused, we use a hollow box // If we aren't focused, we use a hollow box
if (!self.focused) break :cursor_style .box_hollow; if (!self.focused) break :cursor_style .box_hollow;
const selected_cursor_style = if (state.cursor.style == .default) self.config.cursor_style else state.cursor.style;
break :cursor_style renderer.CursorStyle.fromTerminal(selected_cursor_style) orelse .box; break :cursor_style renderer.CursorStyle.fromTerminal(selected_cursor_style) orelse .box;
}; };
} }

View File

@ -717,6 +717,14 @@ pub fn render(
return; return;
} }
// If the terminal state isn't requesting any particular style,
// then use the configured style.
const selected_cursor_style = style: {
if (state.cursor.style != .default) break :style state.cursor.style;
if (self.config.cursor_style != .default) break :style self.config.cursor_style;
break :style .blinking_block;
};
self.cursor_visible = visible: { self.cursor_visible = visible: {
// If the cursor is explicitly not visible in the state, // If the cursor is explicitly not visible in the state,
// then it is not visible. // then it is not visible.
@ -726,7 +734,7 @@ pub fn render(
if (state.preedit != null) break :visible true; if (state.preedit != null) break :visible true;
// If the cursor isn't a blinking style, then never blink. // If the cursor isn't a blinking style, then never blink.
if (!state.cursor.style.blinking()) break :visible true; if (!selected_cursor_style.blinking()) break :visible true;
// Otherwise, adhere to our current state. // Otherwise, adhere to our current state.
break :visible self.cursor_visible; break :visible self.cursor_visible;
@ -741,8 +749,6 @@ pub fn render(
// If we aren't focused, we use a hollow box // If we aren't focused, we use a hollow box
if (!self.focused) break :cursor_style .box_hollow; if (!self.focused) break :cursor_style .box_hollow;
const selected_cursor_style = if (state.cursor.style == .default) self.config.cursor_style else state.cursor.style;
break :cursor_style renderer.CursorStyle.fromTerminal(selected_cursor_style) orelse .box; break :cursor_style renderer.CursorStyle.fromTerminal(selected_cursor_style) orelse .box;
}; };
} }