Expose file and Pi panels
This commit is contained in:
+20
-2
@@ -26,6 +26,7 @@ pub const Action = union(enum) {
|
||||
open: []u8,
|
||||
symbol: symbol_mod.Symbol,
|
||||
file_picker,
|
||||
pi_panel,
|
||||
search_file,
|
||||
search_project,
|
||||
hover,
|
||||
@@ -102,7 +103,7 @@ pub const Leader = struct {
|
||||
if (self.message) |message| return message;
|
||||
return switch (self.mode) {
|
||||
.idle => "",
|
||||
.rail => "leader: w save q quit Q discard o open p symbols s search r repeat",
|
||||
.rail => "leader: w save q quit Q discard f files P Pi o open p symbols s search r repeat",
|
||||
.symbol_rail => symbol_mod.rail_status,
|
||||
.search_rail => "search: f current file p project s symbols",
|
||||
.language_rail => "language: h hover s sig f fmt o imports a actions (Space path)",
|
||||
@@ -181,6 +182,10 @@ pub const Leader = struct {
|
||||
self.mode = .idle;
|
||||
return .file_picker;
|
||||
}
|
||||
if (std.mem.eql(u8, text, "P")) {
|
||||
self.mode = .idle;
|
||||
return .pi_panel;
|
||||
}
|
||||
if (std.mem.eql(u8, text, "p")) {
|
||||
self.mode = .symbol_rail;
|
||||
return .none;
|
||||
@@ -448,7 +453,7 @@ test "regular: space opens a visible leader rail and write dispatches" {
|
||||
defer leader.deinit();
|
||||
|
||||
try expectActionTag(.none, try leader.handleEvent(input.normalize(" ")));
|
||||
try std.testing.expectEqualStrings("leader: w save q quit Q discard o open p symbols s search r repeat", leader.status());
|
||||
try std.testing.expectEqualStrings("leader: w save q quit Q discard f files P Pi o open p symbols s search r repeat", leader.status());
|
||||
|
||||
try expectActionTag(.save, try leader.handleEvent(input.normalize("w")));
|
||||
try std.testing.expect(!leader.isActive());
|
||||
@@ -576,3 +581,16 @@ test "adversarial: unknown and cancelled symbol rail inputs do not dispatch" {
|
||||
try expectActionTag(.none, try leader.handleEvent(input.normalize("\x1b")));
|
||||
try std.testing.expectEqualStrings("symbol rail cancelled", leader.status());
|
||||
}
|
||||
|
||||
test "regular: leader exposes files and Pi panels" {
|
||||
var leader = Leader.init(std.testing.allocator);
|
||||
defer leader.deinit();
|
||||
|
||||
try expectActionTag(.none, try leader.handleEvent(input.normalize(" ")));
|
||||
try std.testing.expect(std.mem.indexOf(u8, leader.status(), "f files") != null);
|
||||
try std.testing.expect(std.mem.indexOf(u8, leader.status(), "P Pi") != null);
|
||||
try expectActionTag(.file_picker, try leader.handleEvent(input.normalize("f")));
|
||||
|
||||
try expectActionTag(.none, try leader.handleEvent(input.normalize(" ")));
|
||||
try expectActionTag(.pi_panel, try leader.handleEvent(input.normalize("P")));
|
||||
}
|
||||
|
||||
+22
@@ -1313,6 +1313,15 @@ pub const Client = struct {
|
||||
self.panel_context = .file_picker;
|
||||
}
|
||||
|
||||
fn openPiPanel(self: *Client) !void {
|
||||
const rows = [_][]const u8{
|
||||
"pi_ask:explain_current_buffer",
|
||||
"pi_edit:propose_patch",
|
||||
"pi_review:critique_diff",
|
||||
};
|
||||
try self.openListRows("pi", rows[0..], .none);
|
||||
}
|
||||
|
||||
fn openListRows(self: *Client, title: []const u8, rows: []const []const u8, context: PanelContext) !void {
|
||||
if (rows.len == 0) {
|
||||
self.message = "empty list";
|
||||
@@ -2426,6 +2435,7 @@ pub const Client = struct {
|
||||
},
|
||||
.symbol => |symbol| try self.applyProtocol(symbol_mod.protocolCommand(symbol)),
|
||||
.file_picker => try self.openFilePickerPanel(),
|
||||
.pi_panel => try self.openPiPanel(),
|
||||
.search_file => self.openSearchPrompt(),
|
||||
.search_project => self.openProjectSearchPrompt(),
|
||||
.hover => try self.showCompactHover(),
|
||||
@@ -5353,3 +5363,15 @@ test "regular: dot repeats put and remains undoable" {
|
||||
snap = try client.session.snapshot();
|
||||
try std.testing.expectEqualStrings("abcabc", snap.bytes);
|
||||
}
|
||||
|
||||
test "regular: Space P opens Pi panel" {
|
||||
var client = try Client.init(std.testing.allocator, .{ .width = 56, .height = 10 });
|
||||
defer client.deinit();
|
||||
|
||||
try client.handleInput(" ");
|
||||
try client.handleInput("P");
|
||||
const frame = try client.render(std.testing.allocator);
|
||||
defer std.testing.allocator.free(frame);
|
||||
try std.testing.expect(std.mem.indexOf(u8, frame, "panel [pi]") != null);
|
||||
try std.testing.expect(std.mem.indexOf(u8, frame, "pi_ask:explain_current_buffer") != null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user