refactor: completely remove inclusive selection mode

Having inclusive mode change a few critical functions behind the sceans
is not a good way to share functionality. Basically every function is
broken in one or the other mode. So we remove it entirely and instead
will rely on different functions for different behaviors.
This commit is contained in:
CJ van den Berg 2025-11-27 17:22:58 +01:00
parent b8e9f981f2
commit a5c360a2ec
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
7 changed files with 75 additions and 111 deletions

View file

@ -226,7 +226,7 @@ const cmds_ = struct {
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
while (repeat > 0) : (repeat -= 1) {
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
const sel = cursel.enable_selection_normal();
const sel = cursel.enable_selection();
sel.normalize();
try Editor.move_cursor_begin(root, &sel.begin, ed.metrics);
@ -321,7 +321,7 @@ const cmds_ = struct {
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
while (repeat > 0) : (repeat -= 1) {
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
const sel = cursel.enable_selection(root, ed.metrics);
const sel = cursel.enable_selection();
// handling left to right transition
const sel_begin: i32 = @intCast(sel.begin.col);
@ -333,7 +333,7 @@ const cmds_ = struct {
try Editor.move_cursor_right(root, &sel.end, ed.metrics);
cursel.cursor = sel.end;
cursel.check_selection(root, ed.metrics);
cursel.check_selection();
};
}
ed.clamp();
@ -361,7 +361,7 @@ const cmds_ = struct {
}
}
cursel.check_selection(root, ed.metrics);
cursel.check_selection();
};
}
ed.clamp();
@ -634,7 +634,7 @@ fn extend_to_word(ctx: command.Context, move: Editor.cursor_operator_const, _: D
var repeat: usize = 1;
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
const sel = cursel.enable_selection(root, ed.metrics);
const sel = cursel.enable_selection();
const pivot: usize = if (sel.is_reversed()) sel.begin.col -| 1 else sel.begin.col;
var i: usize = repeat;
while (i > 0) : (i -= 1) {
@ -660,7 +660,7 @@ fn select_inner_word(root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics
Editor.move_cursor_left_until(root, &prev, Editor.is_word_boundary_left, metrics);
Editor.move_cursor_right_until(root, &next, Editor.is_word_boundary_right, metrics);
try next.move_right(root, metrics);
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
sel.begin = prev;
sel.end = next;
cursel.*.cursor = next;
@ -673,7 +673,7 @@ fn select_inner_long_word(root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Me
Editor.move_cursor_left_until(root, &prev, is_long_word_boundary_left, metrics);
Editor.move_cursor_right_until(root, &next, is_long_word_boundary_right, metrics);
try next.move_right(root, metrics);
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
sel.begin = prev;
sel.end = next;
cursel.*.cursor = next;
@ -694,7 +694,7 @@ fn select_around_word(root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metric
if (!cursel.cursor.test_at(root, Editor.is_word_char, metrics)) return;
var expander = cursel.*;
try select_inner_word(root, &expander, metrics);
const sel_e = expander.enable_selection(root, metrics);
const sel_e = expander.enable_selection();
var prev = sel_e.begin;
var next = sel_e.end;
if (next.test_at(root, is_tab_or_space, metrics)) {
@ -709,7 +709,7 @@ fn select_around_word(root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metric
prev = sel_e.begin;
}
}
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
sel.begin = prev;
sel.end = next;
cursel.*.cursor = next;
@ -750,7 +750,7 @@ fn select_cursel_to_char_left_helix(root: Buffer.Root, cursel: *CurSel, ctx: com
//At end of file, it's ok
};
moving_cursor.target = moving_cursor.col;
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
sel.begin = begin;
sel.end = moving_cursor;
cursel.cursor = moving_cursor;
@ -763,7 +763,7 @@ fn extend_cursel_to_char_left_helix(root: Buffer.Root, cursel: *CurSel, ctx: com
//Character found, selecting
moving_cursor.target = moving_cursor.col;
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
if (sel.empty())
sel.begin = begin;
sel.end = moving_cursor;
@ -780,7 +780,7 @@ fn select_cursel_till_char_left_helix(root: Buffer.Root, cursel: *CurSel, ctx: c
//At end of file, it's ok
};
moving_cursor.target = moving_cursor.col;
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
sel.begin = begin;
sel.end = moving_cursor;
cursel.cursor = moving_cursor;
@ -793,7 +793,7 @@ fn extend_cursel_till_char_left_helix(root: Buffer.Root, cursel: *CurSel, ctx: c
//Character found, selecting
moving_cursor.target = moving_cursor.col;
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
if (sel.empty())
sel.begin = begin;
sel.end = moving_cursor;
@ -807,7 +807,7 @@ fn select_cursel_till_char_right_helix(root: Buffer.Root, cursel: *CurSel, ctx:
//Character found, selecting
moving_cursor.target = moving_cursor.col;
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
sel.begin = begin;
sel.end = moving_cursor;
cursel.cursor = moving_cursor;
@ -820,7 +820,7 @@ fn extend_cursel_till_char_right_helix(root: Buffer.Root, cursel: *CurSel, ctx:
//Character found, selecting
moving_cursor.target = moving_cursor.col;
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
if (sel.empty())
sel.begin = begin;
sel.end = moving_cursor;
@ -837,7 +837,7 @@ fn select_cursel_to_char_right_helix(root: Buffer.Root, cursel: *CurSel, ctx: co
// We might be at end of file
};
moving_cursor.target = moving_cursor.col;
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
sel.begin = begin;
sel.end = moving_cursor;
cursel.cursor = moving_cursor;
@ -853,7 +853,7 @@ fn extend_cursel_to_char_right_helix(root: Buffer.Root, cursel: *CurSel, ctx: co
// We might be at end of file
};
moving_cursor.target = moving_cursor.col;
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
if (sel.empty())
sel.begin = begin;
sel.end = moving_cursor;
@ -891,7 +891,7 @@ fn replace_cursel_with_character(ed: *Editor, root: Buffer.Root, cursel: *CurSel
var egc: []const u8 = undefined;
if (!(ctx.args.match(.{tp.extract(&egc)}) catch return error.Stop))
return error.Stop;
const no_selection = try select_char_if_no_selection(cursel, root, ed.metrics);
const no_selection = try select_char_if_no_selection(cursel);
var begin: Cursor = undefined;
var sel_length: usize = 1;
if (cursel.selection) |*sel| {
@ -911,7 +911,7 @@ fn replace_cursel_with_character(ed: *Editor, root: Buffer.Root, cursel: *CurSel
if (no_selection) {
try cursel.cursor.move_left(root, ed.metrics);
cursel.disable_selection(root, ed.metrics);
cursel.disable_selection();
} else {
cursel.selection = Selection{ .begin = begin, .end = cursel.cursor };
}
@ -1004,7 +1004,7 @@ fn move_cursor_till_char_right_beyond_eol(root: Buffer.Root, cursor: *Cursor, me
fn add_cursors_to_cursel_line_ends_helix(ed: *Editor, root: Buffer.Root, cursel: *CurSel) !void {
const original_cursel = cursel.*;
const sel = cursel.enable_selection(root, ed.metrics);
const sel = cursel.enable_selection();
sel.normalize();
var row = sel.begin.row;
const is_multiline = sel.begin.row != sel.end.row;
@ -1059,7 +1059,7 @@ fn insert_before(editor: *Editor, root: Buffer.Root, cursel: *CurSel, text: []co
var root_: Buffer.Root = root;
const cursor: *Cursor = &cursel.cursor;
cursel.check_selection(root, editor.metrics);
cursel.check_selection();
if (cursel.selection) |sel_| {
var sel = sel_;
sel.normalize();
@ -1085,7 +1085,7 @@ fn insert_replace_selection(editor: *Editor, root: Buffer.Root, cursel: *CurSel,
// replaces the selection, if no selection, replaces the current
// character and sets the selection to the replacement text
var root_: Buffer.Root = root;
cursel.check_selection(root, editor.metrics);
cursel.check_selection();
if (cursel.selection == null) {
// Select current character to replace it
@ -1105,7 +1105,7 @@ fn insert_replace_selection(editor: *Editor, root: Buffer.Root, cursel: *CurSel,
fn insert_after(editor: *Editor, root: Buffer.Root, cursel: *CurSel, text: []const u8, allocator: Allocator) !Buffer.Root {
var root_: Buffer.Root = root;
const cursor = &cursel.cursor;
cursel.check_selection(root, editor.metrics);
cursel.check_selection();
if (text[text.len - 1] == '\n') {
move_cursor_carriage_return(root, cursel.*, cursor, editor.metrics) catch {};
} else {
@ -1270,7 +1270,7 @@ fn move_cursor_carriage_return(root: Buffer.Root, cursel: CurSel, cursor: *Curso
try Editor.move_cursor_right(root, cursor, metrics);
}
fn select_char_if_no_selection(cursel: *CurSel, root: Buffer.Root, metrics: Buffer.Metrics) !bool {
fn select_char_if_no_selection(cursel: *CurSel) !bool {
if (cursel.selection) |*sel_| {
const sel: *Selection = sel_;
if (sel.*.empty()) {
@ -1279,7 +1279,7 @@ fn select_char_if_no_selection(cursel: *CurSel, root: Buffer.Root, metrics: Buff
}
return false;
} else {
const sel = cursel.enable_selection(root, metrics);
const sel = cursel.enable_selection();
sel.begin = .{ .row = cursel.cursor.row, .col = cursel.cursor.col + 1, .target = cursel.cursor.target + 1 };
return true;
}