mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-24 09:05:48 -04:00
Merge branch 'search-render-improvements'
This commit is contained in:
commit
f209541688
3 changed files with 29 additions and 6 deletions
32
render.c
32
render.c
|
|
@ -886,10 +886,19 @@ render_search_box(struct terminal *term)
|
||||||
{
|
{
|
||||||
assert(term->window->search_sub_surface != NULL);
|
assert(term->window->search_sub_surface != NULL);
|
||||||
|
|
||||||
|
const size_t wanted_visible_chars = max(20, term->search.len);
|
||||||
|
|
||||||
const int scale = term->scale >= 1 ? term->scale : 1;
|
const int scale = term->scale >= 1 ? term->scale : 1;
|
||||||
const int margin = scale * 3;
|
const size_t margin = scale * 3;
|
||||||
const int width = min(term->width, 2 * margin + max(20, term->search.len) * term->cell_width);
|
|
||||||
const int height = min(term->height, 2 * margin + 1 * term->cell_height);
|
const size_t width = min(
|
||||||
|
term->width - 2 * margin,
|
||||||
|
2 * margin + wanted_visible_chars * term->cell_width);
|
||||||
|
const size_t height = min(
|
||||||
|
term->height - 2 * margin,
|
||||||
|
2 * margin + 1 * term->cell_height);
|
||||||
|
|
||||||
|
const size_t visible_chars = (width - 2 * margin) / term->cell_width;
|
||||||
|
|
||||||
unsigned long cookie = (uintptr_t)term + 1;
|
unsigned long cookie = (uintptr_t)term + 1;
|
||||||
struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie);
|
struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie);
|
||||||
|
|
@ -908,8 +917,19 @@ render_search_box(struct terminal *term)
|
||||||
int y = margin;
|
int y = margin;
|
||||||
pixman_color_t fg = color_hex_to_pixman(term->colors.table[0]);
|
pixman_color_t fg = color_hex_to_pixman(term->colors.table[0]);
|
||||||
|
|
||||||
|
if (term->search.cursor < term->render.search_offset ||
|
||||||
|
term->search.cursor >= term->render.search_offset + visible_chars + 2)
|
||||||
|
{
|
||||||
|
/* Make sure cursor is always visible */
|
||||||
|
term->render.search_offset = term->search.cursor;
|
||||||
|
}
|
||||||
|
|
||||||
/* Text (what the user entered - *not* match(es)) */
|
/* Text (what the user entered - *not* match(es)) */
|
||||||
for (size_t i = 0; i < term->search.len; i++) {
|
for (size_t i = term->render.search_offset;
|
||||||
|
i < term->search.len &&
|
||||||
|
i - term->render.search_offset < visible_chars + 1;
|
||||||
|
i++)
|
||||||
|
{
|
||||||
if (i == term->search.cursor)
|
if (i == term->search.cursor)
|
||||||
draw_bar(term, buf->pix, font, &fg, x, y);
|
draw_bar(term, buf->pix, font, &fg, x, y);
|
||||||
|
|
||||||
|
|
@ -932,8 +952,8 @@ render_search_box(struct terminal *term)
|
||||||
|
|
||||||
wl_subsurface_set_position(
|
wl_subsurface_set_position(
|
||||||
term->window->search_sub_surface,
|
term->window->search_sub_surface,
|
||||||
max(0, term->width - width - margin),
|
max(0, (int32_t)term->width - width - margin),
|
||||||
max(0, term->height - height - margin));
|
max(0, (int32_t)term->height - height - margin));
|
||||||
|
|
||||||
wl_surface_damage_buffer(term->window->search_surface, 0, 0, width, height);
|
wl_surface_damage_buffer(term->window->search_surface, 0, 0, width, height);
|
||||||
wl_surface_attach(term->window->search_surface, buf->wl_buf, 0, 0);
|
wl_surface_attach(term->window->search_surface, buf->wl_buf, 0, 0);
|
||||||
|
|
|
||||||
1
search.c
1
search.c
|
|
@ -51,6 +51,7 @@ search_cancel_keep_selection(struct terminal *term)
|
||||||
term->search.match = (struct coord){-1, -1};
|
term->search.match = (struct coord){-1, -1};
|
||||||
term->search.match_len = 0;
|
term->search.match_len = 0;
|
||||||
term->is_searching = false;
|
term->is_searching = false;
|
||||||
|
term->render.search_offset = 0;
|
||||||
|
|
||||||
term_xcursor_update(term);
|
term_xcursor_update(term);
|
||||||
render_refresh(term);
|
render_refresh(term);
|
||||||
|
|
|
||||||
|
|
@ -310,6 +310,8 @@ struct terminal {
|
||||||
bool was_flashing; /* Flash was active last time we rendered */
|
bool was_flashing; /* Flash was active last time we rendered */
|
||||||
bool was_searching;
|
bool was_searching;
|
||||||
|
|
||||||
|
size_t search_offset;
|
||||||
|
|
||||||
bool presentation_timings;
|
bool presentation_timings;
|
||||||
struct timespec input_time;
|
struct timespec input_time;
|
||||||
struct timespec commit_time;
|
struct timespec commit_time;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue