aboutsummaryrefslogtreecommitdiff
path: root/search.c (follow)
Commit message (Collapse)AuthorAgeLines
* config: add search-bindings.delete-to-{start,end} key bindingsAdrian fxj9a2025-03-05-0/+23
| | | | | | Defaults to ctrl+u and ctrl+k respectively. Closes #1972
* input: match unshifted key-bindings before shiftedDaniel Eklöf2025-01-31-17/+17
| | | | | | | | | | | | | | | | | | | | That is, try to match e.g. Control+shift+a, before trying to match Control+A. In most cases, order doesn't matter. There are however a couple of symbols where the layout consumes the shift-modifier, and the generated symbol is the same in both the shifted and unshifted form. One such example is backspace. Before this patch, key-bindings with shift-backspace would be ignored, if there were another key-binding with backspace. So, for example, if we had one key-binding with Control+Backspace, and another with Control+Shift+Backspace, the latter would never trigger, as we would always match the first one. By checking for unshifted matches first, we ensure Control+Shift+Backspace does match.
* input: ignore key-bindings without modifiers when matching untranslated/rawDaniel Eklöf2025-01-31-2/+2
| | | | | | | | | When matching the unshifted symbol, or the raw key code, ignore all key bindings that don't have any modifiers. This fixes an issue where it was impossible to enter (some of the) numbers on the keypad, **if** there was a key-binding for e.g. KP_Page_Up, or KP_Page_Down.
* key-bindings: try all bindings in translated mode before matching untranslated, and then finally rawDaniel Eklöf2025-01-27-4/+18
| | | | | | | | | | | | | | | | | | | When trying to match key bindings, we do three types of matching: * Match the _translated_ symbol (e.g. Control+C) * Match the _untranslated_ symbol (e.g. Control+Shift+c) * Match raw keyboard codes This was done for *each* key binding. This meant we sometimes matched a keybinding in raw mode, even though there was a translated/untranslated binding that would match it too. All depending on the internal order of the key binding list. This patch changes it, so that we first try all bindings in translated mode, then all bindings in untranslated mode, and finally all bindings in raw mode. Closes #1929
* unicode-mode: move state from seat to termDaniel Eklöf2024-05-21-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* input: remove the concept of "significant" modifiersDaniel Eklöf2024-02-06-7/+2
| | | | | | | | | | | | | | | | | | | For the purpose of matching key bindings, "significant" modifiers are no more. We're really only interested in filtering out "locked" modifiers. We're already doing this, so there's no need to *also* match against a set of "significant" modifiers. Furthermore, we *never* want to consider locked keys (e.g. when emitting escapes to the client application), thus we can filter those out already when retrieving the set of active modifiers. The exception is the kitty keyboard protocol, which has support for CapsLock and NumLock. Since we're already re-retrieving the "consumed" modifiers (using the GTK style, rather than normal "XKB" style, to better match the kitty terminal), we might as well re-retrieve the effective modifiers as well.
* config: add remaining search.scrollback key bindingsDaniel Eklöf2023-10-08-0/+42
| | | | All scrollback up/down key bindings are now available in search mode.
* search: fix mixup in search_extend_find_line()Daniel Eklöf2023-10-08-59/+69
| | | | | | | | | The has_wrapped_around_{right,left} functions were mixed up, causing false positives and false negatives, resulting in bad search matches. Also make all search_extend_find* functions return a boolean; false means no change in the selection. In this case, we can skip trying to extend the selection, and updating the UI.
* search: don't try to extend a search match when there is noneDaniel Eklöf2023-10-08-1/+16
|
* search: add more key bindings to extend the current matchDaniel Eklöf2023-10-08-57/+356
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds the following new search key bindings: * extend-char (shift+right) * extend-line-down (shift+down) * extend-backward-char (shift+left) * extend-backward-to-word-boundary (ctrl+shift+left) * extend-backward-to-next-whitespace (ctrl+shift+alt+left) * extend-line-up (shift+up) They can be used to extend the search match (i.e. the selection). This patch also adds an initial set of key bindings to scroll in the scrollback history: * scrollback-up-page * scrollback-down-page These work just like the key bindings for the normal mode. Also note that it was already possible to scroll using the mouse. This patch also fixes a couple of search mode bugs: * crashing when a search match ends in the last column * grapheme clusters not being matched correctly * Search match not being "extendable" after a pointer leave event * A few others, related to either large matches, or extending matches after moving the viewport. There are still a couple of (known) issues: * A search match isn't correctly highlighted if its *starting* point is outside the viewport. * Extending the match to end of the scrollback (i.e. the most recent output) is simply buggy. Related to #419
* search: regression: refresh current view when canceling a scrollback searchDaniel Eklöf2023-05-15-0/+1
| | | | | | | | | | | | | | | | | | | | 3b41379be43a21a00a776d0d136c5d1b2fe4007e introduced a regression, where canceling a scrollback search didn’t refresh the viewport correctly; the viewport was changed, but the screen content was not refreshed. This worked before, because the workaround for https://github.com/swaywm/sway/issues/6960 always called term_damage_view() when exiting scrollback search mode. 3b41379be43a21a00a776d0d136c5d1b2fe4007e removed that call since it’s no longer required. *Except* when executing the BIND_ACTION_SEARCH_CANCEL binding, since then the viewport may be moved. Note that this regression affected *all* compositors, not just Sway. Closes #1354
* quirks: sway does not damage surface beneath sub-surface, when unmappedDaniel Eklöf2023-05-12-5/+1
| | | | | | | | | | | | | | | | | | | | | When unmapping a sub-surface, Sway <= 1.8 does not damage the surface beneath the sub-surface. https://github.com/swaywm/sway/issues/6960 The workaround is to manually damage the main surface. Previously, this was done when exiting scrollback search, and after the ‘flash’ OSC. But other sub-surfaces, that may also be unmapped, did not. This patch adds a quirk handler that does this, and calls it when: * Exiting scrollback search * Ending the ‘flash’ OSC * Exiting unicode input mode * Clearing URL labels * Removing the scrollback position indicator Closes #1335
* input: add new Unicode input modeDaniel Eklöf2022-07-29-0/+5
| | | | | | | | | | | | | | This mode is activated through the new key-bindings.unicode-input and search-bindings.unicode-input key bindings. When active, the user can “build” a Unicode codepoint by typing its hexadecimal value. Note that there’s no visual feedback in this mode. This is intentional. This mode is intended to be a fallback for users that don’t use an IME. Closes #1116
* search: find_next(): handle trailing SPACER cellsDaniel Eklöf2022-07-28-0/+3
| | | | | | | | Make sure to increment match_end_col to account for trailing SPACER cells after a match. This fixes an issue where search matches weren’t highlighted correctly when the match *ends* with a double-width character.
* selection: find_word_boundary_right: add “stop-on-space-to-word-boundary”Daniel Eklöf2022-04-27-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When true, selection_find_word_boundary_right() behaves as before - it stops as soon as it encounters a character that isn’t of the same *type* as the “initial” character (the last character in the selection). Take this, for example: The Quick Brown Fox The selection will first stop at the end of “the”, then just *before* “quick”, then at the end of “quick”. Then just *before* “brown”, and then at the end of “brown”, and so on. This suits mouse selections pretty good. But when selection_find_word_boundary_right() is used to extend a search match, it’s better to ignore space-to-word character transitions. That is, we want The Quick Brown Fox to first extend to the end of “the”, then immediately to the end of “quick”, then to the end of “brown”, and so on. Setting the ‘stop_to_space_to_word_boundary’ argument to false results in latter behavior. This is now done by search, when executing the “extend-to-word-boundary” and “extend-to-next-whitespace” key bindings.
* search: fix infinite loop when highlighting all matchesDaniel Eklöf2022-04-26-0/+13
| | | | | | | | | | | | | | | find_next() did not always terminate correctly, causing search_matches_next() to never terminate, which finally leads to an infinite loop when rendering the search overlay surface, while finding all matches to highlight. The problem is that find_next(), after having found the initial matching characters, enters a nested while loop that tries to match the rest of the search criteria. This inner while loop did not check if we’ve reached the last cell, and happily continued past it (eventually wrappping around the scrollback buffer). Closes #1047
* search: assert that the match is *inside* the new viewportDaniel Eklöf2022-04-26-0/+9
|
* search: regression: crash when moving viewportDaniel Eklöf2022-04-26-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | 5c4ddebc3c57724bd89b959a33f5ad0bd97f482b refactored search_update_selection(), specifically, the logic that moves the viewport. It did so by converting the absolute row number (of the match) to scrollback relative coordinates. This way we could ensure the viewport wasn’t moved “too much” (e.g. beyond the scrollback start). However, grid_row_abs_to_sb() and grid_row_sb_to_abs() doesn’t take a partially filled scrollback into account. This means the row (numbers) it returns may refer to *uninitialized* rows. Since: * The match row itself is valid (we *know* it has text on it) * We *subtract* from it, when setting the new viewport (to center the match on the screen). it’s only the *upper* part of the new viewport that may be uninitialized. I.e. we may have adjusted it too much. So, what we need to do is move the viewport forward until its *first* row is initialized. Then we know the rest will be too.
* search: work around Sway sub-surface unmap bugDaniel Eklöf2022-04-26-1/+5
| | | | | | | | | | | | | | | | | | Unmapping a sub-surface in Sway does not damage the underlying surface. As a result, "committing" a scrollback search will typically leave most of the foot window dimmed. It can be seen when "cancelling" a search as well, but there it's less obvious - only the margins are left dimmed. This is because cancelling a search damaged the current viewport (something that shouldn't be needed). Out of sway, river, weston and mutter, only Sway needs this workaround. This is a workaround for https://github.com/swaywm/sway/issues/6960
* search: fix multiple crashesDaniel Eklöf2022-04-25-108/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* search: matches_next: assert start’s ‘col’ is validDaniel Eklöf2022-04-24-0/+2
|
* search: matches_next: stop searching when start.row >= term->rowsDaniel Eklöf2022-04-24-1/+10
| | | | | | | | | As this means the last call to sarch_matches_next() found a match at the bottom of the view, and then set the iter’s *next* start position to a row outside the view. This is fine, but we need to handle it, by immediately stopping the iter.
* search: matches_next: don’t wrap around grid->num_rowsDaniel Eklöf2022-04-24-2/+6
| | | | | | | | | | | When bumping the iter’s start.row, we’re working with view-local coordinates. That is, 0 >= row < term->rows. This means it is wrong to and with grid->num_rows - 1, because a), ‘row’ should **never** be that big. And b), if we do, we’ll just end up in an infinite loop, where the next call to matches_next() just starts over from the beginning again (and eventually hitting the exact same place that got us started).
* search: maches_next: assert match coordinates are validDaniel Eklöf2022-04-24-0/+9
| | | | | * They are within range (i.e. ‘row’ does not exceed term->rows-1) * ‘end’ comes after ‘start’
* search: fix debug logDaniel Eklöf2022-04-24-1/+2
| | | | | This has been broken since the forward/backward search logic was refactored.
* search: don't modify search.start coord *before* finding next matchDaniel Eklöf2022-04-21-53/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The match logic uses the last start coordinate to determine which end points in the selection to update. This sometimes fails when the start coordinate has been changed by e.g. a key binding - the new start coordinate is incorrectly matched against the old-but-modified start coordinate, causing foot to e.g. *not* upate the selection start coordinate. Example: $ echo 'test\n\test\ntest' Then do a scrollback search for 'test. The first match is found correctly (the last 'test'), but searching for the previous match (ctrl+r) does not select the middle 'test'. Fix by passing the search direction to search_find_next(), and have _it_ calculate the coordinate to start search. There are three possibilities: * forward * backward * "backward", but at the same position The first two are used when searching for next/prev match with ctrl+s and ctrl+r. The last one is used when the search criteria is updated. In this case, we don't want to move to the previous match, *unless* the current match no longer matches.
* search: add comment to ‘advance_pos()’ macroDaniel Eklöf2022-04-18-0/+2
|
* search: codespell: backards -> backwardsDaniel Eklöf2022-04-18-1/+1
|
* search: rename ‘newline’ -> ‘advance_pos’ macro, reverse return valueDaniel Eklöf2022-04-18-7/+7
|
* search: input: log consumed modifiersDaniel Eklöf2022-04-18-1/+2
|
* search: match iterator: wrap iterator’s row number, when neededDaniel Eklöf2022-04-18-0/+6
|
* search: find_next(): assert start/end coords are validDaniel Eklöf2022-04-18-0/+10
|
* search: find_next(): stop at the exact cell position specified by ‘end’Daniel Eklöf2022-04-18-22/+27
| | | | And not just when reaching end’s row.
* search: find_next(): prefix {start,end}_{row_col} with ‘match’Daniel Eklöf2022-04-18-21/+23
|
* search: find_next(): pass an ‘end’ coord, instead of a row countDaniel Eklöf2022-04-18-5/+31
|
* search: refactor: find_next(): pass start as a ‘coord’ structDaniel Eklöf2022-04-18-17/+16
|
* search: search_update_selection() no longer expects end coordinate to be exclusiveDaniel Eklöf2022-04-17-3/+0
|
* search: match iterator: handle overlapping matchesDaniel Eklöf2022-04-17-2/+2
|
* search: match iterator: always return the primary matchDaniel Eklöf2022-04-17-17/+36
| | | | | | | Normally, the primary match is automatically included by the iterator, but if the secondary and primary matches overlap, it is possible we don’t return the _actual_ primary match. This lead to highlighting issues, where part of the primary match wasn’t highlighted correctly.
* search: fix next/prev not updating selection correctly when matches overlapDaniel Eklöf2022-04-17-2/+8
| | | | | When the new match overlapped with the old match, the selection wasn’t updated correctly.
* key-binding: new API, for handling sets of key bindingsDaniel Eklöf2022-04-17-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* search: refactor: search_update_selection() takes a ‘struct range’Daniel Eklöf2022-04-16-19/+18
|
* search: break out “find next match” logic to a new functionDaniel Eklöf2022-04-16-112/+99
|
* search/render: initial support for highlighting all visible matchesDaniel Eklöf2022-04-16-0/+84
| | | | | | | | | | | | | | | | | 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.
* wayland: optionally disable pointer input on subsurfacesDaniel Eklöf2022-04-16-1/+2
| | | | | | | | | | | | | | | | We have a number of sub-surfaces for which we are *not* interrested in pointer (or touch) input. Up until now, we’ve manually dealt with these, by recognizing these surfaces in all pointer events, and ignoring them. But, lo and behold, there are better ways of doing this. By clearing the subsurface’s input region, the compositor will do this for us - when a pointer is outside a surface’s input region, the event is passed to the next surface underneath it. This is exactly what we want! Do this for all subsurfaces, *except* the CSDs.
* search: use a local ‘grid’ variable to hold term->gridDaniel Eklöf2022-04-09-52/+60
|
* refactor: add a ‘range’ struct, grouping a start and end coord togetherDaniel Eklöf2022-04-09-2/+2
|
* input: don’t allow non-significant modifiers when matching untranslated symbolsDaniel Eklöf2022-03-20-2/+7
| | | | | | | | | | | | | | | | | | When matching “untranslated” bindings (by matching the base symbol of the key, e.g. ctrl+shift+2 in US layout), require that no non-significant modifiers are active. This fixes an issue where AltGr was “ignored”, and would cause certain combinations to match a key binding. Example: ctrl+altgr+0, on many European layouts matched against the default ctrl+0 (reset the font size), instead of emitting ^] To make this work, we now need to filter out “locked” modifiers (e.g. NumLock and CapsLock). Otherwise having e.g. NumLock active would prevent *all* untranslated matching to fail. Closes #983
* input/search/url: pass pointer-to key-binding struct to execute()Daniel Eklöf2022-02-09-4/+5
|
* wayland: unify key- and mouse-binding structsDaniel Eklöf2022-02-09-3/+3
|
* fcft: adapt to API changes in fcft-3.xDaniel Eklöf2022-02-05-44/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* search: remember last searched-for string between searchesDaniel Eklöf2022-01-29-5/+27
| | | | | | | | | Regardless of how we exit search mode (commit or cancel), the search string is remembered. The next time we enter search mode, the last searched-for string will be used when searching for the next/prev match (ctrl+r, ctrl+s), and the search query is empty.
* search: refactor: add add_wchars(), make search_add_chars() use itDaniel Eklöf2022-01-29-23/+28
| | | | | | | | search_add_chars() converts the incoming UTF-8 string into a wide-char string, and then calls add_wchars(). add_wchars() inserts the string into the search buffer, at the current cursor position.
* search: redraw search box after selection has been cancelledDaniel Eklöf2021-07-22-0/+1
|
* search: reset match state when selection is cancelledDaniel Eklöf2021-07-22-0/+7
| | | | | | | | | | | | While we’re in scrollback search mode, the selection may be cancelled (for example, if the application is scrolling out the selected text). Trying to e.g. extend the search selection after this has happened triggered a crash. This fixes it by simply resetting the search match state when the selection is cancelled. Closes #644
* composed: store compose chains in a binary search treeDaniel Eklöf2021-06-24-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* wip: grapheme shapingDaniel Eklöf2021-06-24-3/+3
|
* search: don’t crash when we don’t have any XKB compose stateDaniel Eklöf2021-06-16-2/+3
|
* search: match_to_end_of_word(): we update the selection ourselvesDaniel Eklöf2021-05-17-2/+8
| | | | | | No need to call search_find_next() after doing a search_match_to_end_of_word(), since we already *know* we have a match, and where it is.
* extract: move ‘strip_trailing_empty’ parameter from extra_finish() to extract_begin()Daniel Eklöf2021-05-17-2/+2
|
* search: find_next(): correctly wrap row numberDaniel Eklöf2021-05-17-1/+1
|
* search: match_to_end_of_word(): use a local macro to bump coordDaniel Eklöf2021-05-17-15/+21
|
* search: match_to_end_of_word(): use has_wrapped_around() while extracting textDaniel Eklöf2021-05-17-1/+3
|
* search: match_to_end_of_word(): we always extend the selection with at least one characterDaniel Eklöf2021-05-17-3/+1
|
* search: match_to_end_of_word(): skip newlines when copying from extraction bufferDaniel Eklöf2021-05-17-1/+7
|
* search: match_to_end_of_word(): refactorDaniel Eklöf2021-05-17-61/+40
| | | | | | | | | | | | | | | Rewrite match_to_end_of_word() in terms of * selection_find_word_boundary_right() * extract_begin() + extract_one() + extract_finish() This adds a small overhead, in that extract_*() allocates an internal buffer, from which we then immediately copy, into our newly resized prompt buffer. On the other hand, this makes the matching behavior more consistent with regular mouse selections, and we don’t have to keep two very similar match-to-next-word-boundary implementations in sync.
* search: find_next(): proper check for scrollback wrap aroundDaniel Eklöf2021-05-17-5/+14
| | | | | | Besides disallowing matches that crosses the scrollback wrap-around, this also fixes a crash when the trying to search beyond the last output, when the scrollback history hasn’t yet been completely filled.
* term: rename CELL_MULT_COL_SPACER -> CELL_SPACER, and change its definitionDaniel Eklöf2021-05-14-2/+2
| | | | | | | | | | | | | | | | | | | | | Instead of using CELL_SPACER for *all* cells that previously used CELL_MULT_COL_SPACER, include the remaining number of spacers following, and including, itself. This is encoded by adding to the CELL_SPACER value. So, a double width character will now store the character itself in the first cell (just like before), and CELL_SPACER+1 in the second cell. A three-cell character would store the character itself, then CELL_SPACER+2, and finally CELL_SPACER+1. In other words, the last spacer is always CELL_SPACER+1. CELL_SPACER+0 is used when padding at the right margin. I.e. when writing e.g. a double width character in the last column, we insert a CELL_SPACER+0 pad character, and then write the double width character in the first column on the next row.
* search: when matching cell content, treat empty cells as spacesDaniel Eklöf2021-03-28-0/+3
|
* input: rewrite of how we match foot’s own key bindingsDaniel Eklöf2021-03-04-8/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* wayland: drop ‘_surface’ suffix from subsurface struct instancesDaniel Eklöf2021-02-17-3/+2
|
* search: use wayl_win_subsurface_new/destroy()Daniel Eklöf2021-02-17-15/+4
|
* Convert some more uses of xassert(false) to BUG("...")Craig Barnes2021-02-09-2/+2
|
* key-bindings: refactor: use a single type for all key bindingsDaniel Eklöf2021-02-08-3/+3
| | | | | | | | | | | | | | | | Up until now, the various key binding modes (“normal”, “search” and “url”) have used their own struct definitions for their key bindings. The only reason for this was to have a properly typed “action” (using the appropriate “action” enum). This caused lots of duplicated code. This patch refactors this to use a single struct definition for the “unparsed” key bindings handled by the configuration, and another single definition for “parsed” bindings used while handling input. This allows us to implement configuration parsing, keymap translation and so on using one set of functions, regardless of key binding mode.
* search: match composed characters when extending the search string to the next word boundaryDaniel Eklöf2021-01-26-0/+13
|
* search: fix matching of multi-column charactersDaniel Eklöf2021-01-26-3/+13
| | | | | We were matching the sub-sequence SPACERs as if they were regular characters, which obviously failed.
* search: don’t re-scan the scrollback unless the search string actually has changedDaniel Eklöf2021-01-26-36/+82
|
* Merge branch 'search-match-composed-characters'Daniel Eklöf2021-01-26-3/+37
|\
| * search: fix matching against composed charactersDaniel Eklöf2021-01-24-3/+37
| |
* | search: filter out non-printable charactersDaniel Eklöf2021-01-24-4/+16
|/ | | | Don’t allow non-printable characters in the search input string.
* debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes2021-01-16-16/+16
|
* Print stack trace on assert() failure or when calling fatal_error()Craig Barnes2021-01-16-2/+0
| | | | | | Note: this uses the __sanitizer_print_stack_trace() function from the AddressSanitizer runtime, so it only works when AddressSanitizer is in use.
* selection: combine enum selection_kind with selection_semanticDaniel Eklöf2021-01-06-2/+2
|
* selection: use selection_start() to initialize word/row-based selectionDaniel Eklöf2021-01-04-1/+1
| | | | | | This removes the selection_mark_word() and selection_mark_row() functions. To start a word/row-based selection, use selection_start() with SELECTION_SEMANTIC_{WORD,ROW}
* selection: wip: update selection word-wise when initial selection was by wordDaniel Eklöf2021-01-04-1/+2
|
* search: reset IME state when entering/exiting search modeDaniel Eklöf2020-12-07-0/+12
|
* render: search: glyph_offset is in *cells*, cursor position in *characters*Daniel Eklöf2020-12-07-0/+6
| | | | | | When calculating the offset into the search string, from where to start rendering, take into account that the cursor position is in *characters*, and the glyph-offset is in *cells*.
* search: new function: search_add_chars()Daniel Eklöf2020-12-07-4/+4
| | | | | This function inserts a string into the search buffer, at the current insertion point (i.e. where the cursor is).
* search: add {clipboard,primary}-paste key bindingsDaniel Eklöf2020-11-01-25/+57
| | | | | | | | | | These bindings copy from the clipboard or primary selection into the search buffer. Default bindings: * clipboard-paste: ctrl+v, ctrl+y * primary-paste: shift+insert
* config: add ‘[default].word-delimiters’Daniel Eklöf2020-10-09-1/+2
| | | | | | | | | | This option lets the user configure which characters act as word delimiters when selecting text. This affects both “double clicking”, and ‘ctrl-w’ in scrollback search mode. Closes #156
* don't use empty struct initializersDaniel Eklöf2020-08-23-2/+2
|
* search: don't update/refresh match when modifier keys are pressedDaniel Eklöf2020-08-12-0/+3
|
* search: fix viewport not moving if we tried to move it past the scrollback startDaniel Eklöf2020-08-12-21/+54
| | | | | | | | | | | | If the match was somewhere near the scrollback beginning, and if the entire scrollback hadn't yet been filled, we ended up trying to move the viewport past the beginning of the scrollback, which we then adjusted in the wrong direction, causing the viewport to not move at all. Besides being a bad user experience, since the new match wasn't visible, foot would also crash if you manually scrolled up to the match.
* fix printf-format errors in 32-bit buildsDaniel Eklöf2020-08-06-1/+1
|
* search: fix crash when searching the scrollback historyDaniel Eklöf2020-07-25-48/+52
| | | | | | | | | | | | search_update_selection() was changed in 1.4.x to *first* update the selection, *then* move the viewport. This leads to a crash if the new match (selection) is outside the current viewport; the selection code assumes the updated selection endpoint is in the visible viewport. Changing back to *first* move the viewport, *then* update the selection solves this.
* search: improve viewport movementsDaniel Eklöf2020-07-24-32/+46
| | | | | | * Don't move the viewport if the new match is already fully visible * When we do have to move the viewport, position it such that the new match ends up roughly in the middle.
* search: re-enable search-commit actionDaniel Eklöf2020-07-22-7/+5
| | | | | This was disabled while implementing multi-seat support, and I forgot to fix and re-enable before that feature was merged.
* multi-seat: re-enable scrollback search supportDaniel Eklöf2020-07-08-23/+12
|
* wip: multi-seat supportDaniel Eklöf2020-07-08-5/+18
| | | | | Compiles and runs, but mouse, clipboard and other things have been disabled.
* util.h: new header file defining commonly used macrosDaniel Eklöf2020-05-01-2/+1
|