2019-08-27 17:23:28 +02:00
|
|
|
#include "search.h"
|
|
|
|
|
|
2019-12-01 19:22:45 +01:00
|
|
|
#include <string.h>
|
2019-08-29 19:34:41 +02:00
|
|
|
|
|
|
|
|
#include <wayland-client.h>
|
2019-08-27 17:23:28 +02:00
|
|
|
#include <xkbcommon/xkbcommon-compose.h>
|
|
|
|
|
|
|
|
|
|
#define LOG_MODULE "search"
|
2019-08-27 21:11:29 +02:00
|
|
|
#define LOG_ENABLE_DBG 0
|
2019-08-27 17:23:28 +02:00
|
|
|
#include "log.h"
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
#include "char32.h"
|
2023-09-26 17:54:03 +02:00
|
|
|
#include "commands.h"
|
2020-10-09 19:44:23 +02:00
|
|
|
#include "config.h"
|
2021-03-28 21:06:21 +02:00
|
|
|
#include "extract.h"
|
2019-08-27 21:11:40 +02:00
|
|
|
#include "grid.h"
|
2020-03-08 15:28:47 +01:00
|
|
|
#include "input.h"
|
key-binding: new API, for handling sets of key bindings
Up until now, our Wayland seats have been tracking key bindings. This
makes sense, since the seat’s keymap determines how the key bindings
are resolved.
However, tying bindings to the seat/keymap alone isn’t enough, since
we also depend on the current configuration (i.e. user settings) when
resolving a key binding.
This means configurations that doesn’t match the wayland object’s
configuration, currently don’t resolve key bindings correctly. This
applies to footclients where the user has overridden key bindings on
the command line (e.g. --override key-bindings.foo=bar).
Thus, to correctly resolve key bindings, each set of key bindings must
be tied *both* to a seat/keymap, *and* a configuration.
This patch introduces a key-binding manager, with an API to
add/remove/lookup, and load/unload keymaps from sets of key bindings.
In the API, sets are tied to a seat and terminal instance, since this
makes the most sense (we need to instantiate, or incref a set whenever
a new terminal instance is created). Internally, the set is tied to a
seat and the terminal’s configuration.
Sets are *added* when a new seat is added, and when a new terminal
instance is created. Since there can only be one instance of each
seat, sets are always removed when a seat is removed.
Terminals on the other hand can re-use the same configuration (and
typically do). Thus, sets ref-count the configuration. In other words,
when instantiating a new terminal, we may not have to instantiate a
new set of key bindings, but can often be incref:ed instead.
Whenever the keymap changes on a seat, all key bindings sets
associated with that seat reloads (re-resolves) their key bindings.
Closes #931
2022-04-17 15:39:51 +02:00
|
|
|
#include "key-binding.h"
|
2019-12-03 19:22:47 +01:00
|
|
|
#include "misc.h"
|
2023-04-25 21:33:45 +02:00
|
|
|
#include "quirks.h"
|
2019-08-27 17:23:28 +02:00
|
|
|
#include "render.h"
|
2019-08-27 19:33:19 +02:00
|
|
|
#include "selection.h"
|
2019-08-29 19:34:41 +02:00
|
|
|
#include "shm.h"
|
2022-07-28 18:09:16 +02:00
|
|
|
#include "unicode-mode.h"
|
2020-05-01 11:46:24 +02:00
|
|
|
#include "util.h"
|
2020-12-05 23:29:12 +01:00
|
|
|
#include "xmalloc.h"
|
2019-08-29 19:34:41 +02:00
|
|
|
|
2020-08-12 18:45:35 +02:00
|
|
|
/*
|
|
|
|
|
* Ensures a "new" viewport doesn't contain any unallocated rows.
|
|
|
|
|
*
|
|
|
|
|
* This is done by first checking if the *first* row is NULL. If so,
|
|
|
|
|
* we move the viewport *forward*, until the first row is non-NULL. At
|
|
|
|
|
* this point, the entire viewport should be allocated rows only.
|
|
|
|
|
*
|
|
|
|
|
* If the first row already was non-NULL, we instead check the *last*
|
|
|
|
|
* row, and if it is NULL, we move the viewport *backward* until the
|
|
|
|
|
* last row is non-NULL.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
ensure_view_is_allocated(struct terminal *term, int new_view)
|
|
|
|
|
{
|
2022-04-09 17:28:16 +02:00
|
|
|
struct grid *grid = term->grid;
|
|
|
|
|
int view_end = (new_view + term->rows - 1) & (grid->num_rows - 1);
|
2020-08-12 18:45:35 +02:00
|
|
|
|
2022-04-09 17:28:16 +02:00
|
|
|
if (grid->rows[new_view] == NULL) {
|
|
|
|
|
while (grid->rows[new_view] == NULL)
|
|
|
|
|
new_view = (new_view + 1) & (grid->num_rows - 1);
|
2020-08-12 18:45:35 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-09 17:28:16 +02:00
|
|
|
else if (grid->rows[view_end] == NULL) {
|
|
|
|
|
while (grid->rows[view_end] == NULL) {
|
2020-08-12 18:45:35 +02:00
|
|
|
new_view--;
|
|
|
|
|
if (new_view < 0)
|
2022-04-09 17:28:16 +02:00
|
|
|
new_view += grid->num_rows;
|
|
|
|
|
view_end = (new_view + term->rows - 1) & (grid->num_rows - 1);
|
2020-08-12 18:45:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if defined(_DEBUG)
|
|
|
|
|
for (size_t r = 0; r < term->rows; r++)
|
2022-04-09 17:28:16 +02:00
|
|
|
xassert(grid->rows[(new_view + r) & (grid->num_rows - 1)] != NULL);
|
2020-08-12 18:45:35 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return new_view;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-03 19:17:34 +01:00
|
|
|
static bool
|
|
|
|
|
search_ensure_size(struct terminal *term, size_t wanted_size)
|
|
|
|
|
{
|
|
|
|
|
while (wanted_size >= term->search.sz) {
|
|
|
|
|
size_t new_sz = term->search.sz == 0 ? 64 : term->search.sz * 2;
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
char32_t *new_buf = realloc(term->search.buf, new_sz * sizeof(term->search.buf[0]));
|
2019-12-03 19:17:34 +01:00
|
|
|
|
|
|
|
|
if (new_buf == NULL) {
|
|
|
|
|
LOG_ERRNO("failed to resize search buffer");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
term->search.buf = new_buf;
|
|
|
|
|
term->search.sz = new_sz;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-28 20:59:35 +02:00
|
|
|
static bool
|
2023-09-26 17:54:03 +02:00
|
|
|
has_wrapped_around_left(const struct terminal *term, int abs_row_no)
|
|
|
|
|
{
|
|
|
|
|
int rebased_row = grid_row_abs_to_sb(term->grid, term->rows, abs_row_no);
|
|
|
|
|
return rebased_row == term->grid->num_rows - 1 || term->grid->rows[abs_row_no] == NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
has_wrapped_around_right(const struct terminal *term, int abs_row_no)
|
2021-03-28 20:59:35 +02:00
|
|
|
{
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
int rebased_row = grid_row_abs_to_sb(term->grid, term->rows, abs_row_no);
|
2021-03-28 20:59:35 +02:00
|
|
|
return rebased_row == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 19:34:41 +02:00
|
|
|
static void
|
|
|
|
|
search_cancel_keep_selection(struct terminal *term)
|
|
|
|
|
{
|
wayland: instantiate sub-surfaces on-demand
While most compositors handle instantiated but not-yet-mapped
sub-surfaces correctly, e.g. kwin does not.
For example, it will incorrectly offset the main surface both
horizontally and vertically with a couple of pixels, leaving two
transparent areas at the top and left, between the SSDs and the main
surface.
Note that a workaround is to position the sub-surfaces inside the main
surface while they're unmapped. However, since the surfaces may be
larger than the main surface (the CSDs, for examples, always are),
this doesn't quite work since kwin, at least, resizes the window to
include the sub-surfaces, even when unmapped.
So, instead we instantiate all sub-surfaces on demand, when we know
where to position them, and when they should be mapped.
2020-02-26 12:22:16 +01:00
|
|
|
struct wl_window *win = term->window;
|
2021-02-12 12:00:40 +01:00
|
|
|
wayl_win_subsurface_destroy(&win->search);
|
2019-08-27 17:23:28 +02:00
|
|
|
|
2022-01-27 18:36:28 +01:00
|
|
|
if (term->search.len > 0) {
|
|
|
|
|
free(term->search.last.buf);
|
|
|
|
|
term->search.last.buf = term->search.buf;
|
|
|
|
|
term->search.last.len = term->search.len;
|
|
|
|
|
} else
|
|
|
|
|
free(term->search.buf);
|
|
|
|
|
|
2019-08-27 17:23:28 +02:00
|
|
|
term->search.buf = NULL;
|
2022-01-27 18:36:28 +01:00
|
|
|
term->search.len = term->search.sz = 0;
|
|
|
|
|
|
2019-08-29 21:03:16 +02:00
|
|
|
term->search.cursor = 0;
|
2019-08-27 19:33:19 +02:00
|
|
|
term->search.match = (struct coord){-1, -1};
|
|
|
|
|
term->search.match_len = 0;
|
2019-08-29 19:34:41 +02:00
|
|
|
term->is_searching = false;
|
2020-01-05 15:25:24 +01:00
|
|
|
term->render.search_glyph_offset = 0;
|
2019-08-29 19:34:41 +02:00
|
|
|
|
2020-12-07 18:57:16 +01:00
|
|
|
/* Reset IME state */
|
|
|
|
|
if (term_ime_is_enabled(term)) {
|
|
|
|
|
term_ime_disable(term);
|
|
|
|
|
term_ime_enable(term);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-29 22:11:15 +01:00
|
|
|
term_xcursor_update(term);
|
2019-08-29 19:34:41 +02:00
|
|
|
render_refresh(term);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
search_begin(struct terminal *term)
|
|
|
|
|
{
|
|
|
|
|
LOG_DBG("search: begin");
|
|
|
|
|
|
|
|
|
|
search_cancel_keep_selection(term);
|
|
|
|
|
selection_cancel(term);
|
|
|
|
|
|
2020-12-07 18:57:16 +01:00
|
|
|
/* Reset IME state */
|
|
|
|
|
if (term_ime_is_enabled(term)) {
|
|
|
|
|
term_ime_disable(term);
|
|
|
|
|
term_ime_enable(term);
|
|
|
|
|
}
|
|
|
|
|
|
wayland: instantiate sub-surfaces on-demand
While most compositors handle instantiated but not-yet-mapped
sub-surfaces correctly, e.g. kwin does not.
For example, it will incorrectly offset the main surface both
horizontally and vertically with a couple of pixels, leaving two
transparent areas at the top and left, between the SSDs and the main
surface.
Note that a workaround is to position the sub-surfaces inside the main
surface while they're unmapped. However, since the surfaces may be
larger than the main surface (the CSDs, for examples, always are),
this doesn't quite work since kwin, at least, resizes the window to
include the sub-surfaces, even when unmapped.
So, instead we instantiate all sub-surfaces on demand, when we know
where to position them, and when they should be mapped.
2020-02-26 12:22:16 +01:00
|
|
|
/* On-demand instantiate wayland surface */
|
2022-04-16 17:41:14 +02:00
|
|
|
bool ret = wayl_win_subsurface_new(
|
|
|
|
|
term->window, &term->window->search, false);
|
2021-02-12 11:47:49 +01:00
|
|
|
xassert(ret);
|
wayland: instantiate sub-surfaces on-demand
While most compositors handle instantiated but not-yet-mapped
sub-surfaces correctly, e.g. kwin does not.
For example, it will incorrectly offset the main surface both
horizontally and vertically with a couple of pixels, leaving two
transparent areas at the top and left, between the SSDs and the main
surface.
Note that a workaround is to position the sub-surfaces inside the main
surface while they're unmapped. However, since the surfaces may be
larger than the main surface (the CSDs, for examples, always are),
this doesn't quite work since kwin, at least, resizes the window to
include the sub-surfaces, even when unmapped.
So, instead we instantiate all sub-surfaces on demand, when we know
where to position them, and when they should be mapped.
2020-02-26 12:22:16 +01:00
|
|
|
|
2022-04-09 17:28:16 +02:00
|
|
|
const struct grid *grid = term->grid;
|
|
|
|
|
term->search.original_view = grid->view;
|
|
|
|
|
term->search.view_followed_offset = grid->view == grid->offset;
|
2019-08-27 17:23:28 +02:00
|
|
|
term->is_searching = true;
|
|
|
|
|
|
2020-12-05 23:29:12 +01:00
|
|
|
term->search.len = 0;
|
|
|
|
|
term->search.sz = 64;
|
|
|
|
|
term->search.buf = xmalloc(term->search.sz * sizeof(term->search.buf[0]));
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
term->search.buf[0] = U'\0';
|
2020-12-05 23:29:12 +01:00
|
|
|
|
2019-11-29 22:11:15 +01:00
|
|
|
term_xcursor_update(term);
|
2020-03-06 19:16:54 +01:00
|
|
|
render_refresh_search(term);
|
2019-08-27 17:23:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
search_cancel(struct terminal *term)
|
|
|
|
|
{
|
2019-08-29 19:34:41 +02:00
|
|
|
if (!term->is_searching)
|
|
|
|
|
return;
|
2019-08-27 17:23:28 +02:00
|
|
|
|
2019-08-29 19:34:41 +02:00
|
|
|
search_cancel_keep_selection(term);
|
|
|
|
|
selection_cancel(term);
|
2019-08-27 17:23:28 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-22 17:53:29 +02:00
|
|
|
void
|
|
|
|
|
search_selection_cancelled(struct terminal *term)
|
|
|
|
|
{
|
|
|
|
|
term->search.match = (struct coord){-1, -1};
|
|
|
|
|
term->search.match_len = 0;
|
2021-07-22 17:57:25 +02:00
|
|
|
render_refresh_search(term);
|
2021-07-22 17:53:29 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-03 19:40:22 +01:00
|
|
|
static void
|
2022-04-16 20:23:15 +02:00
|
|
|
search_update_selection(struct terminal *term, const struct range *match)
|
2019-12-03 19:40:22 +01:00
|
|
|
{
|
2022-04-09 17:28:16 +02:00
|
|
|
struct grid *grid = term->grid;
|
2022-04-16 20:23:15 +02:00
|
|
|
int start_row = match->start.row;
|
|
|
|
|
int start_col = match->start.col;
|
|
|
|
|
int end_row = match->end.row;
|
|
|
|
|
int end_col = match->end.col;
|
|
|
|
|
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
xassert(start_row >= 0);
|
|
|
|
|
xassert(start_row < grid->num_rows);
|
|
|
|
|
|
2020-07-25 11:23:54 +02:00
|
|
|
bool move_viewport = true;
|
|
|
|
|
|
2022-04-09 17:28:16 +02:00
|
|
|
int view_end = (grid->view + term->rows - 1) & (grid->num_rows - 1);
|
|
|
|
|
if (view_end >= grid->view) {
|
2020-07-25 11:23:54 +02:00
|
|
|
/* Viewport does *not* wrap around */
|
2022-04-09 17:28:16 +02:00
|
|
|
if (start_row >= grid->view && end_row <= view_end)
|
2020-07-25 11:23:54 +02:00
|
|
|
move_viewport = false;
|
|
|
|
|
} else {
|
|
|
|
|
/* Viewport wraps */
|
2022-04-09 17:28:16 +02:00
|
|
|
if (start_row >= grid->view || end_row <= view_end)
|
2020-07-25 11:23:54 +02:00
|
|
|
move_viewport = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (move_viewport) {
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
int rebased_new_view = grid_row_abs_to_sb(grid, term->rows, start_row);
|
|
|
|
|
|
|
|
|
|
rebased_new_view -= term->rows / 2;
|
|
|
|
|
rebased_new_view =
|
|
|
|
|
min(max(rebased_new_view, 0), grid->num_rows - term->rows);
|
|
|
|
|
|
|
|
|
|
const int old_view = grid->view;
|
|
|
|
|
int new_view = grid_row_sb_to_abs(grid, term->rows, rebased_new_view);
|
2020-07-25 11:23:54 +02:00
|
|
|
|
2022-04-26 19:32:08 +02:00
|
|
|
/* Scrollback may not be completely filled yet */
|
|
|
|
|
{
|
|
|
|
|
const int mask = grid->num_rows - 1;
|
|
|
|
|
while (grid->rows[new_view] == NULL)
|
|
|
|
|
new_view = (new_view + 1) & mask;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 18:45:35 +02:00
|
|
|
#if defined(_DEBUG)
|
|
|
|
|
/* Verify all to-be-visible rows have been allocated */
|
|
|
|
|
for (int r = 0; r < term->rows; r++)
|
2022-04-09 17:28:16 +02:00
|
|
|
xassert(grid->rows[(new_view + r) & (grid->num_rows - 1)] != NULL);
|
2020-08-12 18:45:35 +02:00
|
|
|
#endif
|
|
|
|
|
|
2022-04-26 19:47:02 +02:00
|
|
|
#if defined(_DEBUG)
|
|
|
|
|
{
|
|
|
|
|
int rel_start_row = grid_row_abs_to_sb(grid, term->rows, start_row);
|
|
|
|
|
int rel_view = grid_row_abs_to_sb(grid, term->rows, new_view);
|
|
|
|
|
xassert(rel_view <= rel_start_row);
|
|
|
|
|
xassert(rel_start_row < rel_view + term->rows);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-07-25 11:23:54 +02:00
|
|
|
/* Update view */
|
2022-04-09 17:28:16 +02:00
|
|
|
grid->view = new_view;
|
2020-07-25 11:23:54 +02:00
|
|
|
if (new_view != old_view)
|
|
|
|
|
term_damage_view(term);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 17:49:50 +02:00
|
|
|
if (start_row != term->search.match.row ||
|
2023-09-26 17:54:03 +02:00
|
|
|
start_col != term->search.match.col ||
|
|
|
|
|
|
|
|
|
|
/* Pointer leave events trigger selection_finalize() :/ */
|
|
|
|
|
!term->selection.ongoing)
|
2020-07-24 17:49:50 +02:00
|
|
|
{
|
2022-04-16 20:23:15 +02:00
|
|
|
int selection_row = start_row - grid->view + grid->num_rows;
|
|
|
|
|
selection_row &= grid->num_rows - 1;
|
2020-07-24 17:49:50 +02:00
|
|
|
|
2021-01-06 10:53:27 +01:00
|
|
|
selection_start(
|
|
|
|
|
term, start_col, selection_row, SELECTION_CHAR_WISE, false);
|
2023-09-26 17:54:03 +02:00
|
|
|
|
|
|
|
|
term->search.match.row = start_row;
|
|
|
|
|
term->search.match.col = start_col;
|
2020-07-24 17:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Update selection endpoint */
|
|
|
|
|
{
|
2022-04-16 20:23:15 +02:00
|
|
|
int selection_row = end_row - grid->view + grid->num_rows;
|
|
|
|
|
selection_row &= grid->num_rows - 1;
|
2020-07-24 17:49:50 +02:00
|
|
|
selection_update(term, end_col, selection_row);
|
|
|
|
|
}
|
2019-12-03 19:40:22 +01:00
|
|
|
}
|
2020-07-08 18:20:34 +02:00
|
|
|
|
2021-01-24 12:02:20 +01:00
|
|
|
static ssize_t
|
|
|
|
|
matches_cell(const struct terminal *term, const struct cell *cell, size_t search_ofs)
|
|
|
|
|
{
|
|
|
|
|
assert(search_ofs < term->search.len);
|
|
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
char32_t base = cell->wc;
|
2021-01-24 12:02:20 +01:00
|
|
|
const struct composed *composed = NULL;
|
|
|
|
|
|
composed: store compose chains in a binary search tree
The previous implementation stored compose chains in a dynamically
allocated array. Adding a chain was easy: resize the array and append
the new chain at the end. Looking up a compose chain given a compose
chain key/index was also easy: just index into the array.
However, searching for a pre-existing chain given a codepoint sequence
was very slow. Since the array wasn’t sorted, we typically had to scan
through the entire array, just to realize that there is no
pre-existing chain, and that we need to add a new one.
Since this happens for *each* codepoint in a grapheme cluster, things
quickly became really slow.
Things were ok:ish as long as the compose chain struct was small, as
that made it possible to hold all the chains in the cache. Once the
number of chains reached a certain point, or when we were forced to
bump maximum number of allowed codepoints in a chain, we started
thrashing the cache and things got much much worse.
So what can we do?
We can’t sort the array, because
a) that would invalidate all existing chain keys in the grid (and
iterating the entire scrollback and updating compose keys is *not* an
option).
b) inserting a chain becomes slow as we need to first find _where_ to
insert it, and then memmove() the rest of the array.
This patch uses a binary search tree to store the chains instead of a
simple array.
The tree is sorted on a “key”, which is the XOR of all codepoints,
truncated to the CELL_COMB_CHARS_HI-CELL_COMB_CHARS_LO range.
The grid now stores CELL_COMB_CHARS_LO+key, instead of
CELL_COMB_CHARS_LO+index.
Since the key is truncated, collisions may occur. This is handled by
incrementing the key by 1.
Lookup is of course slower than before, O(log n) instead of
O(1).
Insertion is slightly slower as well: technically it’s O(log n)
instead of O(1). However, we also need to take into account the
re-allocating the array will occasionally force a full copy of the
array when it cannot simply be growed.
But finding a pre-existing chain is now *much* faster: O(log n)
instead of O(n). In most cases, the first lookup will either
succeed (return a true match), or fail (return NULL). However, since
key collisions are possible, it may also return false matches. This
means we need to verify the contents of the chain before deciding to
use it instead of inserting a new chain. But remember that this
comparison was being done for each and every chain in the previous
implementation.
With lookups being much faster, and in particular, no longer requiring
us to check the chain contents for every singlec chain, we can now use
a dynamically allocated ‘chars’ array in the chain. This was
previously a hardcoded array of 10 chars.
Using a dynamic allocated array means looking in the array is slower,
since we now need two loads: one to load the pointer, and a second to
load _from_ the pointer.
As a result, the base size of a compose chain (i.e. an “empty” chain)
has now been reduced from 48 bytes to 32. A chain with two codepoints
is 40 bytes. This means we have up to 4 codepoints while still using
less, or the same amount, of memory as before.
Furthermore, the Unicode random test (i.e. write random “unicode”
chars) is now **faster** than current master (i.e. before text-shaping
support was added), **with** test-shaping enabled. With text-shaping
disabled, we’re _even_ faster.
2021-06-24 13:17:07 +02:00
|
|
|
if (base >= CELL_COMB_CHARS_LO && base <= CELL_COMB_CHARS_HI)
|
2021-01-24 12:02:20 +01:00
|
|
|
{
|
composed: store compose chains in a binary search tree
The previous implementation stored compose chains in a dynamically
allocated array. Adding a chain was easy: resize the array and append
the new chain at the end. Looking up a compose chain given a compose
chain key/index was also easy: just index into the array.
However, searching for a pre-existing chain given a codepoint sequence
was very slow. Since the array wasn’t sorted, we typically had to scan
through the entire array, just to realize that there is no
pre-existing chain, and that we need to add a new one.
Since this happens for *each* codepoint in a grapheme cluster, things
quickly became really slow.
Things were ok:ish as long as the compose chain struct was small, as
that made it possible to hold all the chains in the cache. Once the
number of chains reached a certain point, or when we were forced to
bump maximum number of allowed codepoints in a chain, we started
thrashing the cache and things got much much worse.
So what can we do?
We can’t sort the array, because
a) that would invalidate all existing chain keys in the grid (and
iterating the entire scrollback and updating compose keys is *not* an
option).
b) inserting a chain becomes slow as we need to first find _where_ to
insert it, and then memmove() the rest of the array.
This patch uses a binary search tree to store the chains instead of a
simple array.
The tree is sorted on a “key”, which is the XOR of all codepoints,
truncated to the CELL_COMB_CHARS_HI-CELL_COMB_CHARS_LO range.
The grid now stores CELL_COMB_CHARS_LO+key, instead of
CELL_COMB_CHARS_LO+index.
Since the key is truncated, collisions may occur. This is handled by
incrementing the key by 1.
Lookup is of course slower than before, O(log n) instead of
O(1).
Insertion is slightly slower as well: technically it’s O(log n)
instead of O(1). However, we also need to take into account the
re-allocating the array will occasionally force a full copy of the
array when it cannot simply be growed.
But finding a pre-existing chain is now *much* faster: O(log n)
instead of O(n). In most cases, the first lookup will either
succeed (return a true match), or fail (return NULL). However, since
key collisions are possible, it may also return false matches. This
means we need to verify the contents of the chain before deciding to
use it instead of inserting a new chain. But remember that this
comparison was being done for each and every chain in the previous
implementation.
With lookups being much faster, and in particular, no longer requiring
us to check the chain contents for every singlec chain, we can now use
a dynamically allocated ‘chars’ array in the chain. This was
previously a hardcoded array of 10 chars.
Using a dynamic allocated array means looking in the array is slower,
since we now need two loads: one to load the pointer, and a second to
load _from_ the pointer.
As a result, the base size of a compose chain (i.e. an “empty” chain)
has now been reduced from 48 bytes to 32. A chain with two codepoints
is 40 bytes. This means we have up to 4 codepoints while still using
less, or the same amount, of memory as before.
Furthermore, the Unicode random test (i.e. write random “unicode”
chars) is now **faster** than current master (i.e. before text-shaping
support was added), **with** test-shaping enabled. With text-shaping
disabled, we’re _even_ faster.
2021-06-24 13:17:07 +02:00
|
|
|
composed = composed_lookup(term->composed, base - CELL_COMB_CHARS_LO);
|
2020-08-20 19:25:35 +02:00
|
|
|
base = composed->chars[0];
|
2021-01-24 12:02:20 +01:00
|
|
|
}
|
|
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
if (composed == NULL && base == 0 && term->search.buf[search_ofs] == U' ')
|
2021-03-27 22:15:44 +01:00
|
|
|
return 1;
|
|
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
if (c32ncasecmp(&base, &term->search.buf[search_ofs], 1) != 0)
|
2021-01-24 12:02:20 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (composed != NULL) {
|
2023-09-26 17:54:03 +02:00
|
|
|
if (search_ofs + composed->count > term->search.len)
|
2021-01-24 12:02:20 +01:00
|
|
|
return -1;
|
|
|
|
|
|
2020-08-20 19:25:35 +02:00
|
|
|
for (size_t j = 1; j < composed->count; j++) {
|
2023-09-26 17:54:03 +02:00
|
|
|
if (composed->chars[j] != term->search.buf[search_ofs + j])
|
2021-01-24 12:02:20 +01:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
return composed != NULL ? composed->count : 1;
|
2021-01-24 12:02:20 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-16 20:13:22 +02:00
|
|
|
static bool
|
|
|
|
|
find_next(struct terminal *term, enum search_direction direction,
|
2022-04-18 12:31:07 +02:00
|
|
|
struct coord abs_start, struct coord abs_end, struct range *match)
|
2019-08-27 19:33:19 +02:00
|
|
|
{
|
2022-04-09 17:28:16 +02:00
|
|
|
#define ROW_DEC(_r) ((_r) = ((_r) - 1 + grid->num_rows) & (grid->num_rows - 1))
|
|
|
|
|
#define ROW_INC(_r) ((_r) = ((_r) + 1) & (grid->num_rows - 1))
|
2019-08-27 21:09:37 +02:00
|
|
|
|
2022-04-16 20:13:22 +02:00
|
|
|
struct grid *grid = term->grid;
|
2022-04-21 18:54:27 +02:00
|
|
|
const bool backward = direction != SEARCH_FORWARD;
|
2022-04-16 20:13:22 +02:00
|
|
|
|
2022-04-18 14:43:01 +02:00
|
|
|
LOG_DBG("%s: start: %dx%d, end: %dx%d", backward ? "backward" : "forward",
|
|
|
|
|
abs_start.row, abs_start.col, abs_end.row, abs_end.col);
|
2022-04-18 12:31:07 +02:00
|
|
|
|
2022-04-18 14:47:07 +02:00
|
|
|
xassert(abs_start.row >= 0);
|
|
|
|
|
xassert(abs_start.row < grid->num_rows);
|
|
|
|
|
xassert(abs_start.col >= 0);
|
|
|
|
|
xassert(abs_start.col < term->cols);
|
|
|
|
|
|
|
|
|
|
xassert(abs_end.row >= 0);
|
|
|
|
|
xassert(abs_end.row < grid->num_rows);
|
|
|
|
|
xassert(abs_end.col >= 0);
|
|
|
|
|
xassert(abs_end.col < term->cols);
|
|
|
|
|
|
2022-04-18 14:43:01 +02:00
|
|
|
for (int match_start_row = abs_start.row, match_start_col = abs_start.col;
|
|
|
|
|
;
|
|
|
|
|
backward ? ROW_DEC(match_start_row) : ROW_INC(match_start_row)) {
|
2022-04-18 12:31:07 +02:00
|
|
|
|
2022-04-18 12:38:09 +02:00
|
|
|
const struct row *row = grid->rows[match_start_row];
|
2022-04-18 14:43:01 +02:00
|
|
|
if (row == NULL) {
|
|
|
|
|
if (match_start_row == abs_end.row)
|
|
|
|
|
break;
|
2022-04-16 20:13:22 +02:00
|
|
|
continue;
|
2022-04-18 14:43:01 +02:00
|
|
|
}
|
2022-04-16 20:13:22 +02:00
|
|
|
|
2019-08-30 20:15:12 +02:00
|
|
|
for (;
|
2022-04-18 12:38:09 +02:00
|
|
|
backward ? match_start_col >= 0 : match_start_col < term->cols;
|
|
|
|
|
backward ? match_start_col-- : match_start_col++)
|
2019-08-30 20:15:12 +02:00
|
|
|
{
|
2022-04-18 14:43:01 +02:00
|
|
|
if (matches_cell(term, &row->cells[match_start_col], 0) < 0) {
|
|
|
|
|
if (match_start_row == abs_end.row &&
|
|
|
|
|
match_start_col == abs_end.col)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-08-27 19:33:19 +02:00
|
|
|
continue;
|
2022-04-18 14:43:01 +02:00
|
|
|
}
|
2019-08-27 19:33:19 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Got a match on the first letter. Now we'll see if the
|
|
|
|
|
* rest of the search buffer matches.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-04-18 14:43:01 +02:00
|
|
|
LOG_DBG("search: initial match at row=%d, col=%d",
|
|
|
|
|
match_start_row, match_start_col);
|
2019-08-27 19:33:19 +02:00
|
|
|
|
2022-04-18 12:38:09 +02:00
|
|
|
int match_end_row = match_start_row;
|
|
|
|
|
int match_end_col = match_start_col;
|
2022-04-18 14:43:01 +02:00
|
|
|
const struct row *match_row = row;
|
2019-08-27 19:33:19 +02:00
|
|
|
size_t match_len = 0;
|
|
|
|
|
|
2021-01-24 12:02:20 +01:00
|
|
|
for (size_t i = 0; i < term->search.len;) {
|
2022-04-18 12:38:09 +02:00
|
|
|
if (match_end_col >= term->cols) {
|
2022-04-18 14:43:01 +02:00
|
|
|
ROW_INC(match_end_row);
|
2022-04-18 12:38:09 +02:00
|
|
|
match_end_col = 0;
|
2021-03-28 20:59:35 +02:00
|
|
|
|
2022-04-18 14:43:01 +02:00
|
|
|
match_row = grid->rows[match_end_row];
|
|
|
|
|
if (match_row == NULL)
|
2021-03-28 20:59:35 +02:00
|
|
|
break;
|
2019-08-27 19:33:19 +02:00
|
|
|
}
|
2019-12-03 19:17:51 +01:00
|
|
|
|
2022-04-18 14:43:01 +02:00
|
|
|
if (match_row->cells[match_end_col].wc >= CELL_SPACER) {
|
2022-04-18 12:38:09 +02:00
|
|
|
match_end_col++;
|
2021-01-26 20:05:14 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 12:38:09 +02:00
|
|
|
ssize_t additional_chars = matches_cell(
|
2022-04-18 14:43:01 +02:00
|
|
|
term, &match_row->cells[match_end_col], i);
|
2021-01-24 12:02:20 +01:00
|
|
|
if (additional_chars < 0)
|
2019-12-03 19:17:51 +01:00
|
|
|
break;
|
|
|
|
|
|
2021-01-24 12:02:20 +01:00
|
|
|
i += additional_chars;
|
|
|
|
|
match_len += additional_chars;
|
2022-04-18 12:38:09 +02:00
|
|
|
match_end_col++;
|
2022-07-28 18:56:28 +02:00
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
while (match_end_col < term->cols &&
|
|
|
|
|
match_row->cells[match_end_col].wc > CELL_SPACER)
|
|
|
|
|
{
|
2022-07-28 18:56:28 +02:00
|
|
|
match_end_col++;
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
2019-08-27 19:33:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (match_len != term->search.len) {
|
|
|
|
|
/* Didn't match (completely) */
|
2022-04-26 18:24:22 +02:00
|
|
|
|
|
|
|
|
if (match_start_row == abs_end.row &&
|
|
|
|
|
match_start_col == abs_end.col)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 19:33:19 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 20:13:22 +02:00
|
|
|
*match = (struct range){
|
2022-04-18 12:38:09 +02:00
|
|
|
.start = {match_start_col, match_start_row},
|
|
|
|
|
.end = {match_end_col - 1, match_end_row},
|
2022-04-16 20:13:22 +02:00
|
|
|
};
|
2019-08-27 19:33:19 +02:00
|
|
|
|
2022-04-16 20:13:22 +02:00
|
|
|
return true;
|
2019-08-27 19:33:19 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-18 14:43:01 +02:00
|
|
|
if (match_start_row == abs_end.row && match_start_col == abs_end.col)
|
|
|
|
|
break;
|
|
|
|
|
|
2022-04-18 12:38:09 +02:00
|
|
|
match_start_col = backward ? term->cols - 1 : 0;
|
2019-08-27 19:33:19 +02:00
|
|
|
}
|
2019-08-27 19:58:44 +02:00
|
|
|
|
2022-04-16 20:13:22 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2022-04-21 18:54:27 +02:00
|
|
|
search_find_next(struct terminal *term, enum search_direction direction)
|
2022-04-16 20:13:22 +02:00
|
|
|
{
|
|
|
|
|
struct grid *grid = term->grid;
|
|
|
|
|
|
|
|
|
|
if (term->search.len == 0) {
|
|
|
|
|
term->search.match = (struct coord){-1, -1};
|
|
|
|
|
term->search.match_len = 0;
|
|
|
|
|
selection_cancel(term);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 12:17:49 +02:00
|
|
|
struct coord start = term->search.match;
|
2022-04-16 20:13:22 +02:00
|
|
|
size_t len = term->search.match_len;
|
|
|
|
|
|
2022-04-18 12:17:49 +02:00
|
|
|
xassert((len == 0 && start.row == -1 && start.col == -1) ||
|
|
|
|
|
(len > 0 && start.row >= 0 && start.col >= 0));
|
2022-04-16 20:13:22 +02:00
|
|
|
|
|
|
|
|
if (len == 0) {
|
2022-04-21 18:54:27 +02:00
|
|
|
/* No previous match, start from the top, or bottom, of the scrollback */
|
|
|
|
|
switch (direction) {
|
|
|
|
|
case SEARCH_FORWARD:
|
2022-04-18 12:17:49 +02:00
|
|
|
start.row = grid_row_absolute_in_view(grid, 0);
|
|
|
|
|
start.col = 0;
|
2022-04-21 18:54:27 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SEARCH_BACKWARD:
|
|
|
|
|
case SEARCH_BACKWARD_SAME_POSITION:
|
|
|
|
|
start.row = grid_row_absolute_in_view(grid, term->rows - 1);
|
|
|
|
|
start.col = term->cols - 1;
|
|
|
|
|
break;
|
2022-04-16 20:13:22 +02:00
|
|
|
}
|
2022-04-21 18:54:27 +02:00
|
|
|
} else {
|
|
|
|
|
/* Continue from last match */
|
|
|
|
|
xassert(start.row >= 0);
|
|
|
|
|
xassert(start.col >= 0);
|
|
|
|
|
|
|
|
|
|
switch (direction) {
|
|
|
|
|
case SEARCH_BACKWARD_SAME_POSITION:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SEARCH_BACKWARD:
|
|
|
|
|
if (--start.col < 0) {
|
|
|
|
|
start.col = term->cols - 1;
|
|
|
|
|
start.row += grid->num_rows - 1;
|
|
|
|
|
start.row &= grid->num_rows - 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SEARCH_FORWARD:
|
|
|
|
|
if (++start.col >= term->cols) {
|
|
|
|
|
start.col = 0;
|
|
|
|
|
start.row++;
|
|
|
|
|
start.row &= grid->num_rows - 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xassert(start.row >= 0);
|
|
|
|
|
xassert(start.row < grid->num_rows);
|
|
|
|
|
xassert(start.col >= 0);
|
|
|
|
|
xassert(start.col < term->cols);
|
2022-04-16 20:13:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG_DBG(
|
2022-04-17 19:17:51 +02:00
|
|
|
"update: %s: starting at row=%d col=%d "
|
2022-04-16 20:13:22 +02:00
|
|
|
"(offset = %d, view = %d)",
|
2022-04-24 12:03:31 +02:00
|
|
|
direction != SEARCH_FORWARD ? "backward" : "forward",
|
|
|
|
|
start.row, start.col,
|
2022-04-16 20:13:22 +02:00
|
|
|
grid->offset, grid->view);
|
|
|
|
|
|
2022-04-18 12:31:07 +02:00
|
|
|
struct coord end = start;
|
2022-04-21 18:54:27 +02:00
|
|
|
switch (direction) {
|
|
|
|
|
case SEARCH_FORWARD:
|
2022-04-18 12:31:07 +02:00
|
|
|
/* Search forward, until we reach the cell *before* current start */
|
|
|
|
|
if (--end.col < 0) {
|
|
|
|
|
end.col = term->cols - 1;
|
|
|
|
|
end.row += grid->num_rows - 1;
|
2022-04-21 18:54:27 +02:00
|
|
|
end.row &= grid->num_rows - 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SEARCH_BACKWARD:
|
|
|
|
|
case SEARCH_BACKWARD_SAME_POSITION:
|
|
|
|
|
/* Search backwards, until we reach the cell *after* current start */
|
|
|
|
|
if (++end.col >= term->cols) {
|
|
|
|
|
end.col = 0;
|
|
|
|
|
end.row++;
|
|
|
|
|
end.row &= grid->num_rows - 1;
|
2022-04-18 12:31:07 +02:00
|
|
|
}
|
2022-04-21 18:54:27 +02:00
|
|
|
break;
|
2022-04-18 12:31:07 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-16 20:13:22 +02:00
|
|
|
struct range match;
|
2022-04-18 12:31:07 +02:00
|
|
|
bool found = find_next(term, direction, start, end, &match);
|
2022-04-16 20:13:22 +02:00
|
|
|
|
|
|
|
|
if (found) {
|
2022-04-17 19:17:51 +02:00
|
|
|
LOG_DBG("primary match found at %dx%d",
|
|
|
|
|
match.start.row, match.start.col);
|
2022-04-16 20:23:15 +02:00
|
|
|
search_update_selection(term, &match);
|
2022-04-16 20:13:22 +02:00
|
|
|
term->search.match = match.start;
|
|
|
|
|
term->search.match_len = term->search.len;
|
|
|
|
|
} else {
|
|
|
|
|
LOG_DBG("no match");
|
|
|
|
|
term->search.match = (struct coord){-1, -1};
|
|
|
|
|
term->search.match_len = 0;
|
|
|
|
|
selection_cancel(term);
|
|
|
|
|
}
|
2019-08-27 21:09:37 +02:00
|
|
|
#undef ROW_DEC
|
2019-08-27 19:33:19 +02:00
|
|
|
}
|
2020-07-08 18:20:34 +02:00
|
|
|
|
search/render: initial support for highlighting all visible matches
Before this patch, only the currently “selected” match was
highlighted (by having the “selected” attribute, and by *not* dimming
it, like the rest of the grid during a scrollback search).
With this patch, we now highlight matches within the viewport. While
searching, only the “primary” match is searched-for, and tracked.
Then, when rendering a frame, we find all “secondary” matches as
well. “holes” are added to the search-mode overlay by the means of an
search-match iterator.
The iterator’s text matching logic is *very* similar to what we do
when the search criteria has been updated, and we re-search the
scrollback. It should be possible to refactor this, and share code.
2022-04-09 17:57:29 +02:00
|
|
|
struct search_match_iterator
|
|
|
|
|
search_matches_new_iter(struct terminal *term)
|
|
|
|
|
{
|
|
|
|
|
return (struct search_match_iterator){
|
|
|
|
|
.term = term,
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
.start = {0, 0},
|
search/render: initial support for highlighting all visible matches
Before this patch, only the currently “selected” match was
highlighted (by having the “selected” attribute, and by *not* dimming
it, like the rest of the grid during a scrollback search).
With this patch, we now highlight matches within the viewport. While
searching, only the “primary” match is searched-for, and tracked.
Then, when rendering a frame, we find all “secondary” matches as
well. “holes” are added to the search-mode overlay by the means of an
search-match iterator.
The iterator’s text matching logic is *very* similar to what we do
when the search criteria has been updated, and we re-search the
scrollback. It should be possible to refactor this, and share code.
2022-04-09 17:57:29 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct range
|
|
|
|
|
search_matches_next(struct search_match_iterator *iter)
|
|
|
|
|
{
|
|
|
|
|
struct terminal *term = iter->term;
|
2022-04-16 20:13:22 +02:00
|
|
|
struct grid *grid = term->grid;
|
search/render: initial support for highlighting all visible matches
Before this patch, only the currently “selected” match was
highlighted (by having the “selected” attribute, and by *not* dimming
it, like the rest of the grid during a scrollback search).
With this patch, we now highlight matches within the viewport. While
searching, only the “primary” match is searched-for, and tracked.
Then, when rendering a frame, we find all “secondary” matches as
well. “holes” are added to the search-mode overlay by the means of an
search-match iterator.
The iterator’s text matching logic is *very* similar to what we do
when the search criteria has been updated, and we re-search the
scrollback. It should be possible to refactor this, and share code.
2022-04-09 17:57:29 +02:00
|
|
|
|
|
|
|
|
if (term->search.match_len == 0)
|
2022-04-16 20:13:22 +02:00
|
|
|
goto no_match;
|
|
|
|
|
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
if (iter->start.row >= term->rows)
|
|
|
|
|
goto no_match;
|
2022-04-17 19:17:51 +02:00
|
|
|
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
xassert(iter->start.row >= 0);
|
|
|
|
|
xassert(iter->start.row < term->rows);
|
|
|
|
|
xassert(iter->start.col >= 0);
|
|
|
|
|
xassert(iter->start.col < term->cols);
|
2022-04-17 19:17:51 +02:00
|
|
|
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
struct coord abs_start = iter->start;
|
|
|
|
|
abs_start.row = grid_row_absolute_in_view(grid, abs_start.row);
|
2022-04-23 12:28:12 +02:00
|
|
|
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
struct coord abs_end = {
|
|
|
|
|
term->cols - 1,
|
|
|
|
|
grid_row_absolute_in_view(grid, term->rows - 1)};
|
|
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
/* BUG: matches *starting* outside the view, but ending *inside*, aren't matched */
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
struct range match;
|
|
|
|
|
bool found = find_next(term, SEARCH_FORWARD, abs_start, abs_end, &match);
|
|
|
|
|
if (!found)
|
2022-04-23 12:28:12 +02:00
|
|
|
goto no_match;
|
|
|
|
|
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
LOG_DBG("match at (absolute coordinates) %dx%d-%dx%d",
|
|
|
|
|
match.start.row, match.start.col,
|
|
|
|
|
match.end.row, match.end.col);
|
2022-04-23 12:28:12 +02:00
|
|
|
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
/* Convert absolute row numbers back to view relative */
|
|
|
|
|
match.start.row = match.start.row - grid->view + grid->num_rows;
|
|
|
|
|
match.start.row &= grid->num_rows - 1;
|
|
|
|
|
match.end.row = match.end.row - grid->view + grid->num_rows;
|
|
|
|
|
match.end.row &= grid->num_rows - 1;
|
2022-04-18 12:17:49 +02:00
|
|
|
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
LOG_DBG("match at (view-local coordinates) %dx%d-%dx%d, view=%d",
|
|
|
|
|
match.start.row, match.start.col,
|
|
|
|
|
match.end.row, match.end.col, grid->view);
|
2022-04-18 12:31:07 +02:00
|
|
|
|
2022-04-26 18:24:22 +02:00
|
|
|
/* Assert match end comes *after* the match start */
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
xassert(match.end.row > match.start.row ||
|
|
|
|
|
(match.end.row == match.start.row &&
|
|
|
|
|
match.end.col >= match.start.col));
|
2022-04-18 14:47:17 +02:00
|
|
|
|
2022-04-26 18:24:22 +02:00
|
|
|
/* Assert the match starts at, or after, the iterator position */
|
|
|
|
|
xassert(match.start.row > iter->start.row ||
|
|
|
|
|
(match.start.row == iter->start.row &&
|
|
|
|
|
match.start.col >= iter->start.col));
|
|
|
|
|
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
/* Continue at next column, next time */
|
|
|
|
|
iter->start.row = match.start.row;
|
|
|
|
|
iter->start.col = match.start.col + 1;
|
|
|
|
|
|
|
|
|
|
if (iter->start.col >= term->cols) {
|
|
|
|
|
iter->start.col = 0;
|
|
|
|
|
iter->start.row++; /* Overflow is caught in next iteration */
|
search/render: initial support for highlighting all visible matches
Before this patch, only the currently “selected” match was
highlighted (by having the “selected” attribute, and by *not* dimming
it, like the rest of the grid during a scrollback search).
With this patch, we now highlight matches within the viewport. While
searching, only the “primary” match is searched-for, and tracked.
Then, when rendering a frame, we find all “secondary” matches as
well. “holes” are added to the search-mode overlay by the means of an
search-match iterator.
The iterator’s text matching logic is *very* similar to what we do
when the search criteria has been updated, and we re-search the
scrollback. It should be possible to refactor this, and share code.
2022-04-09 17:57:29 +02:00
|
|
|
}
|
|
|
|
|
|
search: fix multiple crashes
* When extending the selection to the next word boundary, ensure the
row numbers are valid:
- use selection_get_end() when retrieving the current end
coordinate. This alone fixes a crash where we previously would
crash in an out-of-bounds array access in grid->rows[], due to
term->selection.coords.end being unbounded.
- ensure the new end coordinate is bounded before and after calling
selection_find_word_boundary_right().
* When moving the viewport (to ensure a new match is visible), make
sure we don’t end up with the match outside the new viewport.
Under certain, unusual, circumstances, the moved viewport _still_
did not contain the match. This resulted in assertions triggering
later, that assumed the match(es) are *always* visible.
It’s fairly easy to trigger this one by running foot with e.g.
foot -o scrollback.lines=0 --window-size-chars 25x3
and then hitting enter a couple of times, to fill the scrollback
history (which should consist of a single row in the example above),
and the do a scrollback search for (part of) the prompt, and keep
searching backward until it crashes.
This would happen if calculated (new) viewport had to be adjusted
(for example, to ensure it didn’t go past the scrollback end).
This patch changes the logic used when calculating the new
viewport. Instead of calculating the wanted viewport (match is
vertically centered) and then trying to adjust it to ensure the new
viewport is valid, start with a “safe” new viewport value, and then
determine how much we can move it, if at all, to center the match.
This is done by using scrollback relative coordinates. In this
coordinate system, the new viewport must be
>= 0, and < grid->num_lines - term->rows
This makes it very easy to limit the amount by which the viewport is
adjusted.
As a side-effect, we can remove all the old re-adjustment logic.
* The match iterator no longer special cases the primary match. This
was needed before, when the search iterator did not handle
overlapping matches correctly. Now that we do, the iterator is
guaranteed to find the primary match, and thus we no longer need to
special case it.
This fixes a bug where the primary match was returned twice, due to
the logic checking if a secondary match is the same as the primary
match was flawed...
Closes #1036
2022-04-25 20:00:47 +02:00
|
|
|
xassert(iter->start.row >= 0);
|
|
|
|
|
xassert(iter->start.row <= term->rows);
|
|
|
|
|
xassert(iter->start.col >= 0);
|
|
|
|
|
xassert(iter->start.col < term->cols);
|
|
|
|
|
return match;
|
|
|
|
|
|
2022-04-16 20:13:22 +02:00
|
|
|
no_match:
|
search/render: initial support for highlighting all visible matches
Before this patch, only the currently “selected” match was
highlighted (by having the “selected” attribute, and by *not* dimming
it, like the rest of the grid during a scrollback search).
With this patch, we now highlight matches within the viewport. While
searching, only the “primary” match is searched-for, and tracked.
Then, when rendering a frame, we find all “secondary” matches as
well. “holes” are added to the search-mode overlay by the means of an
search-match iterator.
The iterator’s text matching logic is *very* similar to what we do
when the search criteria has been updated, and we re-search the
scrollback. It should be possible to refactor this, and share code.
2022-04-09 17:57:29 +02:00
|
|
|
iter->start.row = -1;
|
|
|
|
|
iter->start.col = -1;
|
|
|
|
|
return (struct range){{-1, -1}, {-1, -1}};
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 18:34:27 +01:00
|
|
|
static void
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
add_wchars(struct terminal *term, char32_t *src, size_t count)
|
2022-01-27 18:34:27 +01:00
|
|
|
{
|
|
|
|
|
/* Strip non-printable characters */
|
|
|
|
|
for (size_t i = 0, j = 0, orig_count = count; i < orig_count; i++) {
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
if (isc32print(src[i]))
|
2022-01-27 18:34:27 +01:00
|
|
|
src[j++] = src[i];
|
|
|
|
|
else
|
|
|
|
|
count--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!search_ensure_size(term, term->search.len + count))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
xassert(term->search.len + count < term->search.sz);
|
|
|
|
|
|
|
|
|
|
memmove(&term->search.buf[term->search.cursor + count],
|
|
|
|
|
&term->search.buf[term->search.cursor],
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
(term->search.len - term->search.cursor) * sizeof(char32_t));
|
2022-01-27 18:34:27 +01:00
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
memcpy(&term->search.buf[term->search.cursor], src, count * sizeof(char32_t));
|
2022-01-27 18:34:27 +01:00
|
|
|
|
|
|
|
|
term->search.len += count;
|
|
|
|
|
term->search.cursor += count;
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
term->search.buf[term->search.len] = U'\0';
|
2022-01-27 18:34:27 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-05 11:49:32 +01:00
|
|
|
void
|
|
|
|
|
search_add_chars(struct terminal *term, const char *src, size_t count)
|
2020-11-01 12:39:57 +01:00
|
|
|
{
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
size_t chars = mbsntoc32(NULL, src, count, 0);
|
|
|
|
|
if (chars == (size_t)-1) {
|
|
|
|
|
LOG_ERRNO("failed to convert %.*s to Unicode", (int)count, src);
|
2020-11-01 12:39:57 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
char32_t c32s[chars + 1];
|
|
|
|
|
mbsntoc32(c32s, src, count, chars);
|
|
|
|
|
add_wchars(term, c32s, chars);
|
2020-11-01 12:39:57 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
enum extend_direction {SEARCH_EXTEND_LEFT, SEARCH_EXTEND_RIGHT};
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
coord_advance_left(const struct terminal *term, struct coord *pos,
|
|
|
|
|
const struct row **row)
|
|
|
|
|
{
|
|
|
|
|
const struct grid *grid = term->grid;
|
|
|
|
|
struct coord new_pos = *pos;
|
|
|
|
|
|
|
|
|
|
if (--new_pos.col < 0) {
|
|
|
|
|
new_pos.row = (new_pos.row - 1 + grid->num_rows) & (grid->num_rows - 1);
|
|
|
|
|
new_pos.col = term->cols - 1;
|
|
|
|
|
|
|
|
|
|
if (has_wrapped_around_left(term, new_pos.row))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (row != NULL)
|
|
|
|
|
*row = grid->rows[new_pos.row];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*pos = new_pos;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
coord_advance_right(const struct terminal *term, struct coord *pos,
|
|
|
|
|
const struct row **row)
|
|
|
|
|
{
|
|
|
|
|
const struct grid *grid = term->grid;
|
|
|
|
|
struct coord new_pos = *pos;
|
|
|
|
|
|
|
|
|
|
if (++new_pos.col >= term->cols) {
|
|
|
|
|
new_pos.row = (new_pos.row + 1) & (grid->num_rows - 1);
|
|
|
|
|
new_pos.col = 0;
|
|
|
|
|
|
|
|
|
|
if (has_wrapped_around_right(term, new_pos.row))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (row != NULL)
|
|
|
|
|
*row = grid->rows[new_pos.row];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*pos = new_pos;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 10:28:17 +02:00
|
|
|
static bool
|
2023-09-26 17:54:03 +02:00
|
|
|
search_extend_find_char(const struct terminal *term, struct coord *target,
|
|
|
|
|
enum extend_direction direction)
|
2019-12-03 19:22:47 +01:00
|
|
|
{
|
2023-09-27 18:36:52 +02:00
|
|
|
if (term->search.match_len == 0)
|
2023-10-08 10:28:17 +02:00
|
|
|
return false;
|
2023-09-27 18:36:52 +02:00
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
struct coord pos = direction == SEARCH_EXTEND_LEFT
|
|
|
|
|
? selection_get_start(term) : selection_get_end(term);
|
|
|
|
|
xassert(pos.row >= 0);
|
|
|
|
|
xassert(pos.row < term->grid->num_rows);
|
|
|
|
|
|
|
|
|
|
*target = pos;
|
|
|
|
|
|
|
|
|
|
const struct row *row = term->grid->rows[pos.row];
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
switch (direction) {
|
|
|
|
|
case SEARCH_EXTEND_LEFT:
|
|
|
|
|
if (!coord_advance_left(term, &pos, &row))
|
2023-10-08 10:28:17 +02:00
|
|
|
return false;
|
2023-09-26 17:54:03 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SEARCH_EXTEND_RIGHT:
|
|
|
|
|
if (!coord_advance_right(term, &pos, &row))
|
2023-10-08 10:28:17 +02:00
|
|
|
return false;
|
2023-09-26 17:54:03 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char32_t wc = row->cells[pos.col].wc;
|
|
|
|
|
|
|
|
|
|
if (wc >= CELL_SPACER || wc == U'\0')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
*target = pos;
|
2023-10-08 10:28:17 +02:00
|
|
|
return true;
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 10:28:17 +02:00
|
|
|
static bool
|
2023-09-26 17:54:03 +02:00
|
|
|
search_extend_find_char_left(const struct terminal *term, struct coord *target)
|
|
|
|
|
{
|
2023-10-08 10:28:17 +02:00
|
|
|
return search_extend_find_char(term, target, SEARCH_EXTEND_LEFT);
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
2019-12-03 19:22:47 +01:00
|
|
|
|
2023-10-08 10:28:17 +02:00
|
|
|
static bool
|
2023-09-26 17:54:03 +02:00
|
|
|
search_extend_find_char_right(const struct terminal *term, struct coord *target)
|
|
|
|
|
{
|
2023-10-08 10:28:17 +02:00
|
|
|
return search_extend_find_char(term, target, SEARCH_EXTEND_RIGHT);
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
2019-12-03 19:22:47 +01:00
|
|
|
|
2023-10-08 10:28:17 +02:00
|
|
|
static bool
|
2023-09-26 17:54:03 +02:00
|
|
|
search_extend_find_word(const struct terminal *term, bool spaces_only,
|
|
|
|
|
struct coord *target, enum extend_direction direction)
|
|
|
|
|
{
|
2023-09-27 18:36:52 +02:00
|
|
|
if (term->search.match_len == 0)
|
2023-10-08 10:28:17 +02:00
|
|
|
return false;
|
2023-09-27 18:36:52 +02:00
|
|
|
|
2022-04-09 17:28:16 +02:00
|
|
|
struct grid *grid = term->grid;
|
2023-09-26 17:54:03 +02:00
|
|
|
struct coord pos = direction == SEARCH_EXTEND_LEFT
|
|
|
|
|
? selection_get_start(term)
|
|
|
|
|
: selection_get_end(term);
|
2023-09-27 18:36:52 +02:00
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
xassert(pos.row >= 0);
|
|
|
|
|
xassert(pos.row < grid->num_rows);
|
2019-12-03 19:22:47 +01:00
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
*target = pos;
|
2019-12-03 19:22:47 +01:00
|
|
|
|
2021-03-28 21:06:21 +02:00
|
|
|
/* First character to consider is the *next* character */
|
2023-09-26 17:54:03 +02:00
|
|
|
switch (direction) {
|
|
|
|
|
case SEARCH_EXTEND_LEFT:
|
|
|
|
|
if (!coord_advance_left(term, &pos, NULL))
|
2023-10-08 10:28:17 +02:00
|
|
|
return false;
|
2023-09-26 17:54:03 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SEARCH_EXTEND_RIGHT:
|
|
|
|
|
if (!coord_advance_right(term, &pos, NULL))
|
2023-10-08 10:28:17 +02:00
|
|
|
return false;
|
2023-09-26 17:54:03 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2019-12-03 19:22:47 +01:00
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
xassert(pos.row >= 0);
|
|
|
|
|
xassert(pos.row < grid->num_rows);
|
|
|
|
|
xassert(grid->rows[pos.row] != NULL);
|
2019-12-03 19:22:47 +01:00
|
|
|
|
2021-03-28 21:15:39 +02:00
|
|
|
/* Find next word boundary */
|
2023-09-26 17:54:03 +02:00
|
|
|
switch (direction) {
|
|
|
|
|
case SEARCH_EXTEND_LEFT:
|
|
|
|
|
selection_find_word_boundary_left(term, &pos, spaces_only);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SEARCH_EXTEND_RIGHT:
|
|
|
|
|
selection_find_word_boundary_right(term, &pos, spaces_only, false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*target = pos;
|
2023-10-08 10:28:17 +02:00
|
|
|
return true;
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
2021-01-26 20:05:14 +01:00
|
|
|
|
2023-10-08 10:28:17 +02:00
|
|
|
static bool
|
2023-09-26 17:54:03 +02:00
|
|
|
search_extend_find_word_left(const struct terminal *term, bool spaces_only,
|
|
|
|
|
struct coord *target)
|
|
|
|
|
{
|
2023-10-08 10:28:17 +02:00
|
|
|
return search_extend_find_word(term, spaces_only, target, SEARCH_EXTEND_LEFT);
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-08 10:28:17 +02:00
|
|
|
static bool
|
2023-09-26 17:54:03 +02:00
|
|
|
search_extend_find_word_right(const struct terminal *term, bool spaces_only,
|
|
|
|
|
struct coord *target)
|
|
|
|
|
{
|
2023-10-08 10:28:17 +02:00
|
|
|
return search_extend_find_word(term, spaces_only, target, SEARCH_EXTEND_RIGHT);
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-08 10:28:17 +02:00
|
|
|
static bool
|
2023-09-26 17:54:03 +02:00
|
|
|
search_extend_find_line(const struct terminal *term, struct coord *target,
|
|
|
|
|
enum extend_direction direction)
|
|
|
|
|
{
|
2023-09-27 18:36:52 +02:00
|
|
|
if (term->search.match_len == 0)
|
2023-10-08 10:28:17 +02:00
|
|
|
return false;
|
2023-09-27 18:36:52 +02:00
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
struct coord pos = direction == SEARCH_EXTEND_LEFT
|
|
|
|
|
? selection_get_start(term) : selection_get_end(term);
|
|
|
|
|
|
|
|
|
|
xassert(pos.row >= 0);
|
|
|
|
|
xassert(pos.row < term->grid->num_rows);
|
|
|
|
|
|
|
|
|
|
*target = pos;
|
|
|
|
|
|
|
|
|
|
const struct grid *grid = term->grid;
|
|
|
|
|
|
|
|
|
|
switch (direction) {
|
|
|
|
|
case SEARCH_EXTEND_LEFT:
|
|
|
|
|
pos.row = (pos.row - 1 + grid->num_rows) & (grid->num_rows - 1);
|
2023-10-08 10:28:17 +02:00
|
|
|
if (has_wrapped_around_left(term, pos.row))
|
|
|
|
|
return false;
|
2023-09-26 17:54:03 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SEARCH_EXTEND_RIGHT:
|
|
|
|
|
pos.row = (pos.row + 1) & (grid->num_rows - 1);
|
2023-10-08 10:28:17 +02:00
|
|
|
if (has_wrapped_around_right(term, pos.row))
|
|
|
|
|
return false;
|
2023-09-26 17:54:03 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*target = pos;
|
2023-10-08 10:28:17 +02:00
|
|
|
return true;
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-08 10:28:17 +02:00
|
|
|
static bool
|
2023-09-26 17:54:03 +02:00
|
|
|
search_extend_find_line_up(const struct terminal *term, struct coord *target)
|
|
|
|
|
{
|
2023-10-08 10:28:17 +02:00
|
|
|
return search_extend_find_line(term, target, SEARCH_EXTEND_LEFT);
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-08 10:28:17 +02:00
|
|
|
static bool
|
2023-09-26 17:54:03 +02:00
|
|
|
search_extend_find_line_down(const struct terminal *term, struct coord *target)
|
|
|
|
|
{
|
2023-10-08 10:28:17 +02:00
|
|
|
return search_extend_find_line(term, target, SEARCH_EXTEND_RIGHT);
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
search_extend_left(struct terminal *term, const struct coord *target)
|
|
|
|
|
{
|
2023-09-27 18:36:52 +02:00
|
|
|
if (term->search.match_len == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
const struct coord last_coord = selection_get_start(term);
|
|
|
|
|
struct coord pos = *target;
|
|
|
|
|
const struct row *row = term->grid->rows[pos.row];
|
|
|
|
|
|
|
|
|
|
const bool move_cursor = term->search.cursor != 0;
|
|
|
|
|
|
|
|
|
|
struct extraction_context *ctx = extract_begin(SELECTION_NONE, false);
|
|
|
|
|
if (ctx == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
while (pos.col != last_coord.col || pos.row != last_coord.row) {
|
|
|
|
|
if (!extract_one(term, row, &row->cells[pos.col], pos.col, ctx))
|
|
|
|
|
break;
|
|
|
|
|
if (!coord_advance_right(term, &pos, &row))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char32_t *new_text;
|
|
|
|
|
size_t new_len;
|
|
|
|
|
|
|
|
|
|
if (!extract_finish_wide(ctx, &new_text, &new_len))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!search_ensure_size(term, term->search.len + new_len))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
memmove(&term->search.buf[new_len], &term->search.buf[0],
|
|
|
|
|
term->search.len * sizeof(term->search.buf[0]));
|
|
|
|
|
|
|
|
|
|
size_t actually_copied = 0;
|
|
|
|
|
for (size_t i = 0; i < new_len; i++) {
|
|
|
|
|
if (new_text[i] == U'\n') {
|
|
|
|
|
/* extract() adds newlines, which we never match against */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
term->search.buf[actually_copied++] = new_text[i];
|
|
|
|
|
term->search.len++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xassert(actually_copied <= new_len);
|
|
|
|
|
if (actually_copied < new_len) {
|
|
|
|
|
memmove(
|
|
|
|
|
&term->search.buf[actually_copied], &term->search.buf[new_len],
|
|
|
|
|
(term->search.len - actually_copied) * sizeof(term->search.buf[0]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
term->search.buf[term->search.len] = U'\0';
|
|
|
|
|
free(new_text);
|
|
|
|
|
|
|
|
|
|
if (move_cursor)
|
|
|
|
|
term->search.cursor += actually_copied;
|
|
|
|
|
|
|
|
|
|
struct range match = {.start = *target, .end = selection_get_end(term)};
|
|
|
|
|
search_update_selection(term, &match);
|
|
|
|
|
|
|
|
|
|
term->search.match_len = term->search.len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
search_extend_right(struct terminal *term, const struct coord *target)
|
|
|
|
|
{
|
2023-09-27 18:36:52 +02:00
|
|
|
if (term->search.match_len == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
struct coord pos = selection_get_end(term);
|
|
|
|
|
const struct row *row = term->grid->rows[pos.row];
|
|
|
|
|
|
|
|
|
|
const bool move_cursor = term->search.cursor == term->search.len;
|
2019-12-03 19:22:47 +01:00
|
|
|
|
2021-03-30 14:40:21 +02:00
|
|
|
struct extraction_context *ctx = extract_begin(SELECTION_NONE, false);
|
2021-03-28 21:06:21 +02:00
|
|
|
if (ctx == NULL)
|
|
|
|
|
return;
|
2021-01-26 20:26:34 +01:00
|
|
|
|
2021-03-28 21:06:21 +02:00
|
|
|
do {
|
2023-09-26 17:54:03 +02:00
|
|
|
if (!coord_advance_right(term, &pos, &row))
|
2021-03-30 13:49:30 +02:00
|
|
|
break;
|
2021-03-28 21:06:21 +02:00
|
|
|
if (!extract_one(term, row, &row->cells[pos.col], pos.col, ctx))
|
2019-12-03 19:22:47 +01:00
|
|
|
break;
|
2023-09-26 17:54:03 +02:00
|
|
|
} while (pos.col != target->col || pos.row != target->row);
|
2019-12-03 20:26:32 +01:00
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
char32_t *new_text;
|
2021-03-28 21:06:21 +02:00
|
|
|
size_t new_len;
|
2019-12-03 19:22:47 +01:00
|
|
|
|
2021-03-30 14:40:21 +02:00
|
|
|
if (!extract_finish_wide(ctx, &new_text, &new_len))
|
2019-12-03 19:22:47 +01:00
|
|
|
return;
|
|
|
|
|
|
2021-03-28 21:06:21 +02:00
|
|
|
if (!search_ensure_size(term, term->search.len + new_len))
|
2019-12-03 19:22:47 +01:00
|
|
|
return;
|
|
|
|
|
|
2021-03-28 21:11:07 +02:00
|
|
|
for (size_t i = 0; i < new_len; i++) {
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
if (new_text[i] == U'\n') {
|
2021-03-28 21:11:07 +02:00
|
|
|
/* extract() adds newlines, which we never match against */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-28 21:06:21 +02:00
|
|
|
term->search.buf[term->search.len++] = new_text[i];
|
2021-03-28 21:11:07 +02:00
|
|
|
}
|
2019-12-03 19:22:47 +01:00
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
term->search.buf[term->search.len] = U'\0';
|
2021-03-28 21:06:21 +02:00
|
|
|
free(new_text);
|
2019-12-03 19:22:47 +01:00
|
|
|
|
|
|
|
|
if (move_cursor)
|
2021-03-28 21:06:21 +02:00
|
|
|
term->search.cursor = term->search.len;
|
2019-12-03 19:22:47 +01:00
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
struct range match = {.start = term->search.match, .end = *target};
|
2022-04-16 20:23:15 +02:00
|
|
|
search_update_selection(term, &match);
|
2021-03-30 14:40:59 +02:00
|
|
|
term->search.match_len = term->search.len;
|
2019-12-03 19:22:47 +01:00
|
|
|
}
|
2020-07-08 18:20:34 +02:00
|
|
|
|
2019-08-30 19:36:37 +02:00
|
|
|
static size_t
|
|
|
|
|
distance_next_word(const struct terminal *term)
|
|
|
|
|
{
|
|
|
|
|
size_t cursor = term->search.cursor;
|
|
|
|
|
|
|
|
|
|
/* First eat non-whitespace. This is the word we're skipping past */
|
|
|
|
|
while (cursor < term->search.len) {
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
if (isc32space(term->search.buf[cursor++]))
|
2019-08-30 19:36:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
xassert(cursor == term->search.len || isc32space(term->search.buf[cursor - 1]));
|
2019-08-30 19:36:37 +02:00
|
|
|
|
|
|
|
|
/* Now skip past whitespace, so that we end up at the beginning of
|
|
|
|
|
* the next word */
|
|
|
|
|
while (cursor < term->search.len) {
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
if (!isc32space(term->search.buf[cursor++]))
|
2019-08-30 19:36:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
xassert(cursor == term->search.len || !isc32space(term->search.buf[cursor - 1]));
|
2019-08-30 19:36:37 +02:00
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
if (cursor < term->search.len && !isc32space(term->search.buf[cursor]))
|
2019-08-30 19:36:37 +02:00
|
|
|
cursor--;
|
|
|
|
|
|
|
|
|
|
return cursor - term->search.cursor;
|
|
|
|
|
}
|
2020-07-08 18:20:34 +02:00
|
|
|
|
2019-08-30 19:36:37 +02:00
|
|
|
static size_t
|
|
|
|
|
distance_prev_word(const struct terminal *term)
|
|
|
|
|
{
|
|
|
|
|
int cursor = term->search.cursor;
|
|
|
|
|
|
|
|
|
|
/* First, eat whitespace prefix */
|
|
|
|
|
while (cursor > 0) {
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
if (!isc32space(term->search.buf[--cursor]))
|
2019-08-30 19:36:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
xassert(cursor == 0 || !isc32space(term->search.buf[cursor]));
|
2019-08-30 19:36:37 +02:00
|
|
|
|
|
|
|
|
/* Now eat non-whitespace. This is the word we're skipping past */
|
|
|
|
|
while (cursor > 0) {
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
if (isc32space(term->search.buf[--cursor]))
|
2019-08-30 19:36:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
xassert(cursor == 0 || isc32space(term->search.buf[cursor]));
|
|
|
|
|
if (cursor > 0 && isc32space(term->search.buf[cursor]))
|
2019-08-30 19:36:37 +02:00
|
|
|
cursor++;
|
|
|
|
|
|
|
|
|
|
return term->search.cursor - cursor;
|
|
|
|
|
}
|
2020-07-08 18:20:34 +02:00
|
|
|
|
2020-11-01 12:39:57 +01:00
|
|
|
static void
|
|
|
|
|
from_clipboard_cb(char *text, size_t size, void *user)
|
|
|
|
|
{
|
|
|
|
|
struct terminal *term = user;
|
2020-12-05 11:49:32 +01:00
|
|
|
search_add_chars(term, text, size);
|
2020-11-01 12:39:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
from_clipboard_done(void *user)
|
|
|
|
|
{
|
|
|
|
|
struct terminal *term = user;
|
|
|
|
|
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
LOG_DBG("search: buffer: %ls", (const wchar_t *)term->search.buf);
|
2022-04-21 18:54:27 +02:00
|
|
|
search_find_next(term, SEARCH_BACKWARD_SAME_POSITION);
|
2020-11-01 12:39:57 +01:00
|
|
|
render_refresh_search(term);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
static bool
|
2020-07-22 17:51:27 +02:00
|
|
|
execute_binding(struct seat *seat, struct terminal *term,
|
2022-02-08 19:43:00 +01:00
|
|
|
const struct key_binding *binding, uint32_t serial,
|
2022-04-21 18:54:27 +02:00
|
|
|
bool *update_search_result, enum search_direction *direction,
|
|
|
|
|
bool *redraw)
|
2019-08-27 17:23:28 +02:00
|
|
|
{
|
2021-01-24 20:31:22 +01:00
|
|
|
*update_search_result = *redraw = false;
|
2022-02-08 19:43:00 +01:00
|
|
|
const enum bind_action_search action = binding->action;
|
2021-01-24 20:31:22 +01:00
|
|
|
|
2022-04-09 17:28:16 +02:00
|
|
|
struct grid *grid = term->grid;
|
|
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
switch (action) {
|
|
|
|
|
case BIND_ACTION_SEARCH_NONE:
|
|
|
|
|
return false;
|
2020-03-08 15:28:47 +01:00
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
case BIND_ACTION_SEARCH_SCROLLBACK_UP_PAGE:
|
|
|
|
|
if (term->grid == &term->normal) {
|
|
|
|
|
cmd_scrollback_up(term, term->rows);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
|
2023-10-08 10:37:16 +02:00
|
|
|
case BIND_ACTION_SEARCH_SCROLLBACK_UP_HALF_PAGE:
|
|
|
|
|
if (term->grid == &term->normal) {
|
|
|
|
|
cmd_scrollback_up(term, max(term->rows / 2, 1));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_SCROLLBACK_UP_LINE:
|
|
|
|
|
if (term->grid == &term->normal) {
|
|
|
|
|
cmd_scrollback_up(term, 1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
case BIND_ACTION_SEARCH_SCROLLBACK_DOWN_PAGE:
|
|
|
|
|
if (term->grid == &term->normal) {
|
|
|
|
|
cmd_scrollback_down(term, term->rows);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
|
2023-10-08 10:37:16 +02:00
|
|
|
case BIND_ACTION_SEARCH_SCROLLBACK_DOWN_HALF_PAGE:
|
|
|
|
|
if (term->grid == &term->normal) {
|
|
|
|
|
cmd_scrollback_down(term, max(term->rows / 2, 1));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_SCROLLBACK_DOWN_LINE:
|
|
|
|
|
if (term->grid == &term->normal) {
|
|
|
|
|
cmd_scrollback_down(term, 1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_SCROLLBACK_HOME:
|
|
|
|
|
if (term->grid == &term->normal) {
|
|
|
|
|
cmd_scrollback_up(term, term->grid->num_rows);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_SCROLLBACK_END:
|
|
|
|
|
if (term->grid == &term->normal) {
|
|
|
|
|
cmd_scrollback_down(term, term->grid->num_rows);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_CANCEL:
|
2019-08-27 19:33:19 +02:00
|
|
|
if (term->search.view_followed_offset)
|
2022-04-09 17:28:16 +02:00
|
|
|
grid->view = grid->offset;
|
2020-08-12 18:45:35 +02:00
|
|
|
else {
|
2022-04-09 17:28:16 +02:00
|
|
|
grid->view = ensure_view_is_allocated(
|
2020-08-12 18:45:35 +02:00
|
|
|
term, term->search.original_view);
|
|
|
|
|
}
|
2023-05-15 20:34:58 +02:00
|
|
|
term_damage_view(term);
|
2019-08-27 17:23:28 +02:00
|
|
|
search_cancel(term);
|
2020-03-18 15:30:14 +01:00
|
|
|
return true;
|
2019-08-27 19:33:19 +02:00
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_COMMIT:
|
2020-07-22 17:51:27 +02:00
|
|
|
selection_finalize(seat, term, serial);
|
2019-08-29 19:34:41 +02:00
|
|
|
search_cancel_keep_selection(term);
|
2020-03-18 15:30:14 +01:00
|
|
|
return true;
|
2019-08-27 19:33:19 +02:00
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_FIND_PREV:
|
2022-01-27 18:36:28 +01:00
|
|
|
if (term->search.last.buf != NULL && term->search.len == 0) {
|
|
|
|
|
add_wchars(term, term->search.last.buf, term->search.last.len);
|
|
|
|
|
|
|
|
|
|
free(term->search.last.buf);
|
|
|
|
|
term->search.last.buf = NULL;
|
|
|
|
|
term->search.last.len = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 18:54:27 +02:00
|
|
|
*direction = SEARCH_BACKWARD;
|
2021-01-24 20:31:22 +01:00
|
|
|
*update_search_result = *redraw = true;
|
|
|
|
|
return true;
|
2019-08-27 17:23:28 +02:00
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_FIND_NEXT:
|
2022-01-27 18:36:28 +01:00
|
|
|
if (term->search.last.buf != NULL && term->search.len == 0) {
|
|
|
|
|
add_wchars(term, term->search.last.buf, term->search.last.len);
|
|
|
|
|
|
|
|
|
|
free(term->search.last.buf);
|
|
|
|
|
term->search.last.buf = NULL;
|
|
|
|
|
term->search.last.len = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 18:54:27 +02:00
|
|
|
*direction = SEARCH_FORWARD;
|
2021-01-24 20:31:22 +01:00
|
|
|
*update_search_result = *redraw = true;
|
|
|
|
|
return true;
|
2019-08-30 20:15:36 +02:00
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_EDIT_LEFT:
|
2021-01-24 20:31:22 +01:00
|
|
|
if (term->search.cursor > 0) {
|
2019-08-29 21:05:18 +02:00
|
|
|
term->search.cursor--;
|
2021-01-24 20:31:22 +01:00
|
|
|
*redraw = true;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-08-29 21:05:18 +02:00
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_EDIT_LEFT_WORD: {
|
2019-08-30 19:37:18 +02:00
|
|
|
size_t diff = distance_prev_word(term);
|
|
|
|
|
term->search.cursor -= diff;
|
2021-01-16 20:16:00 +00:00
|
|
|
xassert(term->search.cursor <= term->search.len);
|
2021-01-24 20:31:22 +01:00
|
|
|
|
|
|
|
|
if (diff > 0)
|
|
|
|
|
*redraw = true;
|
|
|
|
|
return true;
|
2019-08-30 19:37:18 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_EDIT_RIGHT:
|
2021-01-24 20:31:22 +01:00
|
|
|
if (term->search.cursor < term->search.len) {
|
2019-08-29 21:05:18 +02:00
|
|
|
term->search.cursor++;
|
2021-01-24 20:31:22 +01:00
|
|
|
*redraw = true;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-08-29 21:05:18 +02:00
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_EDIT_RIGHT_WORD: {
|
2019-08-30 19:37:18 +02:00
|
|
|
size_t diff = distance_next_word(term);
|
|
|
|
|
term->search.cursor += diff;
|
2021-01-16 20:16:00 +00:00
|
|
|
xassert(term->search.cursor <= term->search.len);
|
2021-01-24 20:31:22 +01:00
|
|
|
|
|
|
|
|
if (diff > 0)
|
|
|
|
|
*redraw = true;
|
|
|
|
|
return true;
|
2019-08-30 19:37:18 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_EDIT_HOME:
|
2021-01-24 20:31:22 +01:00
|
|
|
if (term->search.cursor != 0) {
|
|
|
|
|
term->search.cursor = 0;
|
|
|
|
|
*redraw = true;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-08-29 21:05:18 +02:00
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_EDIT_END:
|
2021-01-24 20:31:22 +01:00
|
|
|
if (term->search.cursor != term->search.len) {
|
|
|
|
|
term->search.cursor = term->search.len;
|
|
|
|
|
*redraw = true;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-08-29 21:05:18 +02:00
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_DELETE_PREV:
|
2019-08-29 21:05:18 +02:00
|
|
|
if (term->search.cursor > 0) {
|
|
|
|
|
memmove(
|
|
|
|
|
&term->search.buf[term->search.cursor - 1],
|
|
|
|
|
&term->search.buf[term->search.cursor],
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
(term->search.len - term->search.cursor) * sizeof(char32_t));
|
2019-08-29 21:05:18 +02:00
|
|
|
term->search.cursor--;
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
term->search.buf[--term->search.len] = U'\0';
|
2021-01-24 20:31:22 +01:00
|
|
|
*update_search_result = *redraw = true;
|
2019-08-29 21:05:18 +02:00
|
|
|
}
|
2021-01-24 20:31:22 +01:00
|
|
|
return true;
|
2019-08-29 21:05:18 +02:00
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_DELETE_PREV_WORD: {
|
2019-08-30 19:37:06 +02:00
|
|
|
size_t diff = distance_prev_word(term);
|
|
|
|
|
size_t old_cursor = term->search.cursor;
|
|
|
|
|
size_t new_cursor = old_cursor - diff;
|
|
|
|
|
|
2021-01-24 20:31:22 +01:00
|
|
|
if (diff > 0) {
|
|
|
|
|
memmove(&term->search.buf[new_cursor],
|
|
|
|
|
&term->search.buf[old_cursor],
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
(term->search.len - old_cursor) * sizeof(char32_t));
|
2019-08-30 19:37:06 +02:00
|
|
|
|
2021-01-24 20:31:22 +01:00
|
|
|
term->search.len -= diff;
|
|
|
|
|
term->search.cursor = new_cursor;
|
|
|
|
|
*update_search_result = *redraw = true;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-08-29 21:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_DELETE_NEXT:
|
|
|
|
|
if (term->search.cursor < term->search.len) {
|
|
|
|
|
memmove(
|
|
|
|
|
&term->search.buf[term->search.cursor],
|
|
|
|
|
&term->search.buf[term->search.cursor + 1],
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
(term->search.len - term->search.cursor - 1) * sizeof(char32_t));
|
|
|
|
|
term->search.buf[--term->search.len] = U'\0';
|
2021-01-24 20:31:22 +01:00
|
|
|
*update_search_result = *redraw = true;
|
2020-03-18 15:30:14 +01:00
|
|
|
}
|
2021-01-24 20:31:22 +01:00
|
|
|
return true;
|
2020-03-18 15:30:14 +01:00
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_DELETE_NEXT_WORD: {
|
2019-08-30 19:37:06 +02:00
|
|
|
size_t diff = distance_next_word(term);
|
|
|
|
|
size_t cursor = term->search.cursor;
|
|
|
|
|
|
2021-01-24 20:31:22 +01:00
|
|
|
if (diff > 0) {
|
|
|
|
|
memmove(&term->search.buf[cursor],
|
|
|
|
|
&term->search.buf[cursor + diff],
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
(term->search.len - (cursor + diff)) * sizeof(char32_t));
|
2019-08-30 19:37:06 +02:00
|
|
|
|
2021-01-24 20:31:22 +01:00
|
|
|
term->search.len -= diff;
|
|
|
|
|
*update_search_result = *redraw = true;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-08-29 21:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
case BIND_ACTION_SEARCH_EXTEND_CHAR: {
|
|
|
|
|
struct coord target;
|
2023-10-08 10:28:17 +02:00
|
|
|
if (search_extend_find_char_right(term, &target)) {
|
|
|
|
|
search_extend_right(term, &target);
|
|
|
|
|
*update_search_result = false;
|
|
|
|
|
*redraw = true;
|
|
|
|
|
}
|
2023-09-26 17:54:03 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_EXTEND_WORD: {
|
|
|
|
|
struct coord target;
|
2023-10-08 10:28:17 +02:00
|
|
|
if (search_extend_find_word_right(term, false, &target)) {
|
|
|
|
|
search_extend_right(term, &target);
|
|
|
|
|
*update_search_result = false;
|
|
|
|
|
*redraw = true;
|
|
|
|
|
}
|
2023-09-26 17:54:03 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_EXTEND_WORD_WS: {
|
|
|
|
|
struct coord target;
|
2023-10-08 10:28:17 +02:00
|
|
|
if (search_extend_find_word_right(term, true, &target)) {
|
|
|
|
|
search_extend_right(term, &target);
|
|
|
|
|
*update_search_result = false;
|
|
|
|
|
*redraw = true;
|
|
|
|
|
}
|
2023-09-26 17:54:03 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_EXTEND_LINE_DOWN: {
|
|
|
|
|
struct coord target;
|
2023-10-08 10:28:17 +02:00
|
|
|
if (search_extend_find_line_down(term, &target)) {
|
|
|
|
|
search_extend_right(term, &target);
|
|
|
|
|
*update_search_result = false;
|
|
|
|
|
*redraw = true;
|
|
|
|
|
}
|
2023-09-26 17:54:03 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_EXTEND_BACKWARD_CHAR: {
|
|
|
|
|
struct coord target;
|
2023-10-08 10:28:17 +02:00
|
|
|
if (search_extend_find_char_left(term, &target)) {
|
|
|
|
|
search_extend_left(term, &target);
|
|
|
|
|
*update_search_result = false;
|
|
|
|
|
*redraw = true;
|
|
|
|
|
}
|
2021-01-24 20:31:22 +01:00
|
|
|
return true;
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_EXTEND_BACKWARD_WORD: {
|
|
|
|
|
struct coord target;
|
2023-10-08 10:28:17 +02:00
|
|
|
if (search_extend_find_word_left(term, false, &target)) {
|
|
|
|
|
search_extend_left(term, &target);
|
|
|
|
|
*update_search_result = false;
|
|
|
|
|
*redraw = true;
|
|
|
|
|
}
|
2023-09-26 17:54:03 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2019-12-03 19:43:45 +01:00
|
|
|
|
2023-09-26 17:54:03 +02:00
|
|
|
case BIND_ACTION_SEARCH_EXTEND_BACKWARD_WORD_WS: {
|
|
|
|
|
struct coord target;
|
2023-10-08 10:28:17 +02:00
|
|
|
if (search_extend_find_word_left(term, true, &target)) {
|
|
|
|
|
search_extend_left(term, &target);
|
|
|
|
|
*update_search_result = false;
|
|
|
|
|
*redraw = true;
|
|
|
|
|
}
|
2021-01-24 20:31:22 +01:00
|
|
|
return true;
|
2023-09-26 17:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_EXTEND_LINE_UP: {
|
|
|
|
|
struct coord target;
|
2023-10-08 10:28:17 +02:00
|
|
|
if (search_extend_find_line_up(term, &target)) {
|
|
|
|
|
search_extend_left(term, &target);
|
|
|
|
|
*update_search_result = false;
|
|
|
|
|
*redraw = true;
|
|
|
|
|
}
|
2023-09-26 17:54:03 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2019-12-03 19:22:47 +01:00
|
|
|
|
2020-11-01 12:39:57 +01:00
|
|
|
case BIND_ACTION_SEARCH_CLIPBOARD_PASTE:
|
|
|
|
|
text_from_clipboard(
|
|
|
|
|
seat, term, &from_clipboard_cb, &from_clipboard_done, term);
|
2021-01-24 20:31:22 +01:00
|
|
|
*update_search_result = *redraw = true;
|
|
|
|
|
return true;
|
2020-11-01 12:39:57 +01:00
|
|
|
|
|
|
|
|
case BIND_ACTION_SEARCH_PRIMARY_PASTE:
|
|
|
|
|
text_from_primary(
|
|
|
|
|
seat, term, &from_clipboard_cb, &from_clipboard_done, term);
|
2021-01-24 20:31:22 +01:00
|
|
|
*update_search_result = *redraw = true;
|
|
|
|
|
return true;
|
2020-11-01 12:39:57 +01:00
|
|
|
|
2022-07-28 18:09:16 +02:00
|
|
|
case BIND_ACTION_SEARCH_UNICODE_INPUT:
|
unicode-mode: move state from seat to term
This fixes an issue where entering unicode-mode in one foot client,
also enabled unicode-mode on other foot clients. Both
visually (although glitchy), and in effect.
The reason the state was originally in the seat objects, was to fully
support multi-seat. That is, one seat/keyboard entering unicode-mode
should not affect other seats/keyboards.
The issue with this is that seat objects are Wayland global. Thus, in
server mode, all seat objects are shared between the foot clients.
There is a similarity with IME, which also keeps state in the
seat. There's one big difference, however, and that is IME has Wayland
native enter/leave events, that the compositor emits when windows are
focused/unfocused. These events allow us to reset IME state. For our
own Unicode mode, there is nothing similar.
This patch moves the Unicode state from seats, to the terminal
struct. This does mean that if one seat/keyboard enters Unicode mode,
then *all* seats/keyboards will affect the unicode state. This
potential downside is outweighed by the fact that different foot
clients no longer affect each other.
Closes #1717
2024-05-21 07:06:45 +02:00
|
|
|
unicode_mode_activate(term);
|
2022-07-28 18:09:16 +02:00
|
|
|
return true;
|
|
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
case BIND_ACTION_SEARCH_COUNT:
|
2021-02-09 15:16:19 +00:00
|
|
|
BUG("Invalid action type");
|
2021-01-24 20:31:22 +01:00
|
|
|
return true;
|
2020-03-18 15:30:14 +01:00
|
|
|
}
|
2019-08-27 17:23:28 +02:00
|
|
|
|
2021-02-09 15:16:19 +00:00
|
|
|
BUG("Unhandled action type");
|
2020-03-18 15:30:14 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
key-binding: new API, for handling sets of key bindings
Up until now, our Wayland seats have been tracking key bindings. This
makes sense, since the seat’s keymap determines how the key bindings
are resolved.
However, tying bindings to the seat/keymap alone isn’t enough, since
we also depend on the current configuration (i.e. user settings) when
resolving a key binding.
This means configurations that doesn’t match the wayland object’s
configuration, currently don’t resolve key bindings correctly. This
applies to footclients where the user has overridden key bindings on
the command line (e.g. --override key-bindings.foo=bar).
Thus, to correctly resolve key bindings, each set of key bindings must
be tied *both* to a seat/keymap, *and* a configuration.
This patch introduces a key-binding manager, with an API to
add/remove/lookup, and load/unload keymaps from sets of key bindings.
In the API, sets are tied to a seat and terminal instance, since this
makes the most sense (we need to instantiate, or incref a set whenever
a new terminal instance is created). Internally, the set is tied to a
seat and the terminal’s configuration.
Sets are *added* when a new seat is added, and when a new terminal
instance is created. Since there can only be one instance of each
seat, sets are always removed when a seat is removed.
Terminals on the other hand can re-use the same configuration (and
typically do). Thus, sets ref-count the configuration. In other words,
when instantiating a new terminal, we may not have to instantiate a
new set of key bindings, but can often be incref:ed instead.
Whenever the keymap changes on a seat, all key bindings sets
associated with that seat reloads (re-resolves) their key bindings.
Closes #931
2022-04-17 15:39:51 +02:00
|
|
|
search_input(struct seat *seat, struct terminal *term,
|
|
|
|
|
const struct key_binding_set *bindings, uint32_t key,
|
input: rewrite of how we match foot’s own key bindings
Bindings are matched in one out of three ways:
* By translated (by XKB) symbols
* By untranslated symbols
* By raw key codes
A translated symbol is affected by pressed modifiers, some of which
can be “consumed”. Consumed modifiers to not partake in the comparison
with the binding’s modifiers. In this mode, ctrl+shift+2 maps to
ctrl+@ on a US layout.
Untranslated symbols, or un-shifted symbols refer to the “base” symbol
of the pressed key, i.e. it’s unaffected by modifiers. In this mode,
consumed modifiers *do* partake in the comparison with the binding’s
modifiers, and ctrl+shift+2 maps to ctrl+shift+2 on a US layout.
More examples: ctrl+shift+u maps to ctrl+U in the translated lookup,
while ctrl+shift+u maps to ctrl+shift+u in the untranslated lookup.
Finally, we also match raw key codes. This allows our bindings to work
using the same physical keys when the user switches between latin and
non-latin layouts.
This means key bindings in foot.ini *must* not include both +shift+
and a *shifted* key. I.e. ctrl+shift+U is not a valid combo as it
cannot be triggered. Unfortunately, this was how you were supposed to
write bindings up until now... so, we try to detect such bindings, log
a deprecation warning and then “fix” the binding for the user.
When specifying bindings in foot.ini, both ctrl+U and ctrl+shift+u are
valid, and will work. The latter is preferred though, since we cannot
detect the raw key code for the former variant. Personally, I also
prefer the latter one because it is more explicit; it’s more obvious
which keys are involved.
However, in some cases it makes more sense to use the other
variant. Typically for non-letter combos.
2021-02-27 20:42:31 +01:00
|
|
|
xkb_keysym_t sym, xkb_mod_mask_t mods, xkb_mod_mask_t consumed,
|
|
|
|
|
const xkb_keysym_t *raw_syms, size_t raw_count,
|
|
|
|
|
uint32_t serial)
|
2020-03-18 15:30:14 +01:00
|
|
|
{
|
2022-04-18 14:57:13 +02:00
|
|
|
LOG_DBG("search: input: sym=%d/0x%x, mods=0x%08x, consumed=0x%08x",
|
|
|
|
|
sym, sym, mods, consumed);
|
2020-03-18 15:30:14 +01:00
|
|
|
|
2021-06-16 17:44:14 +02:00
|
|
|
enum xkb_compose_status compose_status = seat->kbd.xkb_compose_state != NULL
|
|
|
|
|
? xkb_compose_state_get_status(seat->kbd.xkb_compose_state)
|
|
|
|
|
: XKB_COMPOSE_NOTHING;
|
2019-08-27 17:23:28 +02:00
|
|
|
|
2022-04-21 18:54:27 +02:00
|
|
|
enum search_direction search_direction = SEARCH_BACKWARD_SAME_POSITION;
|
2021-01-24 20:31:22 +01:00
|
|
|
bool update_search_result = false;
|
|
|
|
|
bool redraw = false;
|
|
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
/* Key bindings */
|
key-binding: new API, for handling sets of key bindings
Up until now, our Wayland seats have been tracking key bindings. This
makes sense, since the seat’s keymap determines how the key bindings
are resolved.
However, tying bindings to the seat/keymap alone isn’t enough, since
we also depend on the current configuration (i.e. user settings) when
resolving a key binding.
This means configurations that doesn’t match the wayland object’s
configuration, currently don’t resolve key bindings correctly. This
applies to footclients where the user has overridden key bindings on
the command line (e.g. --override key-bindings.foo=bar).
Thus, to correctly resolve key bindings, each set of key bindings must
be tied *both* to a seat/keymap, *and* a configuration.
This patch introduces a key-binding manager, with an API to
add/remove/lookup, and load/unload keymaps from sets of key bindings.
In the API, sets are tied to a seat and terminal instance, since this
makes the most sense (we need to instantiate, or incref a set whenever
a new terminal instance is created). Internally, the set is tied to a
seat and the terminal’s configuration.
Sets are *added* when a new seat is added, and when a new terminal
instance is created. Since there can only be one instance of each
seat, sets are always removed when a seat is removed.
Terminals on the other hand can re-use the same configuration (and
typically do). Thus, sets ref-count the configuration. In other words,
when instantiating a new terminal, we may not have to instantiate a
new set of key bindings, but can often be incref:ed instead.
Whenever the keymap changes on a seat, all key bindings sets
associated with that seat reloads (re-resolves) their key bindings.
Closes #931
2022-04-17 15:39:51 +02:00
|
|
|
tll_foreach(bindings->search, it) {
|
input: rewrite of how we match foot’s own key bindings
Bindings are matched in one out of three ways:
* By translated (by XKB) symbols
* By untranslated symbols
* By raw key codes
A translated symbol is affected by pressed modifiers, some of which
can be “consumed”. Consumed modifiers to not partake in the comparison
with the binding’s modifiers. In this mode, ctrl+shift+2 maps to
ctrl+@ on a US layout.
Untranslated symbols, or un-shifted symbols refer to the “base” symbol
of the pressed key, i.e. it’s unaffected by modifiers. In this mode,
consumed modifiers *do* partake in the comparison with the binding’s
modifiers, and ctrl+shift+2 maps to ctrl+shift+2 on a US layout.
More examples: ctrl+shift+u maps to ctrl+U in the translated lookup,
while ctrl+shift+u maps to ctrl+shift+u in the untranslated lookup.
Finally, we also match raw key codes. This allows our bindings to work
using the same physical keys when the user switches between latin and
non-latin layouts.
This means key bindings in foot.ini *must* not include both +shift+
and a *shifted* key. I.e. ctrl+shift+U is not a valid combo as it
cannot be triggered. Unfortunately, this was how you were supposed to
write bindings up until now... so, we try to detect such bindings, log
a deprecation warning and then “fix” the binding for the user.
When specifying bindings in foot.ini, both ctrl+U and ctrl+shift+u are
valid, and will work. The latter is preferred though, since we cannot
detect the raw key code for the former variant. Personally, I also
prefer the latter one because it is more explicit; it’s more obvious
which keys are involved.
However, in some cases it makes more sense to use the other
variant. Typically for non-letter combos.
2021-02-27 20:42:31 +01:00
|
|
|
const struct key_binding *bind = &it->item;
|
|
|
|
|
|
|
|
|
|
/* Match translated symbol */
|
2022-02-07 19:41:33 +01:00
|
|
|
if (bind->k.sym == sym &&
|
2024-02-06 10:41:01 +01:00
|
|
|
bind->mods == (mods & ~consumed)) {
|
2019-08-27 17:23:28 +02:00
|
|
|
|
2022-02-08 19:43:00 +01:00
|
|
|
if (execute_binding(seat, term, bind, serial,
|
2022-04-21 18:54:27 +02:00
|
|
|
&update_search_result, &search_direction,
|
|
|
|
|
&redraw))
|
2021-01-24 20:31:22 +01:00
|
|
|
{
|
2020-03-18 15:30:14 +01:00
|
|
|
goto update_search;
|
2021-01-24 20:31:22 +01:00
|
|
|
}
|
2019-08-27 17:23:28 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 10:41:01 +01:00
|
|
|
if (bind->mods != mods)
|
input: rewrite of how we match foot’s own key bindings
Bindings are matched in one out of three ways:
* By translated (by XKB) symbols
* By untranslated symbols
* By raw key codes
A translated symbol is affected by pressed modifiers, some of which
can be “consumed”. Consumed modifiers to not partake in the comparison
with the binding’s modifiers. In this mode, ctrl+shift+2 maps to
ctrl+@ on a US layout.
Untranslated symbols, or un-shifted symbols refer to the “base” symbol
of the pressed key, i.e. it’s unaffected by modifiers. In this mode,
consumed modifiers *do* partake in the comparison with the binding’s
modifiers, and ctrl+shift+2 maps to ctrl+shift+2 on a US layout.
More examples: ctrl+shift+u maps to ctrl+U in the translated lookup,
while ctrl+shift+u maps to ctrl+shift+u in the untranslated lookup.
Finally, we also match raw key codes. This allows our bindings to work
using the same physical keys when the user switches between latin and
non-latin layouts.
This means key bindings in foot.ini *must* not include both +shift+
and a *shifted* key. I.e. ctrl+shift+U is not a valid combo as it
cannot be triggered. Unfortunately, this was how you were supposed to
write bindings up until now... so, we try to detect such bindings, log
a deprecation warning and then “fix” the binding for the user.
When specifying bindings in foot.ini, both ctrl+U and ctrl+shift+u are
valid, and will work. The latter is preferred though, since we cannot
detect the raw key code for the former variant. Personally, I also
prefer the latter one because it is more explicit; it’s more obvious
which keys are involved.
However, in some cases it makes more sense to use the other
variant. Typically for non-letter combos.
2021-02-27 20:42:31 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Match untranslated symbols */
|
|
|
|
|
for (size_t i = 0; i < raw_count; i++) {
|
2022-02-07 19:41:33 +01:00
|
|
|
if (bind->k.sym == raw_syms[i]) {
|
2022-02-08 19:43:00 +01:00
|
|
|
if (execute_binding(seat, term, bind, serial,
|
2022-04-21 18:54:27 +02:00
|
|
|
&update_search_result, &search_direction,
|
|
|
|
|
&redraw))
|
input: rewrite of how we match foot’s own key bindings
Bindings are matched in one out of three ways:
* By translated (by XKB) symbols
* By untranslated symbols
* By raw key codes
A translated symbol is affected by pressed modifiers, some of which
can be “consumed”. Consumed modifiers to not partake in the comparison
with the binding’s modifiers. In this mode, ctrl+shift+2 maps to
ctrl+@ on a US layout.
Untranslated symbols, or un-shifted symbols refer to the “base” symbol
of the pressed key, i.e. it’s unaffected by modifiers. In this mode,
consumed modifiers *do* partake in the comparison with the binding’s
modifiers, and ctrl+shift+2 maps to ctrl+shift+2 on a US layout.
More examples: ctrl+shift+u maps to ctrl+U in the translated lookup,
while ctrl+shift+u maps to ctrl+shift+u in the untranslated lookup.
Finally, we also match raw key codes. This allows our bindings to work
using the same physical keys when the user switches between latin and
non-latin layouts.
This means key bindings in foot.ini *must* not include both +shift+
and a *shifted* key. I.e. ctrl+shift+U is not a valid combo as it
cannot be triggered. Unfortunately, this was how you were supposed to
write bindings up until now... so, we try to detect such bindings, log
a deprecation warning and then “fix” the binding for the user.
When specifying bindings in foot.ini, both ctrl+U and ctrl+shift+u are
valid, and will work. The latter is preferred though, since we cannot
detect the raw key code for the former variant. Personally, I also
prefer the latter one because it is more explicit; it’s more obvious
which keys are involved.
However, in some cases it makes more sense to use the other
variant. Typically for non-letter combos.
2021-02-27 20:42:31 +01:00
|
|
|
{
|
|
|
|
|
goto update_search;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
/* Match raw key code */
|
2022-02-07 19:41:33 +01:00
|
|
|
tll_foreach(bind->k.key_codes, code) {
|
2020-03-18 15:30:14 +01:00
|
|
|
if (code->item == key) {
|
2022-02-08 19:43:00 +01:00
|
|
|
if (execute_binding(seat, term, bind, serial,
|
2022-04-21 18:54:27 +02:00
|
|
|
&update_search_result, &search_direction,
|
|
|
|
|
&redraw))
|
2021-01-24 20:31:22 +01:00
|
|
|
{
|
2020-03-18 15:30:14 +01:00
|
|
|
goto update_search;
|
2021-01-24 20:31:22 +01:00
|
|
|
}
|
2020-03-18 15:30:14 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-27 17:23:28 +02:00
|
|
|
|
2020-08-23 07:42:20 +02:00
|
|
|
uint8_t buf[64] = {0};
|
2020-03-18 15:30:14 +01:00
|
|
|
int count = 0;
|
2019-08-27 17:23:28 +02:00
|
|
|
|
2020-03-18 15:30:14 +01:00
|
|
|
if (compose_status == XKB_COMPOSE_COMPOSED) {
|
|
|
|
|
count = xkb_compose_state_get_utf8(
|
2020-07-08 18:20:34 +02:00
|
|
|
seat->kbd.xkb_compose_state, (char *)buf, sizeof(buf));
|
|
|
|
|
xkb_compose_state_reset(seat->kbd.xkb_compose_state);
|
2020-03-18 15:30:14 +01:00
|
|
|
} else if (compose_status == XKB_COMPOSE_CANCELLED) {
|
|
|
|
|
count = 0;
|
|
|
|
|
} else {
|
|
|
|
|
count = xkb_state_key_get_utf8(
|
2020-07-08 18:20:34 +02:00
|
|
|
seat->kbd.xkb_state, key, (char *)buf, sizeof(buf));
|
2020-03-18 15:30:14 +01:00
|
|
|
}
|
2019-08-29 21:03:46 +02:00
|
|
|
|
2021-01-24 20:31:22 +01:00
|
|
|
update_search_result = redraw = count > 0;
|
2022-04-21 18:54:27 +02:00
|
|
|
search_direction = SEARCH_BACKWARD_SAME_POSITION;
|
2021-01-24 20:31:22 +01:00
|
|
|
|
2020-08-12 18:47:54 +02:00
|
|
|
if (count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-12-05 11:49:32 +01:00
|
|
|
search_add_chars(term, (const char *)buf, count);
|
2020-03-18 15:30:14 +01:00
|
|
|
|
|
|
|
|
update_search:
|
fcft: adapt to API changes in fcft-3.x
Fcft no longer uses wchar_t, but plain uint32_t to represent
codepoints.
Since we do a fair amount of string operations in foot, it still makes
sense to use something that actually _is_ a string (or character),
rather than an array of uint32_t.
For this reason, we switch out all wchar_t usage in foot to
char32_t. We also verify, at compile-time, that char32_t used
UTF-32 (which is what fcft expects).
Unfortunately, there are no string functions for char32_t. To avoid
having to re-implement all wcs*() functions, we add a small wrapper
layer of c32*() functions.
These wrapper functions take char32_t arguments, but then simply call
the corresponding wcs*() function.
For this to work, wcs*() must _also_ be UTF-32 compatible. We can
check for the presence of the __STDC_ISO_10646__ macro. If set,
wchar_t is at least 4 bytes and its internal representation is UTF-32.
FreeBSD does *not* define this macro, because its internal wchar_t
representation depends on the current locale. It _does_ use UTF-32
_if_ the current locale is UTF-8.
Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is
defined.
Other fcft API changes:
* fcft_glyph_rasterize() -> fcft_codepoint_rasterize()
* font.space_advance has been removed
* ‘tags’ have been removed from fcft_grapheme_rasterize()
* ‘fcft_log_init()’ removed
* ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2021-08-21 14:50:42 +02:00
|
|
|
LOG_DBG("search: buffer: %ls", (const wchar_t *)term->search.buf);
|
2021-01-24 20:31:22 +01:00
|
|
|
if (update_search_result)
|
2022-04-21 18:54:27 +02:00
|
|
|
search_find_next(term, search_direction);
|
2021-01-24 20:31:22 +01:00
|
|
|
if (redraw)
|
|
|
|
|
render_refresh_search(term);
|
2019-08-27 17:23:28 +02:00
|
|
|
}
|