-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp-Buffer.cppm
More file actions
47 lines (39 loc) · 1.54 KB
/
Copy pathApp-Buffer.cppm
File metadata and controls
47 lines (39 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// This project is licensed under the GPL-3.0 License. See the LICENSE file for details, or check out <gnu.org>.
// Copyright (C) 2026 mxreal64
export module delta.app:buffer;
import delta.types;
import std;
export class DocumentBuffer {
private:
std::string text_ = "";
public:
DocumentBuffer() noexcept = default;
// Standard types must be explicitly namespace qualified under named modules
void insert_str(std::size_t index, const std::string& str) noexcept {
if (index <= text_.size()) {
text_.insert(index, str);
}
}
void erase_range(std::size_t index, std::size_t length) noexcept {
if (index + length <= text_.size()) {
text_.erase(index, length);
}
}
void inject_style(selection_span& sel, char marker) noexcept {
if (sel.start != sel.end) {
std::string before = text_.substr(0, sel.start);
std::string middle = text_.substr(sel.start, sel.end - sel.start);
std::string after = text_.substr(sel.end);
text_ = before + marker + middle + marker + after;
sel.start += 2;
sel.end += 2;
} else {
text_.insert(sel.start, std::string(1, marker));
sel.start++;
sel.end = sel.start;
}
}
[[nodiscard]] const std::string& get_raw() const noexcept { return text_; }
[[nodiscard]] std::size_t size() const noexcept { return text_.size(); }
[[nodiscard]] char operator[](std::size_t idx) const noexcept { return text_[idx]; }
};