Compare commits
No commits in common. "281b9e47a1c33f309703bc587540ebcba9b53386" and "9fb9b45c4dc7f43cc73533f9b3d8435045b84def" have entirely different histories.
281b9e47a1
...
9fb9b45c4d
5 changed files with 0 additions and 112 deletions
|
|
@ -13,7 +13,6 @@ const Self = @This();
|
||||||
const max_imbalance = 7;
|
const max_imbalance = 7;
|
||||||
pub const Root = *const Node;
|
pub const Root = *const Node;
|
||||||
pub const unicode = @import("unicode.zig");
|
pub const unicode = @import("unicode.zig");
|
||||||
pub const reflow = @import("reflow.zig").reflow;
|
|
||||||
|
|
||||||
pub const Manager = @import("Manager.zig");
|
pub const Manager = @import("Manager.zig");
|
||||||
pub const Cursor = @import("Cursor.zig");
|
pub const Cursor = @import("Cursor.zig");
|
||||||
|
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
pub fn reflow(allocator: std.mem.Allocator, text: []const u8, width: usize) error{ OutOfMemory, WriteFailed }![]u8 {
|
|
||||||
const prefix = detect_prefix(text);
|
|
||||||
const words = try split_words(allocator, text, prefix.len);
|
|
||||||
defer allocator.free(words);
|
|
||||||
var output: std.Io.Writer.Allocating = .init(allocator);
|
|
||||||
const writer = &output.writer;
|
|
||||||
|
|
||||||
var first = true;
|
|
||||||
var line_len: usize = 0;
|
|
||||||
for (words) |word| {
|
|
||||||
if (line_len == 0) {
|
|
||||||
if (first) {
|
|
||||||
try writer.writeAll(prefix.first);
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
try writer.writeAll(prefix.continuation);
|
|
||||||
var pad = prefix.first.len - prefix.continuation.len;
|
|
||||||
while (pad > 0) : (pad -= 1)
|
|
||||||
try writer.writeByte(' ');
|
|
||||||
}
|
|
||||||
line_len += prefix.len;
|
|
||||||
}
|
|
||||||
if (line_len > prefix.len)
|
|
||||||
try writer.writeByte(' ');
|
|
||||||
try writer.writeAll(word);
|
|
||||||
line_len += word.len;
|
|
||||||
if (line_len >= width) {
|
|
||||||
try writer.writeByte('\n');
|
|
||||||
line_len = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output.toOwnedSlice();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn split_words(allocator: std.mem.Allocator, text: []const u8, prefix: usize) error{OutOfMemory}![]const []const u8 {
|
|
||||||
var words: std.ArrayList([]const u8) = .empty;
|
|
||||||
var lines = std.mem.splitScalar(u8, text, '\n');
|
|
||||||
while (lines.next()) |line| {
|
|
||||||
if (line.len <= prefix) continue;
|
|
||||||
var it = std.mem.splitAny(u8, line[prefix..], " \t");
|
|
||||||
while (it.next()) |word| if (word.len > 0) {
|
|
||||||
(try words.addOne(allocator)).* = word;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return words.toOwnedSlice(allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn detect_prefix(text: []const u8) Prefix {
|
|
||||||
var lines = std.mem.splitScalar(u8, text, '\n');
|
|
||||||
const line1 = lines.next() orelse return .{};
|
|
||||||
var prefix: []const u8 = line1;
|
|
||||||
while (lines.next()) |line|
|
|
||||||
prefix = lcp(prefix, line);
|
|
||||||
|
|
||||||
if (line1.len > prefix.len + 2 and line1[prefix.len] == '-' and line1[prefix.len + 1] == ' ') {
|
|
||||||
const first = line1[0 .. prefix.len + 2];
|
|
||||||
return .{
|
|
||||||
.len = first.len,
|
|
||||||
.first = first,
|
|
||||||
.continuation = prefix,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return .{
|
|
||||||
.len = prefix.len,
|
|
||||||
.first = prefix,
|
|
||||||
.continuation = prefix,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const Prefix = struct {
|
|
||||||
len: usize = 0,
|
|
||||||
first: []const u8 = &.{},
|
|
||||||
continuation: []const u8 = &.{},
|
|
||||||
};
|
|
||||||
|
|
||||||
fn lcp(a: []const u8, b: []const u8) []const u8 {
|
|
||||||
const len = @min(a.len, b.len);
|
|
||||||
for (0..len) |i| if (a[i] != b[i])
|
|
||||||
return a[0..i];
|
|
||||||
return a[0..len];
|
|
||||||
}
|
|
||||||
|
|
||||||
const std = @import("std");
|
|
||||||
|
|
@ -45,7 +45,6 @@ auto_run_commands: ?[]const []const u8 = &.{"save_session_quiet"}, // a list of
|
||||||
indent_size: usize = 4,
|
indent_size: usize = 4,
|
||||||
tab_width: usize = 8,
|
tab_width: usize = 8,
|
||||||
indent_mode: IndentMode = .auto,
|
indent_mode: IndentMode = .auto,
|
||||||
reflow_width: usize = 80,
|
|
||||||
|
|
||||||
top_bar: []const u8 = "tabs",
|
top_bar: []const u8 = "tabs",
|
||||||
bottom_bar: []const u8 = "mode file log selection diagnostics keybind branch linenumber clock spacer",
|
bottom_bar: []const u8 = "mode file log selection diagnostics keybind branch linenumber clock spacer",
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,6 @@
|
||||||
["alt+p", "goto_prev_file_or_diagnostic"],
|
["alt+p", "goto_prev_file_or_diagnostic"],
|
||||||
["alt+u", "to_upper"],
|
["alt+u", "to_upper"],
|
||||||
["alt+l", "to_lower"],
|
["alt+l", "to_lower"],
|
||||||
["alt+q", "reflow"],
|
|
||||||
["alt+c", "switch_case"],
|
["alt+c", "switch_case"],
|
||||||
["ctrl+_", "underline"],
|
["ctrl+_", "underline"],
|
||||||
["ctrl+=", "underline_with_char", "=", "solid"],
|
["ctrl+=", "underline_with_char", "=", "solid"],
|
||||||
|
|
|
||||||
|
|
@ -6818,30 +6818,6 @@ 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 {
|
|
||||||
var root = root_;
|
|
||||||
var sel = cursel.selection orelse return root;
|
|
||||||
sel.normalize();
|
|
||||||
var sfa = std.heap.stackFallback(4096, self.allocator);
|
|
||||||
const sfa_allocator = sfa.get();
|
|
||||||
const cut_text = copy_selection(root, sel, sfa_allocator, self.metrics) catch return error.Stop;
|
|
||||||
defer sfa_allocator.free(cut_text);
|
|
||||||
const reflowed = Buffer.reflow(sfa_allocator, cut_text, tui.config().reflow_width) catch return error.Stop;
|
|
||||||
defer sfa_allocator.free(reflowed);
|
|
||||||
root = try self.delete_selection(root, cursel, allocator);
|
|
||||||
root = self.insert(root, cursel, reflowed, allocator) catch return error.Stop;
|
|
||||||
cursel.selection = .{ .begin = sel.begin, .end = cursel.cursor };
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reflow(self: *Self, _: Context) Result {
|
|
||||||
const b = try self.buf_for_update();
|
|
||||||
const root = try self.with_cursels_mut_once(b.root, reflow_cursel, b.allocator);
|
|
||||||
try self.update_buf(root);
|
|
||||||
self.clamp();
|
|
||||||
}
|
|
||||||
pub const reflow_meta: Meta = .{ .description = "Reflow selection" };
|
|
||||||
|
|
||||||
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_;
|
||||||
const saved = cursel.*;
|
const saved = cursel.*;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue