aboutsummaryrefslogtreecommitdiff
path: root/selection.c (unfollow)
Commit message (Collapse)AuthorLines
2026-10-28selection: fix multi-cell chars selection updateCismonX-3/+1
As in 0e7e943062, absolute row numbers cannot be used for comparison. Here it may break selection update with multi-cell characters. Note that there's no need to compare the coordinates again. A better fix is to check the selection direction instead.
2026-10-25selection: fix row comparison in selection updateCismonX-3/+8
Absolute row numbers may wrap around, thus not suitable for comparison. This may incorrectly update the selection direction and break word-wise selection. Compare scrollback-relative row numbers instead. Fixes #2483.
2026-09-10selection: treat spacer pad cells as empty cells when marking cells for highlightingDaniel Eklöf-1/+3
2026-09-10selection: don't allow the start/end-points to be inside spacer pad cellsDaniel Eklöf-0/+13
Having the start/end-points in the pad area made the spacer cells tracking points when reflowing the grid. This caused the spacer cells to be kept, instead of removed.
2026-09-10selection: don't include spacer pad cells when extending the selection to cover all of a ↵Daniel Eklöf-4/+13
multi-cell character When the selection starts or ends in the middle of a multi-cell character, we stretch the selection so that all of the cells belonging to the character is selected. When we do this, we do *not* want trailing pad cells to be included in the selection.
2026-08-06selection: check column when updating selectionCismonX-8/+12
Selection coordinates may appear outside of the terminal grid (e.g., during the "fast resize" stage of delayed resize), resulting in bad width passed to pixman_region32_union_rect().
2026-07-30selection: find-quote-right: assert next-row > 0Daniel Eklöf-0/+4
2026-07-30selection: fixed segfault when quote is on newlineEmily Vlasics-3/+7
Closes #2405
2026-07-21selection: fix word boundary checkCismonX-23/+17
This patch fixes rightmost boundary check for a word wrapped to another line, where a multi-column character appears as the last character in the original line. Closes #2411
2026-06-12selection: escape quotes in file names being DnD:ed on the command lineDaniel Eklöf-1/+10
Closes #2363
2026-06-12selection: fix block selection direction updateCismonX-1/+1
This patch fixes a condition check in selection_update(), so that during block selection, the selection area no longer gets incorrectly updated when selecting back across the starting column.
2026-05-22selection: do not copy empty textCismonX-0/+6
Copy-on-select (configured with 'selection-target') may accidentally clear the clipboard, if the user drags the mouse a little bit when clicking inside a terminal window. Now we only copy if there is actual text being selected. Closes #2327
2026-03-22osc-52: don't strip any control characters, and don't do newline conversionDaniel Eklöf-13/+26
2025-11-12Fix assertion failure triple-clicking line with quote in last columnJohannes Altmanninger-3/+10
By default, triple-click tries to select quoted strings within a logical line. This also works if the line spans multiple screen lines. If there is a quote character in the last column: printf %"$COLUMNS"s \'; printf wrapped; sleep inf and I triple-click on the following soft-wrapped line, there's an assertion failure because the column next to the quote is out of range. The quote position has been found by walking at least one cell backwards from "pos". This means that if the quote position is in the very last column, there must be a row below. Also move the assertion to be a pre-condition, though that's debatable.
2024-12-22selection: fix crash when tripple clicking in a region containing NUL charactersDaniel Eklöf-4/+4
If a cell contains a NUL character, it was incorrectly treated as a quote, later triggering an assertion. Patch by Johannes Altmanninger
2024-09-21selection: set row->dirty when clearing the cell->attrs.clean bitDaniel Eklöf-1/+4
Closes #1715
2024-02-06Don't use fancy Unicode quotes, stick to ASCIIDaniel Eklöf-19/+19
2024-02-05util: add streq() function and use in place of strcmp(...) == 0Craig Barnes-2/+2
2023-10-08selection: find_word_boundary: ensure row number is boundedDaniel Eklöf-6/+8
2023-10-08selection: selection_update() uses view-local coordinatesDaniel Eklöf-7/+12
2023-10-08search: add more key bindings to extend the current matchDaniel Eklöf-38/+51
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
2023-09-19selection: add support for selecting the contents of a quoteDaniel Eklöf-14/+151
This patch changes the default of triple clicking, from selecting the current logical row, to first trying to select the contents of the quote under the cursor, and if failing to find a quote, selecting the current row (like before). This is implemented by adding a new key binding, 'select-quote'. It will search for surrounding quote characters, and if one is found on each side of the cursor, the quote is selected. If not, the entire row is selected instead. Subsequent selection operations will behave as if the selection is either a word selection (a quote was found), or a row selection (no quote found). Escaped quote characters are not supported: "foo \" bar" will match 'foo \', and not 'foo " bar'. Mismatched quotes are not custom handled. They will simply not match. Nested quotes ("123 'abc def' 456") are supported. Closes #1364
2023-07-22selection: send_clipboard_or_primary(): handle selection text being NULLDaniel Eklöf-3/+1
2022-11-24selection: selection_on_rows(): typo: row_start -> row_endDaniel Eklöf-1/+1
This fixes an issue where selections in the scroll margins were not detected correctly. This meant they weren’t canceled as they should have been, which in turn caused a visual glitch where text appeared to be selected, but were in fact not.
2022-10-16selection: scroll down: handle non-full scrollback correctlyDaniel Eklöf-3/+8
When determining whether or not to cancel a selection (due to it, or part of it, being "scrolled out"), we assumed the scrollback was full. This patch changes the implementation to compare the scrollback relative selection coordinates with the scrollback relative end-of-the-scrollback coordinates.
2022-08-31selection: mark_selected_region(): use an enum to encode how the cells are to be updatedDaniel Eklöf-7/+20
2022-08-31selection: restore <= 1.12 behavior in block selection wrt empty cellsDaniel Eklöf-1/+3
That is, highlight empty cells, regardless of whether they’re trailing or not.
2022-08-31selection: once again highlight non-trailing empty cellsDaniel Eklöf-6/+38
Foot 1.13.0 introduced a regression where non-trailing empty cells were highlighted inconsistently (cells that shouldn’t be highlighted, were, seemingly at random). 86663522d5915c0fdb2b8b132bacc247fcfd1fb8 “fixed” this by never highlighting *any* empty cells. This meant the behavior, compared to foot 1.12 and earlier, changed. In foot 1.12 and older versions, non-trailing empty cells were highlighted, as long as the selection covered at least one of the trailing non-empty cells. This patch restores that behavior. To understand how this works, lets first take a look at how selection works: When a selection is made, and updated (i.e. the mouse is dragged, or the selection is extended through RMB etc), we need to (un)tag and dirty the cells that are a) newly selected, or b) newly deselected. That is, we look at the diff between the “old” and the “new” selection, and only update those cells. This is for performance reasons: iterating the entire selection is not feasible with large selections. However, it also means we cannot reason about empty cells; we simply don’t know if an empty cells is a trailing empty cell, or a non-trailing one. Then, when we render a frame, we iterate all the *visible* and *selected* cells, once again tagging them as selected (this is needed since a selected cell might have lost its selected tag if the cell was written to, by the client application, after the selection was made). At this point, we *can* reason about empty cells. So, to restore the highlighting behavior to that of foot 1.12, we do this: When working with the selection diffs when a selection is updated, we don’t special case empty cells at all. Thus, all empty cells covered by the selection is highlighted, and dirtied. But, when rendering the frame, we _do_ special case them. The only difference (compared to foot 1.12) is that we *must* explicitly *clear* the selection tag, and dirty the empty cells. This is to ensure the empty cells that were incorrectly highlighted by the selection update algorithm, isn’t rendered as that. This does have a slight performance impact, as empty cells are now always re-rendered. The impact should however be small.
2022-08-31selection: never highlight selected, empty cellsDaniel Eklöf-2/+21
This fixes a regression, where empty cells "between" non-empty cells (i.e. non-trailing empty cells) sometimes were incorrectly highlighted. The idea has always been to highlight exactly those cells that will get extracted when they’re copied. This means we’ve not highlighted trailing empty cells, but we _have_ highlighted other empty cells, since they are converted to spaces when copied (whereas trailing empty cells are skipped). fa2d9f86996467ba33cc381f810ea966a4323381 changed how a selection is updated. That is, which cells gets marked as selected, and which ones gets unmarked. Since we no longer walk all the cells, but instead work with pixman regions representing selection diffs, we can no longer determine (with certainty) which empty cells should be selected and which shouldn’t. Before this patch (but after fa2d9f86996467ba33cc381f810ea966a4323381), we sometimes incorrectly highlighted empty cells that should not have been highlighted. This happened when we’ve first (correctly) highlighted a region of empty cells, but then shrink the selection such that all those empty cells should be de-selected. This patch changes the selection behavior to *never* highlight empty cells. This fixes the regression, but also means slightly different behavior, compared to pre-fa2d9f86996467ba33cc381f810ea966a4323381. The other alternative is to always highlight all empty cells. But, since I personally like the fact that we’re skipping trailing empty cells, I prefer the approach taken by this patch.
2022-08-26selection: mark_selected_region(): use an enum to encode how the cells are to be updatedDaniel Eklöf-7/+20
2022-08-26selection: restore <= 1.12 behavior in block selection wrt empty cellsDaniel Eklöf-1/+3
That is, highlight empty cells, regardless of whether they’re trailing or not.
2022-08-22selection: once again highlight non-trailing empty cellsDaniel Eklöf-6/+38
Foot 1.13.0 introduced a regression where non-trailing empty cells were highlighted inconsistently (cells that shouldn’t be highlighted, were, seemingly at random). 86663522d5915c0fdb2b8b132bacc247fcfd1fb8 “fixed” this by never highlighting *any* empty cells. This meant the behavior, compared to foot 1.12 and earlier, changed. In foot 1.12 and older versions, non-trailing empty cells were highlighted, as long as the selection covered at least one of the trailing non-empty cells. This patch restores that behavior. To understand how this works, lets first take a look at how selection works: When a selection is made, and updated (i.e. the mouse is dragged, or the selection is extended through RMB etc), we need to (un)tag and dirty the cells that are a) newly selected, or b) newly deselected. That is, we look at the diff between the “old” and the “new” selection, and only update those cells. This is for performance reasons: iterating the entire selection is not feasible with large selections. However, it also means we cannot reason about empty cells; we simply don’t know if an empty cells is a trailing empty cell, or a non-trailing one. Then, when we render a frame, we iterate all the *visible* and *selected* cells, once again tagging them as selected (this is needed since a selected cell might have lost its selected tag if the cell was written to, by the client application, after the selection was made). At this point, we *can* reason about empty cells. So, to restore the highlighting behavior to that of foot 1.12, we do this: When working with the selection diffs when a selection is updated, we don’t special case empty cells at all. Thus, all empty cells covered by the selection is highlighted, and dirtied. But, when rendering the frame, we _do_ special case them. The only difference (compared to foot 1.12) is that we *must* explicitly *clear* the selection tag, and dirty the empty cells. This is to ensure the empty cells that were incorrectly highlighted by the selection update algorithm, isn’t rendered as that. This does have a slight performance impact, as empty cells are now always re-rendered. The impact should however be small.
2022-08-22selection: never highlight selected, empty cellsDaniel Eklöf-2/+21
This fixes a regression, where empty cells "between" non-empty cells (i.e. non-trailing empty cells) sometimes were incorrectly highlighted. The idea has always been to highlight exactly those cells that will get extracted when they’re copied. This means we’ve not highlighted trailing empty cells, but we _have_ highlighted other empty cells, since they are converted to spaces when copied (whereas trailing empty cells are skipped). fa2d9f86996467ba33cc381f810ea966a4323381 changed how a selection is updated. That is, which cells gets marked as selected, and which ones gets unmarked. Since we no longer walk all the cells, but instead work with pixman regions representing selection diffs, we can no longer determine (with certainty) which empty cells should be selected and which shouldn’t. Before this patch (but after fa2d9f86996467ba33cc381f810ea966a4323381), we sometimes incorrectly highlighted empty cells that should not have been highlighted. This happened when we’ve first (correctly) highlighted a region of empty cells, but then shrink the selection such that all those empty cells should be de-selected. This patch changes the selection behavior to *never* highlight empty cells. This fixes the regression, but also means slightly different behavior, compared to pre-fa2d9f86996467ba33cc381f810ea966a4323381. The other alternative is to always highlight all empty cells. But, since I personally like the fact that we’re skipping trailing empty cells, I prefer the approach taken by this patch.
2022-07-28selection: rework how we update a selectionDaniel Eklöf-106/+190
Before this patch, each selection update would result in grid covered by the selection being walked *three* times. First to “premark” the area that *will* be selected after the update, then again to unmark the previous selection (excluding the cells that were premarked - but the cells are still iterated), and then one more time to finalize the selection state in the grid. Furthermore, each time a frame is rendered, the entire selection were iterated again, to ensure all the cells have their ‘selected’ bit set. This quickly gets *very* slow. This patch takes a completely different approach. Instead of looking at the selection as a range of cells to iterate, we view it as an area, or region. Thus, on each update, we have to regions: the region representing the previous selection, and the region representing the to-be selection. By diffing these two regions, we get two new regions: one that represents the cells that were selected, but aren’t any more, and one that represents the cells that previously were not selected, but now will be. We implement the regions using pixman regions. By subtracting the current selection from the previous selection, we get the region representing the cells that are no longer selected, and that should be unmarked. By subtracting the previous selection from the current, we get the region representing the cells that was added to the selection in this update, and that should be marked. selection_dirty_cells() is rewritten in a similar manner. We create pixman regions for the selection, and the current scrollback view. The intersection represents the (selected) cells that are visible. These need to iterated and marked as being selected. Closes #1114
2022-07-28selection: extend: use scrollback relative coordinatesDaniel Eklöf-15/+33
When extending a selection, we determine *how* to extend it (which endpoint to move, and whether to grow or shrink the selection) by comparing the extension point with the old start and end coordinates. For this to work correctly, we need to use scrollback relative coordinates. This fixes an issue where extending a very large selection (covering many pages) sometimes shrunk the selection instead of growing it, or just misbehaving in general.
2022-07-28selection: foreach_selected_*(): refactor: use grid_row_abs_to_sb()Daniel Eklöf-6/+5
2022-07-28selection: selection_on_rows(): use scrollback relative coordsDaniel Eklöf-15/+59
When checking if the current selection intersects with the region (passed as parameter to the function), use scrollback relative coordinates. This fixes an issue where selections crossing the scrollback wrap-around being misdetected, resulting in either the selection being canceled while scrolling, even though it wasn’t scrolled out, or the selection _not_ being canceled, when it _was_ scrolled out.
2022-06-21selection: wl_data_offer_set_action: use enum values instead of magic integersDaniel Eklöf-1/+4
2022-06-20selection: reject dnd offers with unsupported mime-typesDaniel Eklöf-0/+4
We were already doing this, implicitly, *if* the offer was for the main grid. This patch makes it more clear that we do not accept the offer.
2022-06-20selection: explicitly reject *all* dnd offers not targeting the gridDaniel Eklöf-0/+1
2022-06-20selection: ignore drag-and-drops with unsupported mime-typesDaniel Eklöf-0/+6
Specifically, make sure we do *not* call wl_data_offer_receive() with a NULL mime-type, as this causes libwayland to error out, which in turn causes foot to exit. Closes #1092
2022-06-15selection: allow HT, VT and FF, disallow NUL in non-bracketed paste modeDaniel Eklöf-3/+16
This syncs foot with more recent versions of XTerm, where it’s “disallowedPasteControls” resource has changed its default value to BS,DEL,ENQ,EOT,ESC,NULL Note that we’re already stripping out ENQ,EOT,ESC in all modes. What does it mean for foot: * HT, VT and FF are now allowed, regardless of paste mode * NUL is now stripped in non-bracketed paste mode Closes #1084
2022-04-27selection: find_word_boundary_right: add “stop-on-space-to-word-boundary”Daniel Eklöf-8/+19
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.
2022-04-25selection: add start/end coordinate gettersDaniel Eklöf-0/+24
Internally, selection coordinates are *unbounded* (that is, the row numbers may be larger than grid->num_rows) while a selection is ongoing. Only after it has been finalized are the coordinates bounded. This means it isn’t safe to use term->selection.coords.* directly.
2022-04-24selection: assert serial is non-zero before copying data to the clipboardDaniel Eklöf-1/+4
2022-04-24selection: find_word_boundary: assert ‘pos’ is validDaniel Eklöf-0/+10
2022-04-17search: fix next/prev not updating selection correctly when matches overlapDaniel Eklöf-1/+1
When the new match overlapped with the old match, the selection wasn’t updated correctly.
2022-04-09refactor: add a ‘range’ struct, grouping a start and end coord togetherDaniel Eklöf-52/+52
2022-03-19selection: don’t translate \r to \n when pastingDaniel Eklöf-7/+2
In non-bracketed paste mode, we translate \n to \r, and \r\n to \r. The latter matches XTerm, urxvt, alacritty and kitty. The former matches alacritty and kitty (xterm and urxvt just blindly replaces all \n occurrences with \r, meaning \r\n is translated to \r\r. For some reason, we then unconditionally translated all \r back to \n, regardless of whether bracketed paste was enabled or not. Unsure why/where this comes from, but it doesn't match any of the other terminal emulators I tested. One example where this caused issues is in older versions of nano (at least up to 2.9). Closes #980
2022-02-07selection: foreach: sort start/end based on their scrollback-start relative valuesDaniel Eklöf-20/+56
When iterating the characters in a selection, we want to go from the “start” to the “end”, where start is the upper left-most character, and “end” is the lower right-most character. There are two things to consider: * The ‘start’ coordinate may actually sort after the ‘end’ coordinate (user selected from bottom of the window and upward) * The scrollback wraparound. What we do is calculate both the star and end coordinates’ scrollback-start relative row numbers. That is, the number of rows from the beginning of the scrollback. So if the very first row (i.e. the oldest) in the scrollback is selected, that has the scrollback-start relative number “0”. Then we loop from whichever (start or end coordinate) is highest up in the scrollback, to the “other” coordinate.
2022-02-07selection: ensure start/end coordinates are bounded by the current gridDaniel Eklöf-10/+2
Closes #924
2022-02-05fcft: adapt to API changes in fcft-3.xDaniel Eklöf-9/+9
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
2022-02-02selection: don’t quote file URIs on the alt screenDaniel Eklöf-2/+9
Closes #379
2021-10-19selection: convert \r -> \n when reading clipboard dataDaniel Eklöf-0/+5
This fixes an issue where pasting (using e.g. OSC-52) in client applications that doesn’t do this conversion themselves, like tmux, doesn’t work. Closes #752
2021-09-30selection: line-wise selection now handles soft line-wrappingDaniel Eklöf-16/+83
Previously, soft-wrapped lines were not selected correctly, as the selection logic was hardcoded to simply select everything between the first and last column on the current terminal row. Now, we scan backward and forward, looking for hard-wrapped lines. This is similar to how word-based selection works. Closes #726
2021-08-16selection: modify: no need to check for NULL before calling free()Daniel Eklöf-4/+1
2021-08-16selection: modify: convert ‘keep_selection’ bitmask from uint64_t to uint8_tDaniel Eklöf-11/+11
2021-08-16selection: modify: replace reset_context() macro with a functionDaniel Eklöf-9/+9
2021-08-16selection: don’t require two cell attr bits for selection updatingDaniel Eklöf-24/+61
When updating the selection (i.e when changing it - adding or removing cells to the selection), we need to do two things: * Unset the ‘selected’ bit on all cells that are no longer selected. * Set the ‘selected’ bit on all cells that *are* selected. Since it’s quite tricky to calculate the difference between the “old” and “new” selection, this is done by first un-selecting the old selection, and then selecting the new, updated selection. I.e. first we clear the ‘selected’ bit from *all* cells, and then we re-set it on those cells that are still selected. This process also dirties the cells, to make sure they are re-rendered (needed to reflect their new selected/un-selected status). To avoid dirtying *all* previously selected, and newly selected cells, we have used an algorithm that first runs a “pre-pass”, marking all cells that *will* be selected as such. The un-select pass would then skip (no dirty) cells that have been marked by the pre-pass. Finally, the select pass would only dirty cells that have *not* been marked by the pre-pass. In short, we only dirty cells whose selection state have *changed*. To do this, we used a second ‘selected’ bit in the cell attribute struct. Those bits are *scarce*. This patch implements an alternative algorithm, that frees up one of the two ‘selected’ bits. This is done by lazy allocating a bitmask for the entire grid. The pre-pass sets bits in the bitmask. Thus, after the pre-pass, the bitmask has set bits for all cells that *will* be selected. The un-select pass simply skips cells with a one-bit in the bitmask. Cells without a one-bit in the bitmask are dirtied, and their ‘selected’ bit is cleared. The select-pass doesn’t even have to look at the bitmask - if the cell already has its ‘selected’ bit set, it does nothing. Otherwise it sets it and dirties the cell. The bitmask is implemented as an array of arrays of 64-bit integers. Each outer element represents one row. These pointers are calloc():ed before starting the pre-pass. The pre-pass allocates the inner arrays on demand. The unselect pass is designed to handle both the complete absence of a bitmask, as well as row entries being NULL (both means the cell is *not* pre-marked, and will thus be dirtied).
2021-07-22search: reset match state when selection is cancelledDaniel Eklöf-0/+3
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
2021-07-18csi: erase scrollback: cancel selection if it touches the scrollbackDaniel Eklöf-3/+1
This breaks out the scrollback erasing logic for \E[3J from csi.c, and moves it to the new function term_erase_scrollback(), and changes the logic to calculate the start and end row (absolute) numbers of the scrollback, and only iterate those, instead of iterating *all* rows, filtering out those that are on-screen. It also adds an intersection range check of the selection range, and cancels the selection if it touches any of the deleted scrollback rows. This fixes a crash when trying to render the next frame, since the selection now references rows that have been freed. Closes #633
2021-06-24composed: store compose chains in a binary search treeDaniel Eklöf-20/+8
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-24wip: grapheme shapingDaniel Eklöf-4/+4
2021-06-09selection: add support for TEXT/STRING/UTF8_STRING mime-types in incoming offersDaniel Eklöf-6/+15
We were already offering these mime types for our own clipboard data, but ignored them in incoming offers. Fixes paste issues from Geany. Closes #583
2021-06-05selection: reset ‘empty_count’ after we’ve emitted the empty cellsDaniel Eklöf-0/+2
When marking and unmarking cells, we don’t highlight trailing empty cells. We do however highlight empty cells if they are followed by non-empty cells. I think this was an intentional choice. If one row ended with trailing empty cells, but *no* hard linebreak, then we’d continue on the next row, and emit all the empty cells once we hit a non-emtpy cell on the second row. But this is something that shouldn’t happen in any real-world use cases.
2021-06-02selection: fix bad assertionDaniel Eklöf-2/+2
When there are multiple multi-column characters back-to-back, the cell before the pivot end point may in fact be a SPACER+1 cell.
2021-05-31selection: pay attention to hard linebreaks when search for word boundariesDaniel Eklöf-4/+18
Double-clicking on a word in the left or right margin, would line-wrap the selection if there was a non-empty cell in the corresponding right/left margin on the prev/next line. Regardless of whether there was a hard linebreak or not. Script to reprouce: !/bin/bash cols=$(tput cols) printf "%*coo\nbar\n" $((${cols} - 2)) f Run, then double click either “foo” or “bar”. Neither should select the other part. Closes #565
2021-05-17extract: move ‘strip_trailing_empty’ parameter from extra_finish() to extract_begin()Daniel Eklöf-2/+2
2021-05-17extract: add extract_finish_wide(), and optionally skip stripping trailing empty cellsDaniel Eklöf-1/+1
extract_finish() returns the extracted text in UTF-8, while extract_finish_wide() returns the extracted text in Unicode. This patch also adds a new argument to extract_finish{,_wide}, that when set to true, skips stripping trailing empty cells.
2021-05-17selection: expose find_word_boundary_{left,right}()Daniel Eklöf-12/+16
2021-05-14term: rename CELL_MULT_COL_SPACER -> CELL_SPACER, and change its definitionDaniel Eklöf-13/+13
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.
2021-02-12selection: don’t strip formatting C0 control characters in bracketed paste modeDaniel Eklöf-18/+25
It’s ok to let the receiving end handle formatting C0 control characters in bracketed paste mode. In fact, we *must* let them through. Otherwise it is impossible to paste e.g. tabs into editors and similar applications.
2021-02-12selection: don’t strip formatting C0 control characters in bracketed paste modeDaniel Eklöf-18/+25
It’s ok to let the receiving end handle formatting C0 control characters in bracketed paste mode. In fact, we *must* let them through. Otherwise it is impossible to paste e.g. tabs into editors and similar applications.
2021-02-12config: add ‘none’ as a possible value for ‘selection-target’Daniel Eklöf-0/+3
When ‘selection-target’ is set to ‘none’, selecting text does not copy the text to _any_ clipboard. This patch also refactors the value parsing to be data driven.
2021-02-12selection: copy selected text to the target configured by ‘selection-target’Daniel Eklöf-1/+14
Closes #288
2021-02-10Convert all but 2 remaining uses of xassert(false) to BUG("...")Craig Barnes-7/+6
2021-02-02selection: remove selection_enabled()Daniel Eklöf-10/+0
Its name did not reflect its semantics. Since it was only used in a single place, “inline” it there, and get rid of it.
2021-01-27selection: don’t replace \r\n and \n with \r in bracketed paste modeDaniel Eklöf-3/+14
2021-01-27selection: don’t replace \r\n and \n with \r in bracketed paste modeDaniel Eklöf-3/+14
2021-01-26selection: no xassert() in the releases/1.6 branchDaniel Eklöf-1/+1
2021-01-26selection: remove duplicate ‘ESC’ in switch caseDaniel Eklöf-4/+0
2021-01-26selection: DEL is 0x7f, not 0x1fDaniel Eklöf-1/+1
2021-01-26selection: codespell: stript -> stripDaniel Eklöf-1/+1
2021-01-26selection: strip non-formatting C0, BS, HT and DEL from pasted textDaniel Eklöf-0/+17
2021-01-26selection: unbreak text/uri-list decoding: we’re not using \r, not \nDaniel Eklöf-1/+1
Before passing the pasted text to the decoder, we now replace \r\n, and \n, with \r. The URI decoder was looking for a \n, which meant we failed to split up the list and instead pasted a single “multi-line” URI.
2021-01-26selection: replace \r\n and \n with \r, and strip \e from pasted textDaniel Eklöf-3/+27
Closes #305 Closes #306
2021-01-26selection: remove duplicate ‘ESC’ in switch caseDaniel Eklöf-4/+0
2021-01-26selection: DEL is 0x7f, not 0x1fDaniel Eklöf-1/+1
2021-01-26selection: codespell: stript -> stripDaniel Eklöf-1/+1
2021-01-26selection: strip non-formatting C0, BS, HT and DEL from pasted textDaniel Eklöf-0/+17
2021-01-26selection: unbreak text/uri-list decoding: we’re not using \r, not \nDaniel Eklöf-1/+1
Before passing the pasted text to the decoder, we now replace \r\n, and \n, with \r. The URI decoder was looking for a \n, which meant we failed to split up the list and instead pasted a single “multi-line” URI.
2021-01-26selection: replace \r\n and \n with \r, and strip \e from pasted textDaniel Eklöf-3/+27
Closes #305 Closes #306
2021-01-23config: add ‘none’ as a possible value for ‘selection-target’Daniel Eklöf-0/+3
When ‘selection-target’ is set to ‘none’, selecting text does not copy the text to _any_ clipboard. This patch also refactors the value parsing to be data driven.
2021-01-23selection: copy selected text to the target configured by ‘selection-target’Daniel Eklöf-1/+14
Closes #288
2021-01-21selection: uri decode: move zero-length check into decode_one_uri()Daniel Eklöf-2/+4
2021-01-21selection: add a ‘finish’ function, called at the end of receiving clipboard dataDaniel Eklöf-0/+24
This is necessary to decode the final URI in a text/uri-list offer if it hasn’t been newline terminated.
2021-01-21selection: URI decoder: break out decoding of a single URIDaniel Eklöf-27/+29
2021-01-16debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes-47/+47
2021-01-14config: add ‘select-extend-character-wise’ bind actionDaniel Eklöf-5/+17
This forces the (new) selection mode to be character-wise when extending a word- or line-wise selection. Default key binding is ctrl+RMB.
2021-01-12selection: uri decode: move zero-length check into decode_one_uri()Daniel Eklöf-2/+4