summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/edit.zig12
-rw-r--r--src/normal.zig6
2 files changed, 17 insertions, 1 deletions
diff --git a/src/edit.zig b/src/edit.zig
index 39050b9d..01b34237 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -13,6 +13,7 @@ const body_layer = @import("body_layer.zig");
const config = @import("config.zig");
const pdf_enabled = panes.Pdf.enabled;
const lsp = @import("lsp/lsp.zig");
+const syntax = @import("syntax.zig");
const platform = pardes.platform;
const Pane = panes.Pane;
const Text = panes.Text;
@@ -929,6 +930,17 @@ fn insertEdit(p: *Pardes, t: *Text, key: Key) void {
p.lspRequest(p.active, .completion, "");
if (p.lsp_seq != seq) return;
}
+ // helix smart_tab: after text, Tab leaves the syntax node the
+ // cursor is in; only where the file has a grammar, since the
+ // reference pins smart tab off, which a file without one agrees
+ // with. Shift-Tab always types the tab.
+ const after_text = std.mem.indexOfNone(u8, ln[0..@min(c.col, ln.len)], " \t") != null;
+ if (!key.shift and after_text and t.what == .body) smart: {
+ const pane = t.pane() orelse break :smart;
+ const f = pane.file orelse break :smart;
+ if (!syntax.supportsPath(f.path)) break :smart;
+ return normal.nodeSelect(p, pane, t, .parent_end);
+ }
insertTab(p, t);
},
else => {},
diff --git a/src/normal.zig b/src/normal.zig
index 228c9c39..f9d7cf25 100644
--- a/src/normal.zig
+++ b/src/normal.zig
@@ -171,7 +171,7 @@ pub fn applySelRegex(p: *Pardes, pane: *Pane, t: *Text, pat: []const u8, mode: m
/// which is made on the first of these keys after an edit and kept, never
/// made again for a key that changed nothing. A range the tree has nothing
/// to say about stays as it was; a text without a grammar, all of them.
-fn nodeSelect(p: *Pardes, pane: *Pane, t: *Text, walk: modal.Normal.NodeWalk) void {
+pub fn nodeSelect(p: *Pardes, pane: *Pane, t: *Text, walk: modal.Normal.NodeWalk) void {
if (t.what != .body) return;
const f = if (pane.file) |*file| file else return;
if (f.node_tree == null or f.node_tree_revision != f.revision) {
@@ -945,6 +945,8 @@ test "tree-sitter selection keys do in a JSON file what hx 25.07.1 does" {
.{ .keys = "6lx\x1bid", .want = "\n" },
.{ .keys = "10l\x1beiX\x1b", .want = "{\"a\": [1, 2X, 3], \"b\": true}\n" },
.{ .keys = "10l\x1bb\x1bbiX\x1b", .want = "{X\"a\": [1, 2, 3], \"b\": true}\n" },
+ // insert Tab after text leaves the node (smart tab)
+ .{ .keys = "8li\tX\x1b", .want = "{\"a\": [1, 2, 3]X, \"b\": true}\n" },
}) |c| {
const pane = try p.setTestFile(text);
p.gpa.free(pane.file.?.path);
@@ -959,6 +961,8 @@ test "tree-sitter selection keys do in a JSON file what hx 25.07.1 does" {
p.update(.{ .key = if (k == '>') .{ .cp = Key.right, .alt = true } else .{ .cp = k, .alt = true } });
} else if (ch == 0x1b) {
p.update(.{ .key = .{ .cp = Key.escape } });
+ } else if (ch == '\t') {
+ p.update(.{ .key = .{ .cp = Key.tab } });
} else p.update(.{ .key = .{ .cp = ch, .text = c.keys[i..][0..1] } });
while (p.nextEffect()) |_| {}
}