Improve highlighting structure

- switched to a sparse delta based map
- true lazy-loading to avoid any unneccessary allocations
- fixed windows management api
This commit is contained in:
2026-02-11 18:18:28 +00:00
parent d79ea4e75a
commit 5b66f503e4
24 changed files with 481 additions and 549 deletions
+29 -19
View File
@@ -1,15 +1,16 @@
#include "extentions/hover.h"
#include "io/sysio.h"
#include "syntax/decl.h"
#include "windows/decl.h"
TileRoot *init_hover() {
auto root = std::make_unique<TileRoot>();
root->tile = std::make_unique<HoverBox>();
root->pos = {0, 0};
root->size = {1, 1};
root->tile->hidden = true;
popups.push_back(std::move(root));
return popups.back().get();
HoverBox *init_hover() {
auto hover = std::make_unique<HoverBox>();
hover->pos = {0, 0};
hover->size = {1, 1};
hover->hidden = true;
HoverBox *ptr = hover.get();
layout::popups.push_back(std::move(hover));
return ptr;
}
void HoverBox::scroll(int32_t number) {
@@ -25,20 +26,25 @@ void HoverBox::scroll(int32_t number) {
scroll_dirty = true;
}
void HoverBox::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
void HoverBox::render(std::vector<ScreenCell> &buffer, Coord n_size,
Coord n_pos) {
pos = n_pos;
size = n_size;
if (scroll_dirty) {
// TODO: call syntax highlighter here
}
// int32_t start_row = (int32_t)pos.row - (int32_t)size.row;
// if (start_row < 0)
// start_row = pos.row + 1;
// int32_t start_col = pos.col; // pos here is the cursor pos
Coord screen_size = get_size();
// if (start_col + size.col > screen_size.col) {
// start_col = screen_size.col - size.col;
// if (start_col < 0)
// start_col = 0;
// }
int32_t start_row = (int32_t)pos.row - (int32_t)size.row;
if (start_row < 0)
start_row = pos.row + 1;
int32_t start_col = pos.col; // pos here is the cursor pos
Coord screen_size = {io::rows, io::cols};
if (start_col + size.col > screen_size.col) {
start_col = screen_size.col - size.col;
if (start_col < 0)
start_col = 0;
}
pos.col = start_col;
pos.row = start_row;
uint32_t longest_line = 0;
uint32_t current_width = 0;
for (size_t j = 0; j < text.length(); j++) {
@@ -69,6 +75,8 @@ void HoverBox::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
return;
r += pos.row;
c += pos.col;
if (r < 0 || r >= screen_size.row || c < 0 || c >= screen_size.col)
return;
ScreenCell &cell = buffer[r * screen_size.col + c];
cell.utf8 = text;
cell.width = width;
@@ -103,6 +111,8 @@ void HoverBox::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
for (int w = 1; w < width; w++)
set(r + 1, c - w + 1, "\x1b", 0xFFFFFF, base_bg, 0, 0);
}
while (c < content_width)
set(r + 1, ++c, " ", 0xFFFFFF, base_bg, 0, 0);
r++;
}
if (scroll_dirty)