Improve mouse scrolling

This commit is contained in:
Krzosa Karol
2024-06-29 08:55:16 +02:00
parent 0d3cb029d8
commit ba711b7f14
3 changed files with 57 additions and 30 deletions

View File

@@ -489,15 +489,23 @@ Line GetLineByIndex(Buffer &buffer, int64_t line) {
Line FindLine(Buffer &buffer, int64_t pos) {
Line result = {};
For(buffer.lines) {
bool found_last = (pos == it.min && pos == it.max); // @end_of_buffer
bool found = pos >= it.min && pos < it.max;
if (found || found_last) {
if (pos >= it.min && pos < it.max) {
result = {buffer.lines.get_index(it), it, it.max};
if (it.max > it.min && GetChar(buffer, it.max - 1) == '\n') result.max_without_new_line -= 1;
break;
return result;
}
}
if (pos == buffer.len) { // @end of buffer
auto &it = buffer.lines[buffer.lines.len - 1];
Assert(it.max == buffer.len);
result = {buffer.lines.get_index(it), it, it.max};
if (it.max > it.min && GetChar(buffer, it.max - 1) == '\n') result.max_without_new_line -= 1;
return result;
}
return result;
}