Move folder

This commit is contained in:
2026-04-13 10:32:46 +01:00
parent c683754d49
commit 037f884050
107 changed files with 292 additions and 155 deletions

0
include/editor/completions.h Normal file → Executable file
View File

0
include/editor/decl.h Normal file → Executable file
View File

18
include/editor/editor.h Normal file → Executable file
View File

@@ -1,7 +1,9 @@
#ifndef EDITOR_H
#define EDITOR_H
#include "editor/hooks.h"
#include "editor/indents.h"
#include "editor/visual.h"
#include "extentions/diagnostics.h"
#include "extentions/hover.h"
#include "io/knot.h"
@@ -31,7 +33,6 @@ struct Editor : Window {
Coord size = {0, 0};
Coord scroll = {0, 0};
Language lang = {};
uint32_t hooks[94] = {0};
bool jumper_set = false;
std::vector<VWarn> warnings = {};
bool warnings_dirty = false;
@@ -42,6 +43,7 @@ struct Editor : Window {
DiagnosticBox *diagnostic_popup = init_diagnostic();
std::atomic<int> lsp_version = 1;
IndentationEngine indents = {};
HookEngine hooks = {};
Parser *parser = nullptr;
ExtraHighlighter extra_hl = {};
bool is_css_color = false;
@@ -84,7 +86,6 @@ struct Editor : Window {
void backspace_edit();
void delete_prev_word();
void delete_next_word();
void clear_hooks_at_line(uint32_t line);
void cursor_prev_word();
void cursor_next_word();
void select_all();
@@ -158,19 +159,6 @@ struct Editor : Window {
free(it->buffer);
free(it);
}
inline void apply_hook_insertion(uint32_t line, uint32_t rows) {
for (auto &hook : this->hooks)
if (hook > line)
hook += rows;
}
inline void apply_hook_deletion(uint32_t removal_start,
uint32_t removal_end) {
for (auto &hook : this->hooks)
if (hook > removal_start)
hook -= removal_end - removal_start + 1;
}
};
#endif

0
include/editor/helpers.h Normal file → Executable file
View File

91
include/editor/hooks.h Executable file
View File

@@ -0,0 +1,91 @@
#ifndef EDITOR_HOOKS_H
#define EDITOR_HOOKS_H
#include "utils/utils.h"
struct HookEngine {
uint32_t hooks[94];
std::vector<std::pair<uint32_t, char>> v;
std::vector<std::pair<uint32_t, char>>::iterator it;
HookEngine() {
for (int i = 0; i < 94; i++)
hooks[i] = UINT32_MAX;
v.reserve(94);
}
inline void edit(uint32_t line, uint32_t removed_rows,
uint32_t inserted_rows) {
int64_t delta = (int64_t)inserted_rows - (int64_t)removed_rows;
for (int i = 0; i < 94; i++) {
uint32_t &h = hooks[i];
if (h == UINT32_MAX)
continue;
if (h < line)
continue;
if (removed_rows > 0 && h < line + removed_rows) {
h = UINT32_MAX;
continue;
}
h = (uint32_t)((int64_t)h + delta);
}
}
inline void set(char c, uint32_t line) {
if (c < '!' || c > '~')
return;
int idx = c - '!';
for (int i = 0; i < 94; i++) {
if (hooks[i] == line) {
hooks[i] = UINT32_MAX;
break;
}
}
hooks[idx] = line;
}
inline bool get(char c, uint32_t *out_line) const {
if (c < '!' || c > '~')
return false;
uint32_t h = hooks[c - '!'];
if (h == UINT32_MAX)
return false;
*out_line = h;
return true;
}
inline void clear_line(uint32_t line) {
for (int i = 0; i < 94; i++)
if (hooks[i] == line)
hooks[i] = UINT32_MAX;
}
inline void clear(char c) {
if (c < '!' || c > '~')
return;
hooks[c - '!'] = UINT32_MAX;
}
void start_iter(uint32_t scroll_line) {
for (int i = 0; i < 94; i++)
if (hooks[i] != UINT32_MAX)
v.push_back({hooks[i], (char)('!' + i)});
std::sort(v.begin(), v.end(),
[](const auto &a, const auto &b) { return a.first < b.first; });
it = std::lower_bound(
v.begin(), v.end(), scroll_line,
[](const auto &p, uint32_t line) { return p.first < line; });
}
char next(uint32_t line_index) {
if (it != v.end() && it->first == line_index) {
char c = it->second;
it++;
return c;
}
return '\0';
}
};
#endif

0
include/editor/indents.h Normal file → Executable file
View File

113
include/editor/visual.h Executable file
View File

@@ -0,0 +1,113 @@
#include "editor/decl.h"
#include "io/knot.h"
#include "io/sysio.h"
#include "utils/utils.h"
struct GraphemeIterator {
char *line{nullptr};
uint32_t len{0};
GraphemeIterator(char *line, uint32_t len) : line(line), len(len) {}
char *next(uint32_t *o_len, uint32_t *o_width) {
if (!line || len == 0)
return nullptr;
char *cur = line;
uint32_t g = grapheme_next_character_break_utf8(cur, len);
if (o_width)
*o_width = display_width(cur, g);
if (o_len)
*o_len = g;
line += g;
len -= g;
return cur;
}
};
struct VisualIterator {
LineIterator *it{nullptr};
uint32_t line_index{UINT32_MAX};
uint32_t offset{0};
uint32_t len{0};
bool first{true};
char *line{nullptr};
uint32_t render_width{io::cols};
std::stack<std::pair<Coord, Coord>> prev_stack;
VisualIterator(Knot *root, Coord pos, uint32_t width)
: it(begin_l_iter(root, pos.row)), offset(pos.col),
line_index(pos.row - 1), render_width(width) {}
std::pair<Coord, Coord> prev() {
if (!it)
return {{UINT32_MAX, UINT32_MAX}, {UINT32_MAX, UINT32_MAX}};
if (prev_stack.empty())
return _prev();
auto ret = prev_stack.top();
offset = ret.first.col;
prev_stack.pop();
return ret;
}
std::pair<Coord, Coord> _prev() {
if (!it)
return {{UINT32_MAX, UINT32_MAX}, {UINT32_MAX, UINT32_MAX}};
line_index--;
line = prev_line(it, &len);
if (!line)
return {{UINT32_MAX, UINT32_MAX}, {UINT32_MAX, UINT32_MAX}};
if (len > 0 && line[len - 1] == '\n')
len--;
offset = first ? offset : 0;
first = false;
GraphemeIterator g(line + offset, len - offset);
uint32_t o_len, o_width, rendered = 0, advance = 0;
while (g.next(&o_len, &o_width)) {
if (rendered + o_width > render_width) {
prev_stack.push({{line_index, offset}, {line_index, offset + advance}});
offset += advance;
rendered = 0;
advance = 0;
}
advance += o_len;
rendered += o_width;
}
return {{line_index, offset}, {line_index, offset + advance}};
}
std::pair<Coord, Coord> next() {
if (!it)
return {{UINT32_MAX, UINT32_MAX}, {UINT32_MAX, UINT32_MAX}};
if (!line) {
line_index++;
line = next_line(it, &len);
if (!line)
return {{UINT32_MAX, UINT32_MAX}, {UINT32_MAX, UINT32_MAX}};
if (len > 0 && line[len - 1] == '\n')
len--;
offset = first ? offset : 0;
first = false;
}
GraphemeIterator g(line + offset, len - offset);
uint32_t o_len, o_width, rendered = 0, advance = 0;
while (g.next(&o_len, &o_width)) {
if (rendered + o_width > render_width) {
offset += advance;
return {{line_index, offset - advance}, {line_index, offset}};
}
advance += o_len;
rendered += o_width;
}
offset += advance;
if (offset >= len)
line = nullptr;
return {{line_index, offset}, {line_index, offset + advance}};
}
~VisualIterator() {
if (!it)
return;
free(it->buffer);
free(it);
}
};