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