aboutsummaryrefslogtreecommitdiff
path: root/search.c (follow)
Commit message (Collapse)AuthorAgeLines
* 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
|
* misc: replace all explicit zero-initializers with empty initializersDaniel Eklöf2020-04-13-1/+1
|
* mbstate: fix compile warning on systems where mbstate_t isn't an integralDaniel Eklöf2020-04-13-1/+1
| | | | | An empty initializer still ensures the entire object is zero-initialized.
* search: replace hard-coded key bindings with "user configurable" onesDaniel Eklöf2020-03-18-113/+115
| | | | | | | | They aren't really user configurable. At least not yet. However, with this, we now handle raw key codes just like the normal key bindings. Meaning, e.g. ctrl+g, ctrl+a, ctrl+e etc now works while searching with e.g. a russian layout.
* input: bindings: don't match raw key code alone - mods must also matchDaniel Eklöf2020-03-18-1/+4
|
* input: bind key bindings to raw key codes tooDaniel Eklöf2020-03-18-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | Before, when looking for a matching user key binding, we only matched *symbols*. This means that the physical keys that generate a specific key binding is layout dependent. What's worse, it may not even be possible to generate the key binding at all. Russian is one such layout, where all the "normal" (us) symbols are replaced. By using raw key codes, we can get around this - the key code has a direct mapping to the physical key. However, matching raw key codes **only** doesn't always make sense either. For now, match **both** symbols _and_ key codes. Symbols take precedence. TODO: we might have to make this configurable _per binding_. Note: 'search' mode still uses mostly hardcoded shortcuts that still have this problem (i.e. ctrl+g doesn't work with a russian layout).
* search: add support for user configurable key bindingsDaniel Eklöf2020-03-08-1/+13
| | | | No default bindings defined yet, though.
* render: never render CSD and/or search box "immediately"Daniel Eklöf2020-03-06-4/+2
| | | | | | | | | | Handle the CSDs and the search box the same way we handle the main grid; when we need to redraw them, call render_refresh_{csd,search}(). This sets a flag that is checked after each FDM iteration. All actual rendering is done here. This also ties the commits of the Wayland sub-surfaces to the commit of the main surface.
* search: don't mark the entire sub-surface as opaqueDaniel Eklöf2020-03-01-5/+0
|
* search: enable/disable weston sub-surface desync quirk when rendering search boxDaniel Eklöf2020-03-01-1/+1
|
* search: update search box before we update the main gridDaniel Eklöf2020-03-01-1/+1
|
* wayland: store pointer to window instance in all surfacesDaniel Eklöf2020-02-29-0/+2
|
* wayland: instantiate sub-surfaces on-demandDaniel Eklöf2020-02-26-2/+21
| | | | | | | | | | | | | | | | | | | 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.
* search: rename render.search_offset -> render.search_glyph_offsetDaniel Eklöf2020-01-05-1/+1
|
* render: ensure cursor is always visible in the search boxDaniel Eklöf2020-01-05-0/+1
| | | | | | | | | | | | | | | | | | Maintain a view 'offset' (which glyph from the search string to start rendering at). This defines the start of the viewable area. The end is the offset + the search box size (which is limited to the window size). Adjust this offset whenever the cursor moves outside the viewable area. For now, this is always done in the same way: set the offset to the cursor position. This means that when we're entering text at the end of the search criteria (i.e. the normal case; we're simply typing), and the search box reaches the window size, the cursor will jump to the start of the search box, which will be empty. This could be confusing, but let's go with for now.
* selection: track selection type; normal or block selectionDaniel Eklöf2020-01-03-1/+1
|
* search: match_to_end_of_word: reset end_col when done with a rowDaniel Eklöf2019-12-03-0/+2
|
* search: match_to_end_of_word: bug: reset end-col when bumping end-rowDaniel Eklöf2019-12-03-1/+3
| | | | | | | | When we calculate the end coords, we must reset end-col when we reach the end of the line and bump the end-row. This fixes an issue where bumping the row once lead to the end row being bumped for *each* remaining match character.
* search: bug: restore end-col/end-row adjustmentDaniel Eklöf2019-12-03-2/+4
| | | | | Turns out end_col *can* be exactly 0. In this case, we need to adjust the end-row too.
* search: bug: re-initialize start-row when attempting a new matchDaniel Eklöf2019-12-03-4/+4
| | | | | | When we've already found a partial match (but *not* a complete match), and that match spanned multiple lines, then when we continued with the next start-column we re-used a know-wrong row pointer.
* search: map ctrl+shift+w to match to end of word, spaces onlyDaniel Eklöf2019-12-03-4/+7
| | | | | This works just like ctrl+w, except that the only space separating characters are whitespaces.
* search: search_match_to_end_of_word: rename start_{row,col} -> end_{row,col}Daniel Eklöf2019-12-03-8/+10
|
* search: split up search_update() into twoDaniel Eklöf2019-12-03-68/+71
| | | | | | | | | * search_find_next() searches the scrollback, continuing from the last match. The assumption is that the search buffer has changed. * search_update_selection() updates the selection and moves the view to ensure the selection is visible. Note that it doesn't verify the selection actually matches the search buffer.
* search: rename search_update() -> search_find_next()Daniel Eklöf2019-12-03-3/+3
|
* search: map ctrl+w to 'extend current selection to end of word'Daniel Eklöf2019-12-03-0/+75
| | | | | | | If the user has started a scrollback search and have some matching text, he can now press ctrl+w to extend that selection (and thus the search criteria too) to the end of the current word, or to the end of the next word if currently at a word separating character.
* search: discard canceled compose sequencesDaniel Eklöf2019-12-03-0/+2
|
* Revert "search: discard canceled compose sequences"Daniel Eklöf2019-12-03-4/+0
| | | | This reverts commit f67733c0e3a4e4ba19e1c70bc36ee78af762868f.
* search: discard canceled compose sequencesDaniel Eklöf2019-12-03-0/+4
|
* search: remove debug logDaniel Eklöf2019-12-03-1/+0
|
* search: don't line-wrap unless we actually have a match on the next rowDaniel Eklöf2019-12-03-4/+6
| | | | | | | | When matching characters, we moved on to next row directly after matching the last character in a row. This was wrong since if that last character was the last matching character, we tried to create a selection that was on the wrong row.
* search: break out search buffer resize code to a new functionDaniel Eklöf2019-12-03-12/+21
|
* Add missing includesDaniel Eklöf2019-12-01-0/+1
|
* search: update xcursor when starting and ending a searchDaniel Eklöf2019-11-29-0/+2
|
* wayland: implement wayl_init()Daniel Eklöf2019-10-27-2/+2
| | | | Wayland instantiation is now done by the wayland backend, not in main.
* term: wayland struct is now not a part of the terminal structDaniel Eklöf2019-10-27-9/+9
| | | | | | We do however need access to it, so provide a pointer. The difference is that now we can have a *single* wayland instance, but multiple terminal instances.
* wayland: change all wayland callbacks to take a wayland pointerDaniel Eklöf2019-10-27-1/+1
| | | | | Instead of passing the terminal to the wayland callbacks, pass a 'struct wayland' pointer.
* kbd: move into waylandDaniel Eklöf2019-10-27-8/+8
|
* term: move per-window wayland objects from wayland struct to terminal structDaniel Eklöf2019-10-27-2/+2
| | | | | | | | Short term, we want to break out the wayland backend from the terminal struct. Long term, we might want to support multiple windows. One step towards both the above is separating global wayland objects from per-window objects.
* search: map ctrl+b/f to move cursor single character backward/forwardDaniel Eklöf2019-08-30-2/+6
|
* search: ctrl+s searches forwardDaniel Eklöf2019-08-30-0/+18
|
* search: make search-direction configurableDaniel Eklöf2019-08-30-7/+23
|
* search: fix distance to prev word calculation when final cursor was 0Daniel Eklöf2019-08-30-1/+1
|
* search: implement move cursor word backward/forwardDaniel Eklöf2019-08-30-0/+18
|
* search: implement delete word backward/forwardDaniel Eklöf2019-08-30-2/+18
|
* search: utility functions distance_{next,prev}_word()Daniel Eklöf2019-08-30-0/+56
| | | | | These functions calculate the distance from the current cursor to the next/previous word.
* Revert "search: for now, reset search match state whenever the buffer changes"Daniel Eklöf2019-08-29-9/+0
| | | | This reverts commit 9c6ece747ed328b0e922597ec52646c00bb68c8c.
* search: for now, reset search match state whenever the buffer changesDaniel Eklöf2019-08-29-0/+9
|
* search: call render_search_box() from search_inptu()Daniel Eklöf2019-08-29-3/+1
|
* search: add basic cursor navigation supportDaniel Eklöf2019-08-29-2/+45
|
* search: insert new characters at cursor, not at the end of the bufferDaniel Eklöf2019-08-29-2/+7
|
* search: search_cancel: reset cursor positionDaniel Eklöf2019-08-29-0/+1
|
* search: turn info log to a debug logDaniel Eklöf2019-08-29-1/+1
|
* search: remove INFO log (that really was a debug log)Daniel Eklöf2019-08-29-1/+0
|
* search: don't destroy/recreate search (sub)surfaceDaniel Eklöf2019-08-29-27/+2
| | | | | | Create the sub-surface once, at startup. Then, instead of destroying it when committing/cancelling a search, unmap it (by attaching a NULL buffer to it).