Fix bugs with history setup.
This commit is contained in:
@@ -14,10 +14,8 @@ struct HistoryItem {
|
||||
|
||||
struct GenericBuffer : ShardBuffer {
|
||||
uint64_t base_version{0};
|
||||
std::chrono::system_clock::time_point timestamp{
|
||||
std::chrono::system_clock::now()
|
||||
};
|
||||
std::string action{"created"};
|
||||
std::chrono::system_clock::time_point timestamp;
|
||||
std::string action;
|
||||
std::filesystem::path save_path{};
|
||||
std::vector<HistoryItem> undo_stack;
|
||||
std::vector<HistoryItem> redo_stack;
|
||||
|
||||
@@ -39,7 +39,7 @@ void GenericBuffer::list_history(BEd &ctx) {
|
||||
std::tm tm = *std::localtime(&time);
|
||||
ctx.io.write_line(
|
||||
std::format(
|
||||
"X {} {:04}-{:02}-{:02} {:02}:{:02}:{:02} {}",
|
||||
"* {} {:04}-{:02}-{:02} {:02}:{:02}:{:02} {}",
|
||||
current,
|
||||
tm.tm_year + 1900,
|
||||
tm.tm_mon + 1,
|
||||
@@ -58,7 +58,7 @@ void GenericBuffer::list_history(BEd &ctx) {
|
||||
std::tm tm = *std::localtime(&time);
|
||||
ctx.io.write_line(
|
||||
std::format(
|
||||
" {} {:04}-{:02}-{:02} {:02}:{:02}:{:02}",
|
||||
" {} {:04}-{:02}-{:02} {:02}:{:02}:{:02} {}",
|
||||
version,
|
||||
tm.tm_year + 1900,
|
||||
tm.tm_mon + 1,
|
||||
@@ -90,6 +90,9 @@ HistoryBuffer *GenericBuffer::get_history(uint64_t version) {
|
||||
}
|
||||
|
||||
void GenericBuffer::snapshot(std::string action_) {
|
||||
if (base_version == 0) {
|
||||
base_version++;
|
||||
} else {
|
||||
vase::Shard::retain(root);
|
||||
undo_stack.push_back(
|
||||
HistoryItem{
|
||||
@@ -99,6 +102,7 @@ void GenericBuffer::snapshot(std::string action_) {
|
||||
action
|
||||
}
|
||||
);
|
||||
}
|
||||
for (auto &item : redo_stack) {
|
||||
syntax::release(item.parse_state);
|
||||
vase::Shard::release(item.text);
|
||||
@@ -126,6 +130,8 @@ bool GenericBuffer::undo(BEd &ctx) {
|
||||
root = prev.text;
|
||||
syntax::release(parse);
|
||||
parse = prev.parse_state;
|
||||
timestamp = prev.timestamp;
|
||||
action = prev.summary;
|
||||
state = Modified;
|
||||
if (!root) {
|
||||
ctx.prev().buffername = name;
|
||||
@@ -157,6 +163,8 @@ bool GenericBuffer::redo(BEd &ctx) {
|
||||
root = next.text;
|
||||
syntax::release(parse);
|
||||
parse = next.parse_state;
|
||||
timestamp = next.timestamp;
|
||||
action = next.summary;
|
||||
state = Modified;
|
||||
if (!root) {
|
||||
ctx.prev().buffername = name;
|
||||
|
||||
@@ -125,7 +125,7 @@ void Function::register_extented(BEd &ctx) {
|
||||
}
|
||||
);
|
||||
ctx.functions.insert(
|
||||
"history-list",
|
||||
"hl",
|
||||
Function{
|
||||
.address_kind = Function::AddressKind::None,
|
||||
.argument_kind = Function::ArgumentKind::None,
|
||||
|
||||
Reference in New Issue
Block a user