allow insertion cursor to sit past end of file

This commit is contained in:
Lephenixnoir 2022-06-24 01:23:38 +01:00
parent c1c8bf0fcb
commit 77c9fb8fea
Signed by untrusted user: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 13 additions and 5 deletions

View File

@ -47,12 +47,12 @@ static void compute_maxima(heditor *e, int *max_scroll, int *max_cursor)
int bpl = e->bytes_per_line;
int size = source_size(e->source);
int rows = (size + bpl - 1) / bpl;
int rows = (size + (e->insert == true) + bpl - 1) / bpl;
if(max_scroll)
*max_scroll = max(rows - e->visible_lines, 0) * bpl;
if(max_cursor)
*max_cursor = size - 1;
*max_cursor = size - (e->insert == false);
}
/* Adjust positioning to make sure we stay on legal values */
@ -166,6 +166,7 @@ void heditor_set_insert_mode(heditor *e, bool insert)
e->insert = false;
if(e->source && e->source->intf->cap & SOURCE_RESIZE)
e->insert = insert;
shake(e);
e->widget.update = true;
}
@ -255,7 +256,14 @@ static void heditor_poly_render(void *e0, int x, int y)
sprintf(byte, "%01X_", c >> 4);
else
sprintf(byte, "%02X", c);
dprint(ascii_x, line_y, C_BLACK, "%c",
int fg = C_BLACK;
if(e->cursor == o) {
drect(ascii_x - 1, line_y - 1, ascii_x + 8,
line_y + e->font->line_height, C_BLACK);
fg = C_WHITE;
}
dprint(ascii_x, line_y, fg, "%c",
(c >= 0x20 && c < 0x7f) ? c : '.');
}
@ -278,7 +286,7 @@ static void heditor_poly_render(void *e0, int x, int y)
dtext(bytes_x, line_y, fg, byte);
bytes_x += text_w + ((k & 1) ? 7 : 2);
ascii_x += 9;
ascii_x += 10;
}
offset += n;
@ -318,7 +326,7 @@ static bool heditor_poly_event(void *e0, jevent ev)
}
if(key == KEY_DOWN && ev.key.shift) {
heditor_move_to(e, source_size(e->source) - 1);
heditor_move_to(e, source_size(e->source) /* auto adjust */);
return true;
}
else if(key == KEY_DOWN) {