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:
parent
b8e9f981f2
commit
a5c360a2ec
7 changed files with 75 additions and 111 deletions
|
|
@ -9,8 +9,6 @@ end: Cursor = Cursor{},
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
pub const Style = enum { normal, inclusive };
|
|
||||||
|
|
||||||
pub inline fn eql(self: Self, other: Self) bool {
|
pub inline fn eql(self: Self, other: Self) bool {
|
||||||
return self.begin.eql(other.begin) and self.end.eql(other.end);
|
return self.begin.eql(other.begin) and self.end.eql(other.end);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
"name": "NOR",
|
"name": "NOR",
|
||||||
"line_numbers": "relative",
|
"line_numbers": "relative",
|
||||||
"cursor": "block",
|
"cursor": "block",
|
||||||
"selection": "inclusive",
|
|
||||||
"press": [
|
"press": [
|
||||||
["ctrl+b", "move_scroll_page_up"],
|
["ctrl+b", "move_scroll_page_up"],
|
||||||
["ctrl+f", "move_scroll_page_down"],
|
["ctrl+f", "move_scroll_page_down"],
|
||||||
|
|
@ -281,7 +280,6 @@
|
||||||
"name": "SEL",
|
"name": "SEL",
|
||||||
"line_numbers": "relative",
|
"line_numbers": "relative",
|
||||||
"cursor": "block",
|
"cursor": "block",
|
||||||
"selection": "inclusive",
|
|
||||||
"init_command": ["init_helix_select_mode"],
|
"init_command": ["init_helix_select_mode"],
|
||||||
"press": [
|
"press": [
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
"name": "NORMAL",
|
"name": "NORMAL",
|
||||||
"line_numbers": "relative",
|
"line_numbers": "relative",
|
||||||
"cursor": "block",
|
"cursor": "block",
|
||||||
"selection": "normal",
|
|
||||||
"press": [
|
"press": [
|
||||||
["b", "move_word_left_vim"],
|
["b", "move_word_left_vim"],
|
||||||
["w", "move_word_right_vim"],
|
["w", "move_word_right_vim"],
|
||||||
|
|
@ -121,7 +120,6 @@
|
||||||
"name": "VISUAL",
|
"name": "VISUAL",
|
||||||
"line_numbers": "relative",
|
"line_numbers": "relative",
|
||||||
"cursor": "block",
|
"cursor": "block",
|
||||||
"selection": "normal",
|
|
||||||
"init_command": ["enable_selection"],
|
"init_command": ["enable_selection"],
|
||||||
"press": [
|
"press": [
|
||||||
["<Esc>", ["cancel"], ["enter_mode", "normal"]],
|
["<Esc>", ["cancel"], ["enter_mode", "normal"]],
|
||||||
|
|
@ -186,7 +184,6 @@
|
||||||
"name": "VISUAL LINE",
|
"name": "VISUAL LINE",
|
||||||
"line_numbers": "relative",
|
"line_numbers": "relative",
|
||||||
"cursor": "block",
|
"cursor": "block",
|
||||||
"selection": "normal",
|
|
||||||
"press": [
|
"press": [
|
||||||
["<Esc>", ["cancel"], ["enter_mode", "normal"]],
|
["<Esc>", ["cancel"], ["enter_mode", "normal"]],
|
||||||
["k", "select_up"],
|
["k", "select_up"],
|
||||||
|
|
@ -234,7 +231,6 @@
|
||||||
"inherit": "visual",
|
"inherit": "visual",
|
||||||
"line_numbers": "relative",
|
"line_numbers": "relative",
|
||||||
"cursor": "block",
|
"cursor": "block",
|
||||||
"selection": "normal",
|
|
||||||
"init_command": ["enable_selection"],
|
"init_command": ["enable_selection"],
|
||||||
"press": [
|
"press": [
|
||||||
["k", "add_cursor_up"],
|
["k", "add_cursor_up"],
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ const input = @import("input");
|
||||||
const command = @import("command");
|
const command = @import("command");
|
||||||
const EventHandler = @import("EventHandler");
|
const EventHandler = @import("EventHandler");
|
||||||
const KeyEvent = input.KeyEvent;
|
const KeyEvent = input.KeyEvent;
|
||||||
const SelectionStyle = @import("Buffer").Selection.Style;
|
|
||||||
pub const CursorShape = @import("config").CursorShape;
|
pub const CursorShape = @import("config").CursorShape;
|
||||||
|
|
||||||
const parse_flow = @import("parse_flow.zig");
|
const parse_flow = @import("parse_flow.zig");
|
||||||
|
|
@ -84,7 +83,6 @@ const Handler = struct {
|
||||||
.name = self.bindings.name,
|
.name = self.bindings.name,
|
||||||
.line_numbers = self.bindings.line_numbers,
|
.line_numbers = self.bindings.line_numbers,
|
||||||
.cursor_shape = self.bindings.cursor_shape,
|
.cursor_shape = self.bindings.cursor_shape,
|
||||||
.selection_style = self.bindings.selection_style,
|
|
||||||
.init_command = self.bindings.init_command,
|
.init_command = self.bindings.init_command,
|
||||||
.deinit_command = self.bindings.deinit_command,
|
.deinit_command = self.bindings.deinit_command,
|
||||||
.insert_command = try allocator.dupe(u8, insert_command),
|
.insert_command = try allocator.dupe(u8, insert_command),
|
||||||
|
|
@ -109,7 +107,6 @@ const Handler = struct {
|
||||||
mode_.name = self.bindings.name;
|
mode_.name = self.bindings.name;
|
||||||
mode_.line_numbers = self.bindings.line_numbers;
|
mode_.line_numbers = self.bindings.line_numbers;
|
||||||
mode_.cursor_shape = self.bindings.cursor_shape;
|
mode_.cursor_shape = self.bindings.cursor_shape;
|
||||||
mode_.selection_style = self.bindings.selection_style;
|
|
||||||
mode_.init_command = self.bindings.init_command;
|
mode_.init_command = self.bindings.init_command;
|
||||||
mode_.deinit_command = self.bindings.deinit_command;
|
mode_.deinit_command = self.bindings.deinit_command;
|
||||||
if (mode_.init_command) |init_command| init_command.execute_const();
|
if (mode_.init_command) |init_command| init_command.execute_const();
|
||||||
|
|
@ -132,7 +129,6 @@ pub const Mode = struct {
|
||||||
line_numbers: LineNumbers = .inherit,
|
line_numbers: LineNumbers = .inherit,
|
||||||
keybind_hints: *const KeybindHints,
|
keybind_hints: *const KeybindHints,
|
||||||
cursor_shape: ?CursorShape = null,
|
cursor_shape: ?CursorShape = null,
|
||||||
selection_style: SelectionStyle,
|
|
||||||
init_command: ?Command = null,
|
init_command: ?Command = null,
|
||||||
deinit_command: ?Command = null,
|
deinit_command: ?Command = null,
|
||||||
initialized: bool = false,
|
initialized: bool = false,
|
||||||
|
|
@ -168,7 +164,6 @@ pub const Mode = struct {
|
||||||
self.line_numbers = .inherit;
|
self.line_numbers = .inherit;
|
||||||
self.keybind_hints = &.{};
|
self.keybind_hints = &.{};
|
||||||
self.cursor_shape = null;
|
self.cursor_shape = null;
|
||||||
self.selection_style = .normal;
|
|
||||||
self.init_command = null;
|
self.init_command = null;
|
||||||
self.deinit_command = null;
|
self.deinit_command = null;
|
||||||
self.initialized = false;
|
self.initialized = false;
|
||||||
|
|
@ -462,7 +457,6 @@ const BindingSet = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
line_numbers: LineNumbers = .inherit,
|
line_numbers: LineNumbers = .inherit,
|
||||||
cursor_shape: ?CursorShape = null,
|
cursor_shape: ?CursorShape = null,
|
||||||
selection_style: SelectionStyle,
|
|
||||||
insert_command: []const u8 = "",
|
insert_command: []const u8 = "",
|
||||||
hints_map: KeybindHints = .{},
|
hints_map: KeybindHints = .{},
|
||||||
init_command: ?Command = null,
|
init_command: ?Command = null,
|
||||||
|
|
@ -472,7 +466,7 @@ const BindingSet = struct {
|
||||||
const OnMatchFailure = enum { insert, ignore };
|
const OnMatchFailure = enum { insert, ignore };
|
||||||
|
|
||||||
fn load(allocator: std.mem.Allocator, namespace_name: []const u8, mode_bindings: std.json.Value, fallback: ?*const BindingSet, namespace: *Namespace) (error{ OutOfMemory, WriteFailed } || parse_flow.ParseError || parse_vim.ParseError || std.json.ParseFromValueError)!@This() {
|
fn load(allocator: std.mem.Allocator, namespace_name: []const u8, mode_bindings: std.json.Value, fallback: ?*const BindingSet, namespace: *Namespace) (error{ OutOfMemory, WriteFailed } || parse_flow.ParseError || parse_vim.ParseError || std.json.ParseFromValueError)!@This() {
|
||||||
var self: @This() = .{ .name = undefined, .selection_style = undefined };
|
var self: @This() = .{ .name = undefined };
|
||||||
|
|
||||||
const JsonConfig = struct {
|
const JsonConfig = struct {
|
||||||
press: []const []const std.json.Value = &[_][]std.json.Value{},
|
press: []const []const std.json.Value = &[_][]std.json.Value{},
|
||||||
|
|
@ -484,7 +478,6 @@ const BindingSet = struct {
|
||||||
cursor: ?CursorShape = null,
|
cursor: ?CursorShape = null,
|
||||||
inherit: ?[]const u8 = null,
|
inherit: ?[]const u8 = null,
|
||||||
inherits: ?[][]const u8 = null,
|
inherits: ?[][]const u8 = null,
|
||||||
selection: ?SelectionStyle = null,
|
|
||||||
init_command: ?[]const std.json.Value = null,
|
init_command: ?[]const std.json.Value = null,
|
||||||
deinit_command: ?[]const std.json.Value = null,
|
deinit_command: ?[]const std.json.Value = null,
|
||||||
};
|
};
|
||||||
|
|
@ -497,7 +490,6 @@ const BindingSet = struct {
|
||||||
self.name = try allocator.dupe(u8, parsed.value.name orelse namespace_name);
|
self.name = try allocator.dupe(u8, parsed.value.name orelse namespace_name);
|
||||||
self.line_numbers = parsed.value.line_numbers;
|
self.line_numbers = parsed.value.line_numbers;
|
||||||
self.cursor_shape = parsed.value.cursor;
|
self.cursor_shape = parsed.value.cursor;
|
||||||
self.selection_style = parsed.value.selection orelse .normal;
|
|
||||||
if (parsed.value.init_command) |cmd| self.init_command = try Command.load(allocator, cmd);
|
if (parsed.value.init_command) |cmd| self.init_command = try Command.load(allocator, cmd);
|
||||||
if (parsed.value.deinit_command) |cmd| self.deinit_command = try Command.load(allocator, cmd);
|
if (parsed.value.deinit_command) |cmd| self.deinit_command = try Command.load(allocator, cmd);
|
||||||
try self.load_event(allocator, &self.press, input.event.press, parsed.value.press);
|
try self.load_event(allocator, &self.press, input.event.press, parsed.value.press);
|
||||||
|
|
@ -579,7 +571,7 @@ const BindingSet = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy(allocator: std.mem.Allocator, fallback: *const BindingSet) error{OutOfMemory}!@This() {
|
fn copy(allocator: std.mem.Allocator, fallback: *const BindingSet) error{OutOfMemory}!@This() {
|
||||||
var self: @This() = .{ .name = fallback.name, .selection_style = fallback.selection_style };
|
var self: @This() = .{ .name = fallback.name };
|
||||||
self.on_match_failure = fallback.on_match_failure;
|
self.on_match_failure = fallback.on_match_failure;
|
||||||
for (fallback.press.items) |binding| try self.press.append(allocator, binding);
|
for (fallback.press.items) |binding| try self.press.append(allocator, binding);
|
||||||
for (fallback.release.items) |binding| try self.release.append(allocator, binding);
|
for (fallback.release.items) |binding| try self.release.append(allocator, binding);
|
||||||
|
|
|
||||||
|
|
@ -115,24 +115,12 @@ pub const CurSel = struct {
|
||||||
self.* = .{};
|
self.* = .{};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable_selection(self: *Self, root: Buffer.Root, metrics: Buffer.Metrics) *Selection {
|
pub fn enable_selection(self: *Self) *Selection {
|
||||||
self.selection = self.to_selection(root, metrics);
|
self.selection = self.to_selection();
|
||||||
return if (self.selection) |*sel| sel else unreachable;
|
return if (self.selection) |*sel| sel else unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable_selection_normal(self: *Self) *Selection {
|
fn to_selection(self: *const Self) Selection {
|
||||||
self.selection = self.to_selection_normal();
|
|
||||||
return if (self.selection) |*sel| sel else unreachable;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_selection(self: *const Self, root: Buffer.Root, metrics: Buffer.Metrics) Selection {
|
|
||||||
return switch (tui.get_selection_style()) {
|
|
||||||
.normal => self.to_selection_normal(),
|
|
||||||
.inclusive => self.to_selection_inclusive(root, metrics),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_selection_normal(self: *const Self) Selection {
|
|
||||||
return if (self.selection) |sel| sel else Selection.from_cursor(&self.cursor);
|
return if (self.selection) |sel| sel else Selection.from_cursor(&self.cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,7 +128,7 @@ pub const CurSel = struct {
|
||||||
return self.selection orelse Selection.from_cursor_inclusive(&self.cursor, root, metrics);
|
return self.selection orelse Selection.from_cursor_inclusive(&self.cursor, root, metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disable_selection(self: *Self, _: Buffer.Root, _: Buffer.Metrics) void {
|
pub fn disable_selection(self: *Self) void {
|
||||||
self.selection = null;
|
self.selection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,12 +136,12 @@ pub const CurSel = struct {
|
||||||
self.selection = null;
|
self.selection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_selection(self: *Self, _: Buffer.Root, _: Buffer.Metrics) void {
|
pub fn check_selection(self: *Self) void {
|
||||||
self.selection = if (self.selection) |sel| if (sel.empty()) null else sel else null;
|
self.selection = if (self.selection) |sel| if (sel.empty()) null else sel else null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_selection_to_line(self: *Self, root: Buffer.Root, metrics: Buffer.Metrics) *Selection {
|
fn expand_selection_to_line(self: *Self, root: Buffer.Root, metrics: Buffer.Metrics) *Selection {
|
||||||
const sel = self.enable_selection(root, metrics);
|
const sel = self.enable_selection();
|
||||||
sel.normalize();
|
sel.normalize();
|
||||||
sel.begin.move_begin();
|
sel.begin.move_begin();
|
||||||
if (!(sel.end.row > sel.begin.row and sel.end.col == 0)) {
|
if (!(sel.end.row > sel.begin.row and sel.end.col == 0)) {
|
||||||
|
|
@ -1883,7 +1871,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
fn cancel_all_selections(self: *Self) void {
|
fn cancel_all_selections(self: *Self) void {
|
||||||
var primary = self.get_primary().*;
|
var primary = self.get_primary().*;
|
||||||
primary.disable_selection(self.buf_root() catch return, self.metrics);
|
primary.disable_selection();
|
||||||
self.cursels.clearRetainingCapacity();
|
self.cursels.clearRetainingCapacity();
|
||||||
self.cursels.addOneAssumeCapacity().* = primary;
|
self.cursels.addOneAssumeCapacity().* = primary;
|
||||||
for (self.matches.items) |*match_| if (match_.*) |*match| {
|
for (self.matches.items) |*match_| if (match_.*) |*match| {
|
||||||
|
|
@ -1937,7 +1925,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
fn with_cursors_const_once(self: *Self, root: Buffer.Root, move: cursor_operator_const) error{Stop}!void {
|
fn with_cursors_const_once(self: *Self, root: Buffer.Root, move: cursor_operator_const) error{Stop}!void {
|
||||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
cursel.disable_selection(root, self.metrics);
|
cursel.disable_selection();
|
||||||
try with_cursor_const(root, move, cursel, self.metrics);
|
try with_cursor_const(root, move, cursel, self.metrics);
|
||||||
};
|
};
|
||||||
self.collapse_cursors();
|
self.collapse_cursors();
|
||||||
|
|
@ -1948,7 +1936,7 @@ pub const Editor = struct {
|
||||||
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
|
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
|
||||||
while (repeat > 0) : (repeat -= 1) {
|
while (repeat > 0) : (repeat -= 1) {
|
||||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
cursel.disable_selection(root, self.metrics);
|
cursel.disable_selection();
|
||||||
try with_cursor_const(root, move, cursel, self.metrics);
|
try with_cursor_const(root, move, cursel, self.metrics);
|
||||||
};
|
};
|
||||||
self.collapse_cursors();
|
self.collapse_cursors();
|
||||||
|
|
@ -1961,7 +1949,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
fn with_cursors_const_arg(self: *Self, root: Buffer.Root, move: cursor_operator_const_arg, ctx: Context) error{Stop}!void {
|
fn with_cursors_const_arg(self: *Self, root: Buffer.Root, move: cursor_operator_const_arg, ctx: Context) error{Stop}!void {
|
||||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
cursel.disable_selection(root, self.metrics);
|
cursel.disable_selection();
|
||||||
try with_cursor_const_arg(root, move, cursel, ctx, self.metrics);
|
try with_cursor_const_arg(root, move, cursel, ctx, self.metrics);
|
||||||
};
|
};
|
||||||
self.collapse_cursors();
|
self.collapse_cursors();
|
||||||
|
|
@ -1986,10 +1974,10 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_selection_const(root: Buffer.Root, move: cursor_operator_const, cursel: *CurSel, metrics: Buffer.Metrics) error{Stop}!void {
|
pub fn with_selection_const(root: Buffer.Root, move: cursor_operator_const, cursel: *CurSel, metrics: Buffer.Metrics) error{Stop}!void {
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
try move(root, &sel.end, metrics);
|
try move(root, &sel.end, metrics);
|
||||||
cursel.cursor = sel.end;
|
cursel.cursor = sel.end;
|
||||||
cursel.check_selection(root, metrics);
|
cursel.check_selection();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_selections_const_once(self: *Self, root: Buffer.Root, move: cursor_operator_const) error{Stop}!void {
|
pub fn with_selections_const_once(self: *Self, root: Buffer.Root, move: cursor_operator_const) error{Stop}!void {
|
||||||
|
|
@ -2018,10 +2006,10 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_selection_const_arg(root: Buffer.Root, move: cursor_operator_const_arg, cursel: *CurSel, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void {
|
fn with_selection_const_arg(root: Buffer.Root, move: cursor_operator_const_arg, cursel: *CurSel, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void {
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
try move(root, &sel.end, ctx, metrics);
|
try move(root, &sel.end, ctx, metrics);
|
||||||
cursel.cursor = sel.end;
|
cursel.cursor = sel.end;
|
||||||
cursel.check_selection(root, metrics);
|
cursel.check_selection();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_selections_const_arg(self: *Self, root: Buffer.Root, move: cursor_operator_const_arg, ctx: Context) error{Stop}!void {
|
fn with_selections_const_arg(self: *Self, root: Buffer.Root, move: cursor_operator_const_arg, ctx: Context) error{Stop}!void {
|
||||||
|
|
@ -2035,7 +2023,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_selection_and_view_const(root: Buffer.Root, move: cursor_view_operator_const, cursel: *CurSel, view: *const View, metrics: Buffer.Metrics) error{Stop}!void {
|
fn with_selection_and_view_const(root: Buffer.Root, move: cursor_view_operator_const, cursel: *CurSel, view: *const View, metrics: Buffer.Metrics) error{Stop}!void {
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
try move(root, &sel.end, view, metrics);
|
try move(root, &sel.end, view, metrics);
|
||||||
cursel.cursor = sel.end;
|
cursel.cursor = sel.end;
|
||||||
}
|
}
|
||||||
|
|
@ -2500,7 +2488,7 @@ pub const Editor = struct {
|
||||||
self.cancel_all_selections();
|
self.cancel_all_selections();
|
||||||
}
|
}
|
||||||
const primary = self.get_primary();
|
const primary = self.get_primary();
|
||||||
primary.disable_selection(root, self.metrics);
|
primary.disable_selection();
|
||||||
self.selection_mode = .char;
|
self.selection_mode = .char;
|
||||||
try self.send_editor_jump_source();
|
try self.send_editor_jump_source();
|
||||||
primary.cursor.move_abs(root, &self.view, @intCast(y), @intCast(x), self.metrics) catch return;
|
primary.cursor.move_abs(root, &self.view, @intCast(y), @intCast(x), self.metrics) catch return;
|
||||||
|
|
@ -2514,7 +2502,7 @@ pub const Editor = struct {
|
||||||
pub fn primary_double_click(self: *Self, y: c_int, x: c_int) !void {
|
pub fn primary_double_click(self: *Self, y: c_int, x: c_int) !void {
|
||||||
const primary = self.get_primary();
|
const primary = self.get_primary();
|
||||||
const root = self.buf_root() catch return;
|
const root = self.buf_root() catch return;
|
||||||
primary.disable_selection(root, self.metrics);
|
primary.disable_selection();
|
||||||
self.selection_mode = .word;
|
self.selection_mode = .word;
|
||||||
primary.cursor.move_abs(root, &self.view, @intCast(y), @intCast(x), self.metrics) catch return;
|
primary.cursor.move_abs(root, &self.view, @intCast(y), @intCast(x), self.metrics) catch return;
|
||||||
_ = try self.select_word_at_cursor(primary);
|
_ = try self.select_word_at_cursor(primary);
|
||||||
|
|
@ -2526,7 +2514,7 @@ pub const Editor = struct {
|
||||||
pub fn primary_triple_click(self: *Self, y: c_int, x: c_int) !void {
|
pub fn primary_triple_click(self: *Self, y: c_int, x: c_int) !void {
|
||||||
const primary = self.get_primary();
|
const primary = self.get_primary();
|
||||||
const root = self.buf_root() catch return;
|
const root = self.buf_root() catch return;
|
||||||
primary.disable_selection(root, self.metrics);
|
primary.disable_selection();
|
||||||
self.selection_mode = .line;
|
self.selection_mode = .line;
|
||||||
primary.cursor.move_abs(root, &self.view, @intCast(y), @intCast(x), self.metrics) catch return;
|
primary.cursor.move_abs(root, &self.view, @intCast(y), @intCast(x), self.metrics) catch return;
|
||||||
try self.select_line_at_cursor(root, primary, .exclude_eol);
|
try self.select_line_at_cursor(root, primary, .exclude_eol);
|
||||||
|
|
@ -2540,7 +2528,7 @@ pub const Editor = struct {
|
||||||
const x_ = if (x < 0) 0 else x;
|
const x_ = if (x < 0) 0 else x;
|
||||||
const primary = self.get_primary();
|
const primary = self.get_primary();
|
||||||
const root = self.buf_root() catch return;
|
const root = self.buf_root() catch return;
|
||||||
const sel = primary.enable_selection(root, self.metrics);
|
const sel = primary.enable_selection();
|
||||||
sel.end.move_abs(root, &self.view, @intCast(y_), @intCast(x_), self.metrics) catch return;
|
sel.end.move_abs(root, &self.view, @intCast(y_), @intCast(x_), self.metrics) catch return;
|
||||||
const initial = self.selection_drag_initial orelse sel.*;
|
const initial = self.selection_drag_initial orelse sel.*;
|
||||||
switch (self.selection_mode) {
|
switch (self.selection_mode) {
|
||||||
|
|
@ -2568,7 +2556,7 @@ pub const Editor = struct {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
primary.cursor = sel.end;
|
primary.cursor = sel.end;
|
||||||
primary.check_selection(root, self.metrics);
|
primary.check_selection();
|
||||||
self.collapse_cursors();
|
self.collapse_cursors();
|
||||||
self.clamp_mouse();
|
self.clamp_mouse();
|
||||||
}
|
}
|
||||||
|
|
@ -2758,7 +2746,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(self: *Self, root: Buffer.Root, cursel: *CurSel, s: []const u8, allocator: Allocator) !Buffer.Root {
|
pub fn insert(self: *Self, root: Buffer.Root, cursel: *CurSel, s: []const u8, allocator: Allocator) !Buffer.Root {
|
||||||
cursel.check_selection(root, self.metrics);
|
cursel.check_selection();
|
||||||
var root_ = if (cursel.selection) |_| try self.delete_selection(root, cursel, allocator) else root;
|
var root_ = if (cursel.selection) |_| try self.delete_selection(root, cursel, allocator) else root;
|
||||||
const cursor = &cursel.cursor;
|
const cursor = &cursel.cursor;
|
||||||
const begin = cursel.cursor;
|
const begin = cursel.cursor;
|
||||||
|
|
@ -2911,7 +2899,7 @@ pub const Editor = struct {
|
||||||
const primary = self.get_primary();
|
const primary = self.get_primary();
|
||||||
const root = self.buf_root() catch return;
|
const root = self.buf_root() catch return;
|
||||||
if (primary.selection) |_| {} else {
|
if (primary.selection) |_| {} else {
|
||||||
const sel = primary.enable_selection(root, self.metrics);
|
const sel = primary.enable_selection();
|
||||||
try move_cursor_begin(root, &sel.begin, self.metrics);
|
try move_cursor_begin(root, &sel.begin, self.metrics);
|
||||||
try move_cursor_end(root, &sel.end, self.metrics);
|
try move_cursor_end(root, &sel.end, self.metrics);
|
||||||
try move_cursor_right(root, &sel.end, self.metrics);
|
try move_cursor_right(root, &sel.end, self.metrics);
|
||||||
|
|
@ -3237,7 +3225,7 @@ pub const Editor = struct {
|
||||||
.left => if (sel.is_reversed()) sel.end else sel.begin,
|
.left => if (sel.is_reversed()) sel.end else sel.begin,
|
||||||
.right => if (sel.is_reversed()) sel.begin else sel.end,
|
.right => if (sel.is_reversed()) sel.begin else sel.end,
|
||||||
};
|
};
|
||||||
cursel.disable_selection(root, self.metrics);
|
cursel.disable_selection();
|
||||||
} else {
|
} else {
|
||||||
try with_cursor_const(root, switch (direction) {
|
try with_cursor_const(root, switch (direction) {
|
||||||
.left => move_cursor_left,
|
.left => move_cursor_left,
|
||||||
|
|
@ -3657,7 +3645,7 @@ pub const Editor = struct {
|
||||||
pub const add_cursor_all_matches_meta: Meta = .{ .description = "Add cursors to all highlighted matches" };
|
pub const add_cursor_all_matches_meta: Meta = .{ .description = "Add cursors to all highlighted matches" };
|
||||||
|
|
||||||
fn add_cursors_to_cursel_line_ends(self: *Self, root: Buffer.Root, cursel: *CurSel) !void {
|
fn add_cursors_to_cursel_line_ends(self: *Self, root: Buffer.Root, cursel: *CurSel) !void {
|
||||||
const sel = cursel.enable_selection(root, self.metrics);
|
const sel = cursel.enable_selection();
|
||||||
sel.normalize();
|
sel.normalize();
|
||||||
var row = sel.begin.row;
|
var row = sel.begin.row;
|
||||||
while (row <= sel.end.row) : (row += 1) {
|
while (row <= sel.end.row) : (row += 1) {
|
||||||
|
|
@ -3751,7 +3739,7 @@ pub const Editor = struct {
|
||||||
cursel.cursor = sel.begin;
|
cursel.cursor = sel.begin;
|
||||||
var add_eol = false;
|
var add_eol = false;
|
||||||
if (cursel.selection) |_| {
|
if (cursel.selection) |_| {
|
||||||
cursel.disable_selection(root, self.metrics);
|
cursel.disable_selection();
|
||||||
} else {
|
} else {
|
||||||
var test_eof = sel.end;
|
var test_eof = sel.end;
|
||||||
test_eof.move_right(root, self.metrics) catch { // test for EOF
|
test_eof.move_right(root, self.metrics) catch { // test for EOF
|
||||||
|
|
@ -3786,7 +3774,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
cursel.cursor = sel.end;
|
cursel.cursor = sel.end;
|
||||||
if (cursel.selection) |_| {
|
if (cursel.selection) |_| {
|
||||||
cursel.disable_selection(root, self.metrics);
|
cursel.disable_selection();
|
||||||
} else {
|
} else {
|
||||||
var test_eof = sel.end;
|
var test_eof = sel.end;
|
||||||
test_eof.move_right(root, self.metrics) catch { // test for EOF
|
test_eof.move_right(root, self.metrics) catch { // test for EOF
|
||||||
|
|
@ -3840,7 +3828,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
cursel.cursor = sel.end;
|
cursel.cursor = sel.end;
|
||||||
if (cursel.selection) |_| {
|
if (cursel.selection) |_| {
|
||||||
cursel.disable_selection(root, self.metrics);
|
cursel.disable_selection();
|
||||||
} else {
|
} else {
|
||||||
var test_eof = sel.end;
|
var test_eof = sel.end;
|
||||||
test_eof.move_right(root, self.metrics) catch { // test for EOF
|
test_eof.move_right(root, self.metrics) catch { // test for EOF
|
||||||
|
|
@ -3944,7 +3932,7 @@ pub const Editor = struct {
|
||||||
if (first == 0) return root;
|
if (first == 0) return root;
|
||||||
const off = first % self.indent_size;
|
const off = first % self.indent_size;
|
||||||
const cols = if (off == 0) self.indent_size else off;
|
const cols = if (off == 0) self.indent_size else off;
|
||||||
const sel = cursel.enable_selection(root, self.metrics);
|
const sel = cursel.enable_selection();
|
||||||
try sel.begin.move_to(root, sel.begin.row, first, self.metrics);
|
try sel.begin.move_to(root, sel.begin.row, first, self.metrics);
|
||||||
try sel.end.move_to(root, sel.end.row, first - cols, self.metrics);
|
try sel.end.move_to(root, sel.end.row, first - cols, self.metrics);
|
||||||
var saved = false;
|
var saved = false;
|
||||||
|
|
@ -4169,8 +4157,7 @@ pub const Editor = struct {
|
||||||
pub const cancel_meta: Meta = .{ .description = "Cancel current action" };
|
pub const cancel_meta: Meta = .{ .description = "Cancel current action" };
|
||||||
|
|
||||||
pub fn enable_selection(self: *Self, _: Context) Result {
|
pub fn enable_selection(self: *Self, _: Context) Result {
|
||||||
const root = try self.buf_root();
|
_ = self.get_primary().enable_selection();
|
||||||
_ = self.get_primary().enable_selection(root, self.metrics);
|
|
||||||
}
|
}
|
||||||
pub const enable_selection_meta: Meta = .{ .description = "Enable selection" };
|
pub const enable_selection_meta: Meta = .{ .description = "Enable selection" };
|
||||||
|
|
||||||
|
|
@ -4399,7 +4386,7 @@ pub const Editor = struct {
|
||||||
self.cancel_all_selections();
|
self.cancel_all_selections();
|
||||||
const primary = self.get_primary();
|
const primary = self.get_primary();
|
||||||
const root = try self.buf_root();
|
const root = try self.buf_root();
|
||||||
const sel = primary.enable_selection(root, self.metrics);
|
const sel = primary.enable_selection();
|
||||||
try expand_selection_to_all(root, sel, self.metrics);
|
try expand_selection_to_all(root, sel, self.metrics);
|
||||||
primary.cursor = sel.end;
|
primary.cursor = sel.end;
|
||||||
self.clamp();
|
self.clamp();
|
||||||
|
|
@ -4409,8 +4396,8 @@ pub const Editor = struct {
|
||||||
|
|
||||||
fn select_word_at_cursor(self: *Self, cursel: *CurSel) !*Selection {
|
fn select_word_at_cursor(self: *Self, cursel: *CurSel) !*Selection {
|
||||||
const root = try self.buf_root();
|
const root = try self.buf_root();
|
||||||
const sel = cursel.enable_selection(root, self.metrics);
|
const sel = cursel.enable_selection();
|
||||||
defer cursel.check_selection(root, self.metrics);
|
defer cursel.check_selection();
|
||||||
sel.normalize();
|
sel.normalize();
|
||||||
try move_cursor_word_begin(root, &sel.begin, self.metrics);
|
try move_cursor_word_begin(root, &sel.begin, self.metrics);
|
||||||
move_cursor_word_end(root, &sel.end, self.metrics) catch {};
|
move_cursor_word_end(root, &sel.end, self.metrics) catch {};
|
||||||
|
|
@ -4419,7 +4406,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_line_at_cursor(self: *Self, root: Buffer.Root, cursel: *CurSel, mode: enum { include_eol, exclude_eol, hold_cursor }) !void {
|
pub fn select_line_at_cursor(self: *Self, root: Buffer.Root, cursel: *CurSel, mode: enum { include_eol, exclude_eol, hold_cursor }) !void {
|
||||||
const sel = cursel.enable_selection(root, self.metrics);
|
const sel = cursel.enable_selection();
|
||||||
sel.normalize();
|
sel.normalize();
|
||||||
try move_cursor_begin(root, &sel.begin, self.metrics);
|
try move_cursor_begin(root, &sel.begin, self.metrics);
|
||||||
move_cursor_end(root, &sel.end, self.metrics) catch {};
|
move_cursor_end(root, &sel.end, self.metrics) catch {};
|
||||||
|
|
@ -4483,12 +4470,12 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn top_node_at_cursel(self: *const Self, cursel: *const CurSel, root: Buffer.Root, metrics: Buffer.Metrics) error{Stop}!syntax.Node {
|
fn top_node_at_cursel(self: *const Self, cursel: *const CurSel, root: Buffer.Root, metrics: Buffer.Metrics) error{Stop}!syntax.Node {
|
||||||
const sel = cursel.to_selection(root, metrics);
|
const sel = cursel.to_selection();
|
||||||
return try self.top_node_at_selection(sel, root, metrics);
|
return try self.top_node_at_selection(sel, root, metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_selection_to_parent_node(self: *Self, root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
|
fn expand_selection_to_parent_node(self: *Self, root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
|
||||||
const sel = cursel.enable_selection(root, metrics).*;
|
const sel = cursel.enable_selection().*;
|
||||||
var node = try self.top_node_at_selection(sel, root, metrics);
|
var node = try self.top_node_at_selection(sel, root, metrics);
|
||||||
if (node.isNull()) return error.Stop;
|
if (node.isNull()) return error.Stop;
|
||||||
var node_sel = CurSel.selection_from_node(node, root, metrics);
|
var node_sel = CurSel.selection_from_node(node, root, metrics);
|
||||||
|
|
@ -4502,7 +4489,7 @@ pub const Editor = struct {
|
||||||
try self.send_editor_jump_source();
|
try self.send_editor_jump_source();
|
||||||
const root = try self.buf_root();
|
const root = try self.buf_root();
|
||||||
const cursel = self.get_primary();
|
const cursel = self.get_primary();
|
||||||
cursel.check_selection(root, self.metrics);
|
cursel.check_selection();
|
||||||
try if (cursel.selection) |_|
|
try if (cursel.selection) |_|
|
||||||
self.expand_selection_to_parent_node(root, cursel, self.metrics)
|
self.expand_selection_to_parent_node(root, cursel, self.metrics)
|
||||||
else
|
else
|
||||||
|
|
@ -4513,7 +4500,7 @@ pub const Editor = struct {
|
||||||
pub const expand_selection_meta: Meta = .{ .description = "Expand selection to AST parent node" };
|
pub const expand_selection_meta: Meta = .{ .description = "Expand selection to AST parent node" };
|
||||||
|
|
||||||
fn shrink_selection_to_child_node(self: *Self, root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
|
fn shrink_selection_to_child_node(self: *Self, root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
|
||||||
const sel = cursel.enable_selection(root, metrics).*;
|
const sel = cursel.enable_selection().*;
|
||||||
const node = try self.node_at_selection(sel, root, metrics);
|
const node = try self.node_at_selection(sel, root, metrics);
|
||||||
if (node.isNull() or node.getChildCount() == 0) return error.Stop;
|
if (node.isNull() or node.getChildCount() == 0) return error.Stop;
|
||||||
const child = node.getChild(0);
|
const child = node.getChild(0);
|
||||||
|
|
@ -4522,7 +4509,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shrink_selection_to_named_child_node(self: *Self, root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
|
fn shrink_selection_to_named_child_node(self: *Self, root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
|
||||||
const sel = cursel.enable_selection(root, metrics).*;
|
const sel = cursel.enable_selection().*;
|
||||||
const node = try self.node_at_selection(sel, root, metrics);
|
const node = try self.node_at_selection(sel, root, metrics);
|
||||||
if (node.isNull() or node.getNamedChildCount() == 0) return error.Stop;
|
if (node.isNull() or node.getNamedChildCount() == 0) return error.Stop;
|
||||||
const child = node.getNamedChild(0);
|
const child = node.getNamedChild(0);
|
||||||
|
|
@ -4536,7 +4523,7 @@ pub const Editor = struct {
|
||||||
try self.send_editor_jump_source();
|
try self.send_editor_jump_source();
|
||||||
const root = try self.buf_root();
|
const root = try self.buf_root();
|
||||||
const cursel = self.get_primary();
|
const cursel = self.get_primary();
|
||||||
cursel.check_selection(root, self.metrics);
|
cursel.check_selection();
|
||||||
if (cursel.selection) |_| {
|
if (cursel.selection) |_| {
|
||||||
try if (unnamed)
|
try if (unnamed)
|
||||||
self.shrink_selection_to_child_node(root, cursel, self.metrics)
|
self.shrink_selection_to_child_node(root, cursel, self.metrics)
|
||||||
|
|
@ -4570,7 +4557,7 @@ pub const Editor = struct {
|
||||||
try self.send_editor_jump_source();
|
try self.send_editor_jump_source();
|
||||||
const root = try self.buf_root();
|
const root = try self.buf_root();
|
||||||
const cursel = self.get_primary();
|
const cursel = self.get_primary();
|
||||||
cursel.check_selection(root, self.metrics);
|
cursel.check_selection();
|
||||||
if (cursel.selection) |_| {
|
if (cursel.selection) |_| {
|
||||||
try if (unnamed)
|
try if (unnamed)
|
||||||
self.select_next_sibling_node(root, cursel, self.metrics)
|
self.select_next_sibling_node(root, cursel, self.metrics)
|
||||||
|
|
@ -4604,7 +4591,7 @@ pub const Editor = struct {
|
||||||
try self.send_editor_jump_source();
|
try self.send_editor_jump_source();
|
||||||
const root = try self.buf_root();
|
const root = try self.buf_root();
|
||||||
const cursel = self.get_primary();
|
const cursel = self.get_primary();
|
||||||
cursel.check_selection(root, self.metrics);
|
cursel.check_selection();
|
||||||
try if (unnamed)
|
try if (unnamed)
|
||||||
self.select_prev_sibling_node(root, cursel, self.metrics)
|
self.select_prev_sibling_node(root, cursel, self.metrics)
|
||||||
else
|
else
|
||||||
|
|
@ -4680,7 +4667,7 @@ pub const Editor = struct {
|
||||||
root_ = self.collapse_trailing_ws_line(root_, row, b_allocator);
|
root_ = self.collapse_trailing_ws_line(root_, row, b_allocator);
|
||||||
const leading_ws_ = find_first_non_ws(root_, cursel.cursor.row, self.metrics);
|
const leading_ws_ = find_first_non_ws(root_, cursel.cursor.row, self.metrics);
|
||||||
if (leading_ws_ > leading_ws and leading_ws_ > cursel.cursor.col) {
|
if (leading_ws_ > leading_ws and leading_ws_ > cursel.cursor.col) {
|
||||||
const sel = cursel.enable_selection(root_, self.metrics);
|
const sel = cursel.enable_selection();
|
||||||
sel.* = .{
|
sel.* = .{
|
||||||
.begin = .{ .row = cursel.cursor.row, .col = cursel.cursor.col },
|
.begin = .{ .row = cursel.cursor.row, .col = cursel.cursor.col },
|
||||||
.end = .{ .row = cursel.cursor.row, .col = leading_ws_ },
|
.end = .{ .row = cursel.cursor.row, .col = leading_ws_ },
|
||||||
|
|
@ -4866,7 +4853,7 @@ pub const Editor = struct {
|
||||||
root = try self.insert(root, &begin, chars_begin, b.allocator);
|
root = try self.insert(root, &begin, chars_begin, b.allocator);
|
||||||
var end: CurSel = .{ .cursor = sel.end };
|
var end: CurSel = .{ .cursor = sel.end };
|
||||||
root = try self.insert(root, &end, chars_end, b.allocator);
|
root = try self.insert(root, &end, chars_end, b.allocator);
|
||||||
cursel.disable_selection(root, self.metrics);
|
cursel.disable_selection();
|
||||||
} else blk: {
|
} else blk: {
|
||||||
const egc, _, _ = cursel.cursor.egc_at(root, self.metrics) catch {
|
const egc, _, _ = cursel.cursor.egc_at(root, self.metrics) catch {
|
||||||
root = try self.insert(root, cursel, chars_right, b.allocator);
|
root = try self.insert(root, cursel, chars_right, b.allocator);
|
||||||
|
|
@ -5469,10 +5456,7 @@ pub const Editor = struct {
|
||||||
const col = cursor.col;
|
const col = cursor.col;
|
||||||
for (self.matches.items) |*match_| if (match_.*) |*match| {
|
for (self.matches.items) |*match_| if (match_.*) |*match| {
|
||||||
if (match.has_selection) continue;
|
if (match.has_selection) continue;
|
||||||
switch (tui.get_selection_style()) {
|
if (cursor.within(match.to_selection())) return match;
|
||||||
.normal => if (cursor.within(match.to_selection())) return match,
|
|
||||||
.inclusive => {},
|
|
||||||
}
|
|
||||||
if (row < match.begin.row or (row == match.begin.row and col < match.begin.col)) return match;
|
if (row < match.begin.row or (row == match.begin.row and col < match.begin.col)) return match;
|
||||||
};
|
};
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -6161,7 +6145,7 @@ pub const Editor = struct {
|
||||||
state.chunks = 1;
|
state.chunks = 1;
|
||||||
primary.cursor = state.old_primary.cursor;
|
primary.cursor = state.old_primary.cursor;
|
||||||
} else {
|
} else {
|
||||||
const sel = primary.enable_selection(root, self.metrics);
|
const sel = primary.enable_selection();
|
||||||
sel.begin = state.begin;
|
sel.begin = state.begin;
|
||||||
sel.end = state.pos.cursor;
|
sel.end = state.pos.cursor;
|
||||||
if (state.old_primary_reversed) sel.reverse();
|
if (state.old_primary_reversed) sel.reverse();
|
||||||
|
|
@ -6190,7 +6174,7 @@ pub const Editor = struct {
|
||||||
var root = root_;
|
var root = root_;
|
||||||
const saved = cursel.*;
|
const saved = cursel.*;
|
||||||
const sel = if (cursel.selection) |*sel| sel else ret: {
|
const sel = if (cursel.selection) |*sel| sel else ret: {
|
||||||
var sel = cursel.enable_selection(root, self.metrics);
|
var sel = cursel.enable_selection();
|
||||||
move_cursor_word_begin(root, &sel.begin, self.metrics) catch return error.Stop;
|
move_cursor_word_begin(root, &sel.begin, self.metrics) catch return error.Stop;
|
||||||
move_cursor_word_end(root, &sel.end, self.metrics) catch return error.Stop;
|
move_cursor_word_end(root, &sel.end, self.metrics) catch return error.Stop;
|
||||||
break :ret sel;
|
break :ret sel;
|
||||||
|
|
@ -6219,7 +6203,7 @@ pub const Editor = struct {
|
||||||
var root = root_;
|
var root = root_;
|
||||||
const saved = cursel.*;
|
const saved = cursel.*;
|
||||||
const sel = if (cursel.selection) |*sel| sel else ret: {
|
const sel = if (cursel.selection) |*sel| sel else ret: {
|
||||||
var sel = cursel.enable_selection(root, self.metrics);
|
var sel = cursel.enable_selection();
|
||||||
move_cursor_word_begin(root, &sel.begin, self.metrics) catch return error.Stop;
|
move_cursor_word_begin(root, &sel.begin, self.metrics) catch return error.Stop;
|
||||||
move_cursor_word_end(root, &sel.end, self.metrics) catch return error.Stop;
|
move_cursor_word_end(root, &sel.end, self.metrics) catch return error.Stop;
|
||||||
break :ret sel;
|
break :ret sel;
|
||||||
|
|
@ -6248,7 +6232,7 @@ pub const Editor = struct {
|
||||||
var root = root_;
|
var root = root_;
|
||||||
var saved = cursel.*;
|
var saved = cursel.*;
|
||||||
const sel = if (cursel.selection) |*sel| sel else ret: {
|
const sel = if (cursel.selection) |*sel| sel else ret: {
|
||||||
var sel = cursel.enable_selection(root, self.metrics);
|
var sel = cursel.enable_selection();
|
||||||
move_cursor_right(root, &sel.end, self.metrics) catch return error.Stop;
|
move_cursor_right(root, &sel.end, self.metrics) catch return error.Stop;
|
||||||
saved.cursor = sel.end;
|
saved.cursor = sel.end;
|
||||||
break :ret sel;
|
break :ret sel;
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ const cmds_ = struct {
|
||||||
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
|
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
|
||||||
while (repeat > 0) : (repeat -= 1) {
|
while (repeat > 0) : (repeat -= 1) {
|
||||||
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
const sel = cursel.enable_selection_normal();
|
const sel = cursel.enable_selection();
|
||||||
sel.normalize();
|
sel.normalize();
|
||||||
|
|
||||||
try Editor.move_cursor_begin(root, &sel.begin, ed.metrics);
|
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;
|
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
|
||||||
while (repeat > 0) : (repeat -= 1) {
|
while (repeat > 0) : (repeat -= 1) {
|
||||||
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
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
|
// handling left to right transition
|
||||||
const sel_begin: i32 = @intCast(sel.begin.col);
|
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);
|
try Editor.move_cursor_right(root, &sel.end, ed.metrics);
|
||||||
cursel.cursor = sel.end;
|
cursel.cursor = sel.end;
|
||||||
cursel.check_selection(root, ed.metrics);
|
cursel.check_selection();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
ed.clamp();
|
ed.clamp();
|
||||||
|
|
@ -361,7 +361,7 @@ const cmds_ = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cursel.check_selection(root, ed.metrics);
|
cursel.check_selection();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
ed.clamp();
|
ed.clamp();
|
||||||
|
|
@ -634,7 +634,7 @@ fn extend_to_word(ctx: command.Context, move: Editor.cursor_operator_const, _: D
|
||||||
var repeat: usize = 1;
|
var repeat: usize = 1;
|
||||||
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
|
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
|
||||||
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
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;
|
const pivot: usize = if (sel.is_reversed()) sel.begin.col -| 1 else sel.begin.col;
|
||||||
var i: usize = repeat;
|
var i: usize = repeat;
|
||||||
while (i > 0) : (i -= 1) {
|
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_left_until(root, &prev, Editor.is_word_boundary_left, metrics);
|
||||||
Editor.move_cursor_right_until(root, &next, Editor.is_word_boundary_right, metrics);
|
Editor.move_cursor_right_until(root, &next, Editor.is_word_boundary_right, metrics);
|
||||||
try next.move_right(root, metrics);
|
try next.move_right(root, metrics);
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
sel.begin = prev;
|
sel.begin = prev;
|
||||||
sel.end = next;
|
sel.end = next;
|
||||||
cursel.*.cursor = 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_left_until(root, &prev, is_long_word_boundary_left, metrics);
|
||||||
Editor.move_cursor_right_until(root, &next, is_long_word_boundary_right, metrics);
|
Editor.move_cursor_right_until(root, &next, is_long_word_boundary_right, metrics);
|
||||||
try next.move_right(root, metrics);
|
try next.move_right(root, metrics);
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
sel.begin = prev;
|
sel.begin = prev;
|
||||||
sel.end = next;
|
sel.end = next;
|
||||||
cursel.*.cursor = 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;
|
if (!cursel.cursor.test_at(root, Editor.is_word_char, metrics)) return;
|
||||||
var expander = cursel.*;
|
var expander = cursel.*;
|
||||||
try select_inner_word(root, &expander, metrics);
|
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 prev = sel_e.begin;
|
||||||
var next = sel_e.end;
|
var next = sel_e.end;
|
||||||
if (next.test_at(root, is_tab_or_space, metrics)) {
|
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;
|
prev = sel_e.begin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
sel.begin = prev;
|
sel.begin = prev;
|
||||||
sel.end = next;
|
sel.end = next;
|
||||||
cursel.*.cursor = 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
|
//At end of file, it's ok
|
||||||
};
|
};
|
||||||
moving_cursor.target = moving_cursor.col;
|
moving_cursor.target = moving_cursor.col;
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
sel.begin = begin;
|
sel.begin = begin;
|
||||||
sel.end = moving_cursor;
|
sel.end = moving_cursor;
|
||||||
cursel.cursor = 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
|
//Character found, selecting
|
||||||
moving_cursor.target = moving_cursor.col;
|
moving_cursor.target = moving_cursor.col;
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
if (sel.empty())
|
if (sel.empty())
|
||||||
sel.begin = begin;
|
sel.begin = begin;
|
||||||
sel.end = moving_cursor;
|
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
|
//At end of file, it's ok
|
||||||
};
|
};
|
||||||
moving_cursor.target = moving_cursor.col;
|
moving_cursor.target = moving_cursor.col;
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
sel.begin = begin;
|
sel.begin = begin;
|
||||||
sel.end = moving_cursor;
|
sel.end = moving_cursor;
|
||||||
cursel.cursor = 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
|
//Character found, selecting
|
||||||
moving_cursor.target = moving_cursor.col;
|
moving_cursor.target = moving_cursor.col;
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
if (sel.empty())
|
if (sel.empty())
|
||||||
sel.begin = begin;
|
sel.begin = begin;
|
||||||
sel.end = moving_cursor;
|
sel.end = moving_cursor;
|
||||||
|
|
@ -807,7 +807,7 @@ fn select_cursel_till_char_right_helix(root: Buffer.Root, cursel: *CurSel, ctx:
|
||||||
|
|
||||||
//Character found, selecting
|
//Character found, selecting
|
||||||
moving_cursor.target = moving_cursor.col;
|
moving_cursor.target = moving_cursor.col;
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
sel.begin = begin;
|
sel.begin = begin;
|
||||||
sel.end = moving_cursor;
|
sel.end = moving_cursor;
|
||||||
cursel.cursor = 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
|
//Character found, selecting
|
||||||
moving_cursor.target = moving_cursor.col;
|
moving_cursor.target = moving_cursor.col;
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
if (sel.empty())
|
if (sel.empty())
|
||||||
sel.begin = begin;
|
sel.begin = begin;
|
||||||
sel.end = moving_cursor;
|
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
|
// We might be at end of file
|
||||||
};
|
};
|
||||||
moving_cursor.target = moving_cursor.col;
|
moving_cursor.target = moving_cursor.col;
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
sel.begin = begin;
|
sel.begin = begin;
|
||||||
sel.end = moving_cursor;
|
sel.end = moving_cursor;
|
||||||
cursel.cursor = 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
|
// We might be at end of file
|
||||||
};
|
};
|
||||||
moving_cursor.target = moving_cursor.col;
|
moving_cursor.target = moving_cursor.col;
|
||||||
const sel = cursel.enable_selection(root, metrics);
|
const sel = cursel.enable_selection();
|
||||||
if (sel.empty())
|
if (sel.empty())
|
||||||
sel.begin = begin;
|
sel.begin = begin;
|
||||||
sel.end = moving_cursor;
|
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;
|
var egc: []const u8 = undefined;
|
||||||
if (!(ctx.args.match(.{tp.extract(&egc)}) catch return error.Stop))
|
if (!(ctx.args.match(.{tp.extract(&egc)}) catch return error.Stop))
|
||||||
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 begin: Cursor = undefined;
|
||||||
var sel_length: usize = 1;
|
var sel_length: usize = 1;
|
||||||
if (cursel.selection) |*sel| {
|
if (cursel.selection) |*sel| {
|
||||||
|
|
@ -911,7 +911,7 @@ fn replace_cursel_with_character(ed: *Editor, root: Buffer.Root, cursel: *CurSel
|
||||||
|
|
||||||
if (no_selection) {
|
if (no_selection) {
|
||||||
try cursel.cursor.move_left(root, ed.metrics);
|
try cursel.cursor.move_left(root, ed.metrics);
|
||||||
cursel.disable_selection(root, ed.metrics);
|
cursel.disable_selection();
|
||||||
} else {
|
} else {
|
||||||
cursel.selection = Selection{ .begin = begin, .end = cursel.cursor };
|
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 {
|
fn add_cursors_to_cursel_line_ends_helix(ed: *Editor, root: Buffer.Root, cursel: *CurSel) !void {
|
||||||
const original_cursel = cursel.*;
|
const original_cursel = cursel.*;
|
||||||
const sel = cursel.enable_selection(root, ed.metrics);
|
const sel = cursel.enable_selection();
|
||||||
sel.normalize();
|
sel.normalize();
|
||||||
var row = sel.begin.row;
|
var row = sel.begin.row;
|
||||||
const is_multiline = sel.begin.row != sel.end.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;
|
var root_: Buffer.Root = root;
|
||||||
const cursor: *Cursor = &cursel.cursor;
|
const cursor: *Cursor = &cursel.cursor;
|
||||||
|
|
||||||
cursel.check_selection(root, editor.metrics);
|
cursel.check_selection();
|
||||||
if (cursel.selection) |sel_| {
|
if (cursel.selection) |sel_| {
|
||||||
var sel = sel_;
|
var sel = sel_;
|
||||||
sel.normalize();
|
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
|
// replaces the selection, if no selection, replaces the current
|
||||||
// character and sets the selection to the replacement text
|
// character and sets the selection to the replacement text
|
||||||
var root_: Buffer.Root = root;
|
var root_: Buffer.Root = root;
|
||||||
cursel.check_selection(root, editor.metrics);
|
cursel.check_selection();
|
||||||
|
|
||||||
if (cursel.selection == null) {
|
if (cursel.selection == null) {
|
||||||
// Select current character to replace it
|
// 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 {
|
fn insert_after(editor: *Editor, root: Buffer.Root, cursel: *CurSel, text: []const u8, allocator: Allocator) !Buffer.Root {
|
||||||
var root_: Buffer.Root = root;
|
var root_: Buffer.Root = root;
|
||||||
const cursor = &cursel.cursor;
|
const cursor = &cursel.cursor;
|
||||||
cursel.check_selection(root, editor.metrics);
|
cursel.check_selection();
|
||||||
if (text[text.len - 1] == '\n') {
|
if (text[text.len - 1] == '\n') {
|
||||||
move_cursor_carriage_return(root, cursel.*, cursor, editor.metrics) catch {};
|
move_cursor_carriage_return(root, cursel.*, cursor, editor.metrics) catch {};
|
||||||
} else {
|
} 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);
|
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_| {
|
if (cursel.selection) |*sel_| {
|
||||||
const sel: *Selection = sel_;
|
const sel: *Selection = sel_;
|
||||||
if (sel.*.empty()) {
|
if (sel.*.empty()) {
|
||||||
|
|
@ -1279,7 +1279,7 @@ fn select_char_if_no_selection(cursel: *CurSel, root: Buffer.Root, metrics: Buff
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} 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 };
|
sel.begin = .{ .row = cursel.cursor.row, .col = cursel.cursor.col + 1, .target = cursel.cursor.target + 1 };
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1805,10 +1805,6 @@ pub fn is_cursor_beam() bool {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_selection_style() @import("Buffer").Selection.Style {
|
|
||||||
return if (current().input_mode_) |mode| mode.selection_style else .normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn message(comptime fmt: anytype, args: anytype) void {
|
pub fn message(comptime fmt: anytype, args: anytype) void {
|
||||||
var buf: [256]u8 = undefined;
|
var buf: [256]u8 = undefined;
|
||||||
tp.self_pid().send(.{ "message", std.fmt.bufPrint(&buf, fmt, args) catch @panic("too large") }) catch {};
|
tp.self_pid().send(.{ "message", std.fmt.bufPrint(&buf, fmt, args) catch @panic("too large") }) catch {};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue