Add history support, and fix parsing system.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "clip.h"
|
||||
#include "./types/clip.h"
|
||||
#include "./types/generic.h"
|
||||
#include "decl.h"
|
||||
#include "generic.h"
|
||||
#include "pch.h"
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace bed::internal::buffer {
|
||||
struct Buffer {
|
||||
enum struct Kind : uint8_t {
|
||||
Generic,
|
||||
Null,
|
||||
History,
|
||||
Clip,
|
||||
Cancel,
|
||||
Shell,
|
||||
@@ -26,7 +26,7 @@ struct Buffer {
|
||||
std::string name;
|
||||
|
||||
explicit Buffer(std::string name, Kind kind)
|
||||
: kind(kind), state(Unmodified), name(name) {};
|
||||
: kind(kind), state(Unmodified), name(std::move(name)) {};
|
||||
virtual ~Buffer() = default;
|
||||
|
||||
virtual bool waste() = 0;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "decl.h"
|
||||
#include "pch.h"
|
||||
#include "../decl.h"
|
||||
|
||||
namespace bed::internal::buffer {
|
||||
struct ClipBuffer : Buffer {
|
||||
@@ -1,26 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "decl.h"
|
||||
#include "pch.h"
|
||||
#include "../decl.h"
|
||||
#include "history.h"
|
||||
#include "shard.h"
|
||||
|
||||
namespace bed::internal::buffer {
|
||||
struct GenericBuffer : Buffer {
|
||||
vase::Shard *root;
|
||||
struct HistoryItem {
|
||||
syntax::ParserSnapshot parse_state;
|
||||
vase::Shard *text;
|
||||
std::chrono::system_clock::time_point timestamp;
|
||||
std::string summary;
|
||||
};
|
||||
|
||||
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::filesystem::path save_path{};
|
||||
std::string language{};
|
||||
std::optional<syntax::Parser> parser{};
|
||||
std::vector<HistoryItem> undo_stack;
|
||||
std::vector<HistoryItem> redo_stack;
|
||||
|
||||
GenericBuffer(std::string name)
|
||||
: Buffer(name, Kind::Generic), root(nullptr) {};
|
||||
: ShardBuffer(name, nullptr, nullptr, Kind::Generic) {}
|
||||
~GenericBuffer();
|
||||
|
||||
void list_history(BEd &ctx);
|
||||
HistoryBuffer *get_history(uint64_t version);
|
||||
void snapshot(std::string action);
|
||||
bool undo(BEd &ctx);
|
||||
bool redo(BEd &ctx);
|
||||
void prune(int = 0);
|
||||
bool waste() override;
|
||||
uint64_t lines() override;
|
||||
uint64_t bytes() override;
|
||||
void load(BEd &ctx, vase::Shard *text) override;
|
||||
void set_filename(std::filesystem::path path) override;
|
||||
std::filesystem::path filename() override;
|
||||
vase::Shard *copy(uint64_t start_line, uint64_t end_line) override;
|
||||
void substitute(
|
||||
BEd &ctx, uint64_t start_line, uint64_t end_line,
|
||||
std::string ®ex, std::string &replacement, std::string &options
|
||||
@@ -29,12 +44,5 @@ struct GenericBuffer : Buffer {
|
||||
void remove(BEd &ctx, uint64_t start_line, uint64_t end_line) override;
|
||||
void append(BEd &ctx, vase::Shard *text, uint64_t line) override;
|
||||
void replace(BEd &ctx, vase::Shard *text, uint64_t start_line, uint64_t end_line) override;
|
||||
void print(BEd &ctx, uint64_t start_line, uint64_t end_line) override;
|
||||
void number_print(BEd &ctx, uint64_t start_line, uint64_t end_line) override;
|
||||
void list_print(BEd &ctx, uint64_t start_line, uint64_t end_line) override;
|
||||
uint64_t next_closing(uint64_t start) override;
|
||||
uint64_t prev_closing(uint64_t start) override;
|
||||
uint64_t find_next(std::string_view pattern, uint64_t start) override;
|
||||
uint64_t find_prev(std::string_view pattern, uint64_t start) override;
|
||||
};
|
||||
} // namespace bed::internal::buffer
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "../decl.h"
|
||||
#include "shard.h"
|
||||
|
||||
namespace bed::internal::buffer {
|
||||
struct HistoryBuffer : ShardBuffer {
|
||||
HistoryBuffer(
|
||||
std::string name, vase::Shard *root,
|
||||
const syntax::ParserSnapshot &snapshot
|
||||
) : ShardBuffer(std::move(name), root, snapshot, Kind::History) {}
|
||||
|
||||
bool waste() override {
|
||||
return true;
|
||||
}
|
||||
void load(BEd &, vase::Shard *) override {
|
||||
throw ed_error("History buffers are read-only.");
|
||||
}
|
||||
void set_filename(std::filesystem::path) override {}
|
||||
std::filesystem::path filename() override {
|
||||
return {};
|
||||
}
|
||||
void substitute(BEd &, uint64_t, uint64_t, std::string &, std::string &, std::string &) override {
|
||||
throw ed_error("History buffers are read-only.");
|
||||
}
|
||||
void join(BEd &, uint64_t, uint64_t) override {
|
||||
throw ed_error("History buffers are read-only.");
|
||||
}
|
||||
void remove(BEd &, uint64_t, uint64_t) override {
|
||||
throw ed_error("History buffers are read-only.");
|
||||
}
|
||||
void append(BEd &, vase::Shard *, uint64_t) override {
|
||||
throw ed_error("History buffers are read-only.");
|
||||
}
|
||||
void replace(BEd &, vase::Shard *, uint64_t, uint64_t) override {
|
||||
throw ed_error("History buffers are read-only.");
|
||||
}
|
||||
};
|
||||
} // namespace bed::internal::buffer
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "../decl.h"
|
||||
|
||||
namespace bed::internal::buffer {
|
||||
struct ShardBuffer : Buffer {
|
||||
vase::Shard *root;
|
||||
syntax::ParserSnapshot parse{};
|
||||
|
||||
ShardBuffer(std::string name, vase::Shard *root, syntax::Language *language, Kind kind)
|
||||
: Buffer(std::move(name), kind), root(root) {
|
||||
vase::Shard::retain(root);
|
||||
if (language)
|
||||
parse = syntax::make_parser(root, lines(), language);
|
||||
}
|
||||
ShardBuffer(
|
||||
std::string name,
|
||||
vase::Shard *root,
|
||||
const syntax::ParserSnapshot &snapshot,
|
||||
Kind kind
|
||||
) : Buffer(std::move(name), kind),
|
||||
root(root),
|
||||
parse(syntax::retain(snapshot)) {
|
||||
vase::Shard::retain(root);
|
||||
}
|
||||
~ShardBuffer() {
|
||||
vase::Shard::release(root);
|
||||
syntax::release(parse);
|
||||
}
|
||||
|
||||
uint64_t lines() override;
|
||||
uint64_t bytes() override;
|
||||
vase::Shard *copy(uint64_t start_line, uint64_t end_line) override;
|
||||
void print(BEd &ctx, uint64_t start_line, uint64_t end_line) override;
|
||||
void number_print(BEd &ctx, uint64_t start_line, uint64_t end_line) override;
|
||||
void list_print(BEd &ctx, uint64_t start_line, uint64_t end_line) override;
|
||||
uint64_t next_closing(uint64_t start) override;
|
||||
uint64_t prev_closing(uint64_t start) override;
|
||||
uint64_t find_next(std::string_view pattern, uint64_t start) override;
|
||||
uint64_t find_prev(std::string_view pattern, uint64_t start) override;
|
||||
};
|
||||
} // namespace bed::internal::buffer
|
||||
Reference in New Issue
Block a user