feat: add integer arg support to reflow command
This commit is contained in:
parent
4803daec3e
commit
9f775c9ec8
1 changed files with 10 additions and 5 deletions
|
|
@ -6829,7 +6829,9 @@ pub const Editor = struct {
|
||||||
self.filter_ = null;
|
self.filter_ = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reflow_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
|
fn reflow_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator, ctx: Context) error{Stop}!Buffer.Root {
|
||||||
|
var reflow_width: usize = tui.config().reflow_width;
|
||||||
|
_ = ctx.args.match(.{tp.extract(&reflow_width)}) catch {};
|
||||||
var root = root_;
|
var root = root_;
|
||||||
var sel = cursel.selection orelse return root;
|
var sel = cursel.selection orelse return root;
|
||||||
sel.normalize();
|
sel.normalize();
|
||||||
|
|
@ -6837,7 +6839,7 @@ pub const Editor = struct {
|
||||||
const sfa_allocator = sfa.get();
|
const sfa_allocator = sfa.get();
|
||||||
const cut_text = copy_selection(root, sel, sfa_allocator, self.metrics) catch return error.Stop;
|
const cut_text = copy_selection(root, sel, sfa_allocator, self.metrics) catch return error.Stop;
|
||||||
defer sfa_allocator.free(cut_text);
|
defer sfa_allocator.free(cut_text);
|
||||||
const reflowed = Buffer.reflow(sfa_allocator, cut_text, tui.config().reflow_width) catch return error.Stop;
|
const reflowed = Buffer.reflow(sfa_allocator, cut_text, reflow_width) catch return error.Stop;
|
||||||
defer sfa_allocator.free(reflowed);
|
defer sfa_allocator.free(reflowed);
|
||||||
root = try self.delete_selection(root, cursel, allocator);
|
root = try self.delete_selection(root, cursel, allocator);
|
||||||
root = self.insert(root, cursel, reflowed, allocator) catch return error.Stop;
|
root = self.insert(root, cursel, reflowed, allocator) catch return error.Stop;
|
||||||
|
|
@ -6845,13 +6847,16 @@ pub const Editor = struct {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reflow(self: *Self, _: Context) Result {
|
pub fn reflow(self: *Self, ctx: Context) Result {
|
||||||
const b = try self.buf_for_update();
|
const b = try self.buf_for_update();
|
||||||
const root = try self.with_cursels_mut_once(b.root, reflow_cursel, b.allocator);
|
const root = try self.with_cursels_mut_once_arg(b.root, reflow_cursel, b.allocator, ctx);
|
||||||
try self.update_buf(root);
|
try self.update_buf(root);
|
||||||
self.clamp();
|
self.clamp();
|
||||||
}
|
}
|
||||||
pub const reflow_meta: Meta = .{ .description = "Reflow selection" };
|
pub const reflow_meta: Meta = .{
|
||||||
|
.description = "Reflow selection",
|
||||||
|
.arguments = &.{.integer},
|
||||||
|
};
|
||||||
|
|
||||||
fn to_upper_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
|
fn to_upper_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
|
||||||
var root = root_;
|
var root = root_;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue