diff --git a/include/internal/buffer/types/generic.h b/include/internal/buffer/types/generic.h index 7a1a3f9..bc99cc6 100644 --- a/include/internal/buffer/types/generic.h +++ b/include/internal/buffer/types/generic.h @@ -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 undo_stack; std::vector redo_stack; diff --git a/src/internal/buffer/generic.cc b/src/internal/buffer/generic.cc index 6899679..2a0932e 100644 --- a/src/internal/buffer/generic.cc +++ b/src/internal/buffer/generic.cc @@ -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,15 +90,19 @@ HistoryBuffer *GenericBuffer::get_history(uint64_t version) { } void GenericBuffer::snapshot(std::string action_) { - vase::Shard::retain(root); - undo_stack.push_back( - HistoryItem{ - syntax::retain(parse), - root, - timestamp, - action - } - ); + if (base_version == 0) { + base_version++; + } else { + vase::Shard::retain(root); + undo_stack.push_back( + HistoryItem{ + syntax::retain(parse), + root, + timestamp, + 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; diff --git a/src/internal/functions/extended.cc b/src/internal/functions/extended.cc index 6d1939b..5a6333a 100644 --- a/src/internal/functions/extended.cc +++ b/src/internal/functions/extended.cc @@ -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,