Move folder
This commit is contained in:
Regular → Executable
+13
-58
@@ -2,72 +2,27 @@
|
||||
|
||||
void Editor::ensure_cursor() {
|
||||
if (this->cursor < this->scroll) {
|
||||
this->cursor.row = this->scroll.row;
|
||||
this->cursor.col = this->scroll.col;
|
||||
this->cursor = this->scroll;
|
||||
this->cursor_preffered = UINT32_MAX;
|
||||
return;
|
||||
}
|
||||
uint32_t numlen =
|
||||
EXTRA_META + static_cast<int>(std::log10(this->root->line_count + 1));
|
||||
uint32_t render_width = this->size.col - numlen;
|
||||
uint32_t visual_rows = 0;
|
||||
uint32_t line_index = this->scroll.row;
|
||||
bool first_visual_line = true;
|
||||
LineIterator *it = begin_l_iter(this->root, line_index);
|
||||
if (!it)
|
||||
return;
|
||||
Coord last_visible = this->scroll;
|
||||
while (true) {
|
||||
if (visual_rows >= this->size.row)
|
||||
break;
|
||||
uint32_t line_len;
|
||||
char *line = next_line(it, &line_len);
|
||||
if (!line)
|
||||
break;
|
||||
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||
line_len--;
|
||||
uint32_t offset = first_visual_line ? this->scroll.col : 0;
|
||||
first_visual_line = false;
|
||||
while (offset < line_len || (line_len == 0 && offset == 0)) {
|
||||
Coord current = {line_index, offset};
|
||||
last_visible = current;
|
||||
visual_rows++;
|
||||
if (visual_rows >= this->size.row)
|
||||
break;
|
||||
uint32_t col = 0;
|
||||
uint32_t advance = 0;
|
||||
uint32_t left = line_len - offset;
|
||||
while (left > 0 && col < render_width) {
|
||||
uint32_t g =
|
||||
grapheme_next_character_break_utf8(line + offset + advance, left);
|
||||
int w = display_width(line + offset + advance, g);
|
||||
if (col + w > render_width)
|
||||
break;
|
||||
advance += g;
|
||||
left -= g;
|
||||
col += w;
|
||||
}
|
||||
if (line_index == this->cursor.row) {
|
||||
if (this->cursor.col >= offset &&
|
||||
this->cursor.col <= offset + advance) {
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (advance == 0)
|
||||
break;
|
||||
offset += advance;
|
||||
if (line_len == 0)
|
||||
break;
|
||||
}
|
||||
line_index++;
|
||||
uint32_t render_height = 0;
|
||||
VisualIterator vis(root, scroll, render_width);
|
||||
std::pair<Coord, Coord> vline;
|
||||
Coord last_visible = scroll;
|
||||
while ((vline = vis.next()).first.row != UINT32_MAX &&
|
||||
render_height < this->size.row) {
|
||||
render_height++;
|
||||
last_visible = vline.first;
|
||||
if (cursor >= vline.first && cursor < vline.second)
|
||||
return;
|
||||
}
|
||||
this->cursor.row = last_visible.row;
|
||||
this->cursor.col = last_visible.col;
|
||||
cursor = last_visible;
|
||||
cursor_preffered = UINT32_MAX;
|
||||
this->cursor_preffered = UINT32_MAX;
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
}
|
||||
|
||||
void Editor::ensure_scroll() {
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+4
-3
@@ -44,10 +44,10 @@ void Editor::edit_erase(Coord pos, int64_t len) {
|
||||
}
|
||||
uint32_t start_row = point.row;
|
||||
uint32_t end_row = pos.row;
|
||||
this->apply_hook_deletion(start_row + 1, end_row);
|
||||
this->root = erase(this->root, start, byte_pos - start);
|
||||
if (this->parser)
|
||||
this->parser->edit(start_row, end_row - start_row, 0);
|
||||
this->hooks.edit(start_row, end_row - start_row, 0);
|
||||
if (do_lsp) {
|
||||
auto lsp = this->lsp.load();
|
||||
if (lsp->incremental_sync) {
|
||||
@@ -113,10 +113,10 @@ void Editor::edit_erase(Coord pos, int64_t len) {
|
||||
}
|
||||
uint32_t start_row = pos.row;
|
||||
uint32_t end_row = point.row;
|
||||
this->apply_hook_deletion(start_row + 1, end_row);
|
||||
this->root = erase(this->root, byte_pos, end - byte_pos);
|
||||
if (this->parser)
|
||||
this->parser->edit(start_row, end_row - start_row, 0);
|
||||
this->hooks.edit(start_row, end_row - start_row, 0);
|
||||
if (do_lsp) {
|
||||
auto lsp = this->lsp.load();
|
||||
if (lsp->incremental_sync) {
|
||||
@@ -169,9 +169,9 @@ void Editor::edit_insert(Coord pos, char *data, uint32_t len) {
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
if (data[i] == '\n')
|
||||
rows++;
|
||||
this->apply_hook_insertion(pos.row, rows);
|
||||
if (this->parser)
|
||||
this->parser->edit(pos.row, 0, rows);
|
||||
this->hooks.edit(pos.row, 0, rows);
|
||||
auto lsp = this->lsp.load();
|
||||
if (lsp) {
|
||||
if (lsp->incremental_sync) {
|
||||
@@ -234,6 +234,7 @@ void Editor::edit_replace(Coord start, Coord end, const char *text,
|
||||
rows++;
|
||||
if (this->parser)
|
||||
this->parser->edit(start.row, end.row - start.row, rows);
|
||||
this->hooks.edit(start.row, end.row - start.row, rows);
|
||||
auto lsp = this->lsp.load();
|
||||
if (lsp) {
|
||||
if (lsp->incremental_sync) {
|
||||
|
||||
Regular → Executable
Regular → Executable
+4
-11
@@ -96,7 +96,7 @@ void Editor::handle_event(KeyEvent event) {
|
||||
this->jumper_set = false;
|
||||
break;
|
||||
case 'N':
|
||||
this->clear_hooks_at_line(this->cursor.row);
|
||||
this->hooks.clear_line(this->cursor.row);
|
||||
break;
|
||||
case 's':
|
||||
case 'v':
|
||||
@@ -218,18 +218,11 @@ void Editor::handle_event(KeyEvent event) {
|
||||
if (event.key_type == KEY_CHAR && event.len == 1 &&
|
||||
(event.c[0] >= '!' && event.c[0] <= '~')) {
|
||||
if (this->jumper_set) {
|
||||
for (uint8_t i = 0; i < 94; i++)
|
||||
if (this->hooks[i] == this->cursor.row + 1) {
|
||||
this->hooks[i] = 0;
|
||||
break;
|
||||
}
|
||||
this->hooks[event.c[0] - '!'] = this->cursor.row + 1;
|
||||
this->hooks.set(event.c[0], this->cursor.row);
|
||||
} else {
|
||||
uint32_t line = this->hooks[event.c[0] - '!'] - 1;
|
||||
if (line > 0) {
|
||||
uint32_t line;
|
||||
if (this->hooks.get(event.c[0], &line))
|
||||
this->cursor = {line, 0};
|
||||
this->cursor_preffered = UINT32_MAX;
|
||||
}
|
||||
}
|
||||
}
|
||||
mode = NORMAL;
|
||||
|
||||
Executable
Regular → Executable
-8
@@ -312,14 +312,6 @@ void Editor::delete_next_word() {
|
||||
this->edit_erase(this->cursor, next_col_cluster);
|
||||
}
|
||||
|
||||
void Editor::clear_hooks_at_line(uint32_t line) {
|
||||
for (uint8_t i = 0; i < 94; i++)
|
||||
if (this->hooks[i] == line + 1) {
|
||||
this->hooks[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::cursor_prev_word() {
|
||||
uint32_t prev_col;
|
||||
word_boundaries(this->cursor, &prev_col, nullptr, nullptr, nullptr);
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+6
-24
@@ -11,14 +11,7 @@ void Editor::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
EXTRA_META + static_cast<int>(std::log10(this->root->line_count + 1));
|
||||
uint32_t render_width = size.col - numlen;
|
||||
uint32_t render_x = pos.col + numlen + 1;
|
||||
std::vector<std::pair<uint32_t, char>> v;
|
||||
for (size_t i = 0; i < 94; ++i)
|
||||
if (this->hooks[i] != 0)
|
||||
v.push_back({this->hooks[i], '!' + i});
|
||||
std::sort(v.begin(), v.end());
|
||||
auto hook_it = v.begin();
|
||||
while (hook_it != v.end() && hook_it->first <= this->scroll.row)
|
||||
++hook_it;
|
||||
this->hooks.start_iter(this->scroll.row);
|
||||
auto warn_it = this->warnings.begin();
|
||||
while (warn_it != this->warnings.end() && warn_it->line < this->scroll.row)
|
||||
++warn_it;
|
||||
@@ -140,14 +133,9 @@ void Editor::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
while (current_byte_offset < line_len && rendered_rows < this->size.row) {
|
||||
uint32_t color = this->cursor.row == line_index ? 0x222222 : 0;
|
||||
if (current_byte_offset == 0 || rendered_rows == 0) {
|
||||
const char *hook = "";
|
||||
char h[2] = {0, 0};
|
||||
if (hook_it != v.end() && hook_it->first == line_index + 1) {
|
||||
h[0] = hook_it->second;
|
||||
hook = h;
|
||||
hook_it++;
|
||||
}
|
||||
update(pos.row + rendered_rows, pos.col, hook, 0xAAAAAA, 0, 0, 0, 1);
|
||||
char hook = this->hooks.next(line_index);
|
||||
update(pos.row + rendered_rows, pos.col, {hook, 0}, 0xAAAAAA, 0, 0, 0,
|
||||
1);
|
||||
char buf[16];
|
||||
int len = snprintf(buf, sizeof(buf), "%*u ", numlen, line_index + 1);
|
||||
uint32_t num_color =
|
||||
@@ -337,14 +325,8 @@ void Editor::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
if (line_len == 0 ||
|
||||
(current_byte_offset >= line_len && rendered_rows == 0)) {
|
||||
uint32_t color = this->cursor.row == line_index ? 0x222222 : 0;
|
||||
const char *hook = "";
|
||||
char h[2] = {0, 0};
|
||||
if (hook_it != v.end() && hook_it->first == line_index + 1) {
|
||||
h[0] = hook_it->second;
|
||||
hook = h;
|
||||
hook_it++;
|
||||
}
|
||||
update(pos.row + rendered_rows, pos.col, hook, 0xAAAAAA, 0, 0, 0, 1);
|
||||
char hook = this->hooks.next(line_index);
|
||||
update(pos.row + rendered_rows, pos.col, {hook, 0}, 0xAAAAAA, 0, 0, 0, 1);
|
||||
char buf[16];
|
||||
int len = snprintf(buf, sizeof(buf), "%*u ", numlen, line_index + 1);
|
||||
uint32_t num_color = this->cursor.row == line_index ? 0xFFFFFF : 0x555555;
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
Reference in New Issue
Block a user