diff options
Diffstat (limited to 'src/File.zig')
| -rw-r--r-- | src/File.zig | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/src/File.zig b/src/File.zig index fc50051c..82661c6d 100644 --- a/src/File.zig +++ b/src/File.zig @@ -27,20 +27,6 @@ const Text = panes.Text; const SYNTAX_CONTEXT_AFTER_ROWS: usize = 2; const long_paint: usize = 16 << 10; -/// Where the pane is in its text and what the text is saved as now: an -/// undo step's edge (Text.Place), kept once, never a copy of the text. -fn placeOf(pane: *const Pane, f: *const State) Text.Place { - return .{ - .cur_row = pane.body.cur_row, - .cur_col = pane.body.cur_col, - .vsel = pane.body.vsel, - .gen = f.history.gen, - .clean = f.revision == f.saved_revision, - .saved_hash = f.saved_hash, - .saved_len = f.saved_len, - }; -} - /// A rename (ninep/pane.zig nameBuffer): the name it ends, kept for an undo /// back across it; `old` is the History's from here (owned), freed if it /// cannot be kept. @@ -49,38 +35,6 @@ pub fn noteRenamed(gpa: std.mem.Allocator, history: *History, old: []u8) void { history.gen +%= 1; } -/// After a step's text went in: if it was under another name, that name -/// back, and the step's saved state with it (Get file, Edit's e), as acme's -/// undo puts them back with the text. -fn restoreName(p: *Pardes, pane: *Pane, f: *State, snap: Text.Place) void { - const history = f.history; - if (snap.gen == history.gen) return; - // The latest name kept for that generation. - var at = history.names.items.len; - const path = while (at > 0) { - at -= 1; - if (history.names.items[at].gen == snap.gen) break history.names.items[at].path; - } else return; - if (std.mem.eql(u8, path, f.path)) { - history.gen = snap.gen; - return; - } - const id = for (p.panes, 0..) |slot, i| { - if (slot == pane) break i; - } else return; - // nameBuffer frees nothing of `path`: it keeps the name it ends. - const back = p.gpa.dupe(u8, path) catch |err| return p.reportError(id, "undo", err); - defer p.gpa.free(back); - pardes.ctlfs.pane.nameBuffer(p, id, back, false) catch |err| return p.reportError(id, "undo", err); - history.gen = snap.gen; - f.saved_hash = snap.saved_hash; - f.saved_len = snap.saved_len; - f.saved_revision = if (snap.clean) f.revision else f.revision -% 1; - f.disk_newer = null; - f.disk_newer_warned = false; - if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); -} - /// A file's undo, which its twins (Zerox) share: its edits as a journal /// (Text.Journal), and the names it had. pub const History = struct { @@ -1231,6 +1185,52 @@ pub fn looksLikeDiff(head: []const u8) bool { return diff.looksLikeDiff(lines[0..n]); } +/// Where the pane is in its text and what the text is saved as now: an +/// undo step's edge (Text.Place), kept once, never a copy of the text. +fn placeOf(pane: *const Pane, f: *const State) Text.Place { + return .{ + .cur_row = pane.body.cur_row, + .cur_col = pane.body.cur_col, + .vsel = pane.body.vsel, + .gen = f.history.gen, + .clean = f.revision == f.saved_revision, + .saved_hash = f.saved_hash, + .saved_len = f.saved_len, + }; +} + +/// After a step's text went in: if it was under another name, that name +/// back, and the step's saved state with it (Get file, Edit's e), as acme's +/// undo puts them back with the text. +fn restoreName(p: *Pardes, pane: *Pane, f: *State, snap: Text.Place) void { + const history = f.history; + if (snap.gen == history.gen) return; + // The latest name kept for that generation. + var at = history.names.items.len; + const path = while (at > 0) { + at -= 1; + if (history.names.items[at].gen == snap.gen) break history.names.items[at].path; + } else return; + if (std.mem.eql(u8, path, f.path)) { + history.gen = snap.gen; + return; + } + const id = for (p.panes, 0..) |slot, i| { + if (slot == pane) break i; + } else return; + // nameBuffer frees nothing of `path`: it keeps the name it ends. + const back = p.gpa.dupe(u8, path) catch |err| return p.reportError(id, "undo", err); + defer p.gpa.free(back); + pardes.ctlfs.pane.nameBuffer(p, id, back, false) catch |err| return p.reportError(id, "undo", err); + history.gen = snap.gen; + f.saved_hash = snap.saved_hash; + f.saved_len = snap.saved_len; + f.saved_revision = if (snap.clean) f.revision else f.revision -% 1; + f.disk_newer = null; + f.disk_newer_warned = false; + if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); +} + pub fn restoreSnap(pane: *Pane, f: *State, snap: Text.Place) void { const n = nlines(pane.gpa, f); const row: usize = @min(@as(usize, @intCast(@max(0, snap.cur_row))), n - 1); |
