feat: allow next/previous sibling functions to work with no selection

This commit is contained in:
CJ van den Berg 2025-09-22 12:58:42 +02:00
parent 8100e7d52b
commit 1ef77601e3
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -4397,8 +4397,7 @@ pub const Editor = struct {
pub const shrink_selection_meta: Meta = .{ .description = "Shrink selection to first AST child node" };
fn select_next_sibling_node(self: *Self, root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
const sel = (try cursel.enable_selection(root, metrics)).*;
const node = try self.top_node_at_selection(sel, root, metrics);
const node = try self.top_node_at_cursel(cursel, root, metrics);
if (node.isNull()) return error.Stop;
const sibling = syntax.Node.externs.ts_node_next_sibling(node);
if (sibling.isNull()) return error.Stop;
@ -4406,8 +4405,7 @@ pub const Editor = struct {
}
fn select_next_named_sibling_node(self: *Self, root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
const sel = (try cursel.enable_selection(root, metrics)).*;
const node = try self.top_node_at_selection(sel, root, metrics);
const node = try self.top_node_at_cursel(cursel, root, metrics);
if (node.isNull()) return error.Stop;
const sibling = syntax.Node.externs.ts_node_next_named_sibling(node);
if (sibling.isNull()) return error.Stop;
@ -4421,7 +4419,6 @@ pub const Editor = struct {
const root = try self.buf_root();
const cursel = self.get_primary();
cursel.check_selection(root, self.metrics);
if (cursel.selection) |_|
try if (unnamed)
self.select_next_sibling_node(root, cursel, self.metrics)
else
@ -4432,8 +4429,7 @@ pub const Editor = struct {
pub const select_next_sibling_meta: Meta = .{ .description = "Move selection to next AST sibling node" };
fn select_prev_sibling_node(self: *Self, root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
const sel = (try cursel.enable_selection(root, metrics)).*;
const node = try self.top_node_at_selection(sel, root, metrics);
const node = try self.top_node_at_cursel(cursel, root, metrics);
if (node.isNull()) return error.Stop;
const sibling = syntax.Node.externs.ts_node_prev_sibling(node);
if (sibling.isNull()) return error.Stop;
@ -4441,8 +4437,7 @@ pub const Editor = struct {
}
fn select_prev_named_sibling_node(self: *Self, root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
const sel = (try cursel.enable_selection(root, metrics)).*;
const node = try self.top_node_at_selection(sel, root, metrics);
const node = try self.top_node_at_cursel(cursel, root, metrics);
if (node.isNull()) return error.Stop;
const sibling = syntax.Node.externs.ts_node_prev_named_sibling(node);
if (sibling.isNull()) return error.Stop;
@ -4456,7 +4451,6 @@ pub const Editor = struct {
const root = try self.buf_root();
const cursel = self.get_primary();
cursel.check_selection(root, self.metrics);
if (cursel.selection) |_|
try if (unnamed)
self.select_prev_sibling_node(root, cursel, self.metrics)
else