Make binary portable and other fixes

This commit is contained in:
2026-01-31 10:25:39 +00:00
parent 86d5b7a021
commit f93afc0d14
25 changed files with 738 additions and 427 deletions

View File

@@ -25,6 +25,23 @@ inline static std::string completion_prefix(Editor *editor) {
return prefix;
}
inline static void completion_adjust_scroll(CompletionSession &s) {
if (s.visible.empty())
return;
int vi = -1;
for (size_t i = 0; i < s.visible.size(); i++)
if (s.visible[i] == s.select) {
vi = (int)i;
break;
}
if (vi < 0)
return;
if ((uint32_t)vi < s.scroll)
s.scroll = vi;
else if ((uint32_t)vi >= s.scroll + 8)
s.scroll = vi - 7;
}
void completion_filter(Editor *editor) {
auto &session = editor->completion;
std::string prefix = completion_prefix(editor);
@@ -44,6 +61,8 @@ void completion_filter(Editor *editor) {
session.select) == session.visible.end())
session.select = session.visible[0];
session.box.hidden = false;
session.scroll = 0;
completion_adjust_scroll(session);
session.box.render_update();
}
@@ -417,6 +436,7 @@ void complete_next(Editor *editor) {
vi = (vi + 1) % s.visible.size();
s.select = s.visible[vi];
completion_resolve_doc(editor);
completion_adjust_scroll(editor->completion);
editor->completion.box.render_update();
}
@@ -431,6 +451,7 @@ void complete_prev(Editor *editor) {
vi = (vi + s.visible.size() - 1) % s.visible.size();
s.select = s.visible[vi];
completion_resolve_doc(editor);
completion_adjust_scroll(editor->completion);
editor->completion.box.render_update();
}

View File

@@ -1,6 +1,7 @@
#include "editor/editor.h"
#include "editor/decl.h"
#include "lsp/lsp.h"
#include "main.h"
#include "syntax/langs.h"
#include "utils/utils.h"
@@ -77,6 +78,8 @@ void save_file(Editor *editor) {
}
out.close();
free(str);
bar.log("Written " + std::to_string(char_count) + " bytes to " +
editor->filename);
if (editor->lsp) {
json save_msg = {{"jsonrpc", "2.0"},
{"method", "textDocument/didSave"},

View File

@@ -232,6 +232,4 @@ void handle_editor_event(Editor *editor, KeyEvent event) {
if (old_mode == mode || mode != INSERT)
handle_completion(editor, event);
ensure_scroll(editor);
if ((event.key_type == KEY_CHAR || event.key_type == KEY_PASTE) && event.c)
free(event.c);
}

View File

@@ -218,8 +218,8 @@ void IndentationEngine::insert_new_line(Coord cursor) {
if (is_end_full != kLangtoBlockEndsFull.end())
for (auto end : is_end_full->second)
if (end == trim(line)) {
cursor.col =
set_indent(cursor.row, (int64_t)indent_expected(cursor.row) - 1);
cursor.col = set_indent(
cursor.row, (int64_t)indent_expected(cursor.row) - (int64_t)1);
end_matched = true;
break;
}
@@ -286,7 +286,7 @@ void IndentationEngine::insert_new_line(Coord cursor) {
(indent == 1 ? std::string(c_indent, '\t')
: std::string(c_indent * indent, ' ')) +
ending;
else if (ending_valid)
else if (ending_valid && c_indent)
c_indent--;
}
auto is_end_set = kLangtoBlockStartsEnd.find(editor->lang.name);

View File

@@ -11,7 +11,7 @@ void render_editor(Editor *editor) {
uint32_t numlen =
EXTRA_META + static_cast<int>(std::log10(editor->root->line_count + 1));
uint32_t render_width = editor->size.col - numlen;
uint32_t render_x = editor->position.col + numlen;
uint32_t render_x = editor->position.col + numlen + 1;
std::vector<std::pair<uint32_t, char>> v;
for (size_t i = 0; i < 94; ++i)
if (editor->hooks[i] != 0)
@@ -146,16 +146,14 @@ void render_editor(Editor *editor) {
update(editor->position.row + rendered_rows, editor->position.col, hook,
0xAAAAAA, 0, 0);
char buf[16];
int len =
snprintf(buf, sizeof(buf), "%*u ", numlen - 3, line_index + 1);
int len = snprintf(buf, sizeof(buf), "%*u ", numlen, line_index + 1);
uint32_t num_color =
editor->cursor.row == line_index ? 0xFFFFFF : 0x555555;
for (int i = 0; i < len; i++)
update(editor->position.row + rendered_rows,
editor->position.col + i + 2, (char[2]){buf[i], 0}, num_color,
0, 0);
update(editor->position.row + rendered_rows, editor->position.col + i,
(char[2]){buf[i], 0}, num_color, 0, 0);
} else {
for (uint32_t i = 0; i < numlen; i++)
for (uint32_t i = 0; i < numlen + 1; i++)
update(editor->position.row + rendered_rows, editor->position.col + i,
" ", 0, 0, 0);
}
@@ -349,13 +347,12 @@ void render_editor(Editor *editor) {
update(editor->position.row + rendered_rows, editor->position.col, hook,
0xAAAAAA, 0, 0);
char buf[16];
int len = snprintf(buf, sizeof(buf), "%*u ", numlen - 3, line_index + 1);
int len = snprintf(buf, sizeof(buf), "%*u ", numlen, line_index + 1);
uint32_t num_color =
editor->cursor.row == line_index ? 0xFFFFFF : 0x555555;
for (int i = 0; i < len; i++)
update(editor->position.row + rendered_rows,
editor->position.col + i + 2, (char[2]){buf[i], 0}, num_color, 0,
0);
update(editor->position.row + rendered_rows, editor->position.col + i,
(char[2]){buf[i], 0}, num_color, 0, 0);
if (editor->cursor.row == line_index) {
cursor.row = editor->position.row + rendered_rows;
cursor.col = render_x;