aboutsummaryrefslogtreecommitdiff
path: root/selection.h (unfollow)
Commit message (Collapse)AuthorLines
2026-03-22osc-52: don't strip any control characters, and don't do newline conversionDaniel Eklöf-2/+2
2023-10-08search: add more key bindings to extend the current matchDaniel Eklöf-2/+2
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
2022-07-28selection: selection_on_rows(): use scrollback relative coordsDaniel Eklöf-0/+2
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-04-27selection: find_word_boundary_right: add “stop-on-space-to-word-boundary”Daniel Eklöf-1/+2
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/+3
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.
2021-05-17selection: expose find_word_boundary_{left,right}()Daniel Eklöf-0/+5
2021-02-02selection: remove selection_enabled()Daniel Eklöf-1/+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-14config: add ‘select-extend-character-wise’ bind actionDaniel Eklöf-2/+3
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-06selection: combine enum selection_kind with selection_semanticDaniel Eklöf-2/+1
2021-01-04selection: use selection_start() to initialize word/row-based selectionDaniel Eklöf-7/+2
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}
2021-01-04selection: wip: update selection word-wise when initial selection was by wordDaniel Eklöf-1/+2
2020-10-28selection: add support for different mime-typesDaniel Eklöf-2/+2
Add support for `text/plain`, `text/plain;charset=utf-8` and `text/uri-list` to regular copy operations (both from clipboard and primary selection) and drag-and-drop operations.
2020-10-11selection: auto-scroll: selection keeps scrolling while mouse is outside gridDaniel Eklöf-0/+5
Moving the mouse outside the grid while we have an on-going selection now starts a timer. The interval of this timer depends on the mouse’s distance from the grid - the further away the mouse is, the shorter interval. On each timer timeout, we scroll one line, and update the selection. Thus, the shorter the interval, the faster we scroll. The timer is canceled as soon as the mouse enters the grid again, or the selection is either canceled or finalized. The timer FD is created and destroyed on-demand. Most of the logic is now in selection.c. The exception is the calculation of the timer interval, which depends on the mouse’s position. Thus, this is done in input.c. The scroll+selection update logic needs to know a) which direction we’re scrolling in, and b) which *column* the selection should be updated with. If the mouse is outside the grid’s left or right margins, the stored mouse column will be -1. I.e. we don’t know whether the mouse is on the left or right side of the grid. This is why the caller, that starts the timer, must provide this value. The same applies to top and bottom margins, but since we already have the scroll *direction*, which row value to use can be derived from this.
2020-10-10selection: use appropriate check for PRIMARY pasteSergey Nazaryev-25/+14
Assume it could be a copy-paste typo. We should check PRIMARY, not CLIPBOARD. Without this fix, we can't use PRIMARY until we copy anything to CLIPBOARD.
2020-09-09selection: add selection_<type>_has_data()Daniel Eklöf-0/+3
Returns true when there is data available for paste in the clipboard/primary selection.
2020-09-09selection: add selection_<type>_unset()Daniel Eklöf-0/+3
These functions clear the current selection.
2020-07-31config: add 'pipe-selected' key bindingDaniel Eklöf-0/+1
This works just like pipe-visible and pipe-scrollback, but pipes the user-selected text, if any, to the external tool. Closes #51
2020-07-09seat: use separate 'enter' serials for keyboard and mouseDaniel Eklöf-1/+1
2020-07-09multi-seat: improve handling of multiple (mouse) pointersDaniel Eklöf-1/+1
* xcursor always set for all pointers * xcursor sometimes not updated when it should be * mouse grabbed state wasn't per seat, but global (i.e. "does at least one seat enable mouse grabbing") * selection enabled state wasn't per seat
2020-07-08multi-seat: re-enable selection support (excluding OSC 52)Daniel Eklöf-13/+22
2020-05-19selection: handle viewport wrap around correctlyDaniel Eklöf-0/+3
When the viewport wraps around, the selection points may be "incorrect".
2020-05-17term: scrolling: hopefully fix all selection/scrolling related crashesDaniel Eklöf-1/+1
When scrolling, there are a couple of cases where an existing selection must be canceled because we cannot meaningfully represent it after scrolling. These are when the selection is (partly) inside: * The top scrolling region * The bottom scrolling region * The new lines scrolled in. I.e. re-used lines For the scrolling regions, the real problem is when the selection crosses the scrolling region boundary; a selection that is completely inside a scrolling regions _might_ be possible to keep, but we would need to translate the selection coordinates to the new scrolling region lines. For simplicity, we cancel the selection if it touches the scrolling region. Period. The last item, newly scrolled in lines is when the selection covers very old lines and we're now wrapping around the scrollback history. Then there's a fourth problem case: when the user has started a selection, but hasn't yet moved the cursor. In this case, we have no end point. What's more problematic is that when the user (after scrolling) moves the cursor, we try to create a huge selection that covers mostly empty (NULL) rows, causing us to crash. This can happen e.g. when reverse scrolling in such a way that we wrap around the scrollback history. The actual viewport in this case is something like `-n - m`. But the selection we'll end up trying to create will be `m - (rows - n)`. This range may very well contain NULL rows. To deal with this, we simply cancel the selection.
2020-05-16selection/render: sync cells' 'selected' bit before renderingDaniel Eklöf-0/+1
For performance reasons, we track whether a cell is selected or not using a bit in a cell's attributes. This makes it easy for the renderer to determine if the cells should be rendered as selected or not - it just have to look at the 'selected' bit instead of doing a complex range check against the current selection. This works nicely in most cases. But, if the cell is updated, the 'selected' bit is cleared. This results in the renderer rendering the cell normally, i.e. _not_ selected. Checking for this, and re-setting the 'selected' bit when the cell is updated (printed to) is way too expensive as it is in the hot path. Instead, sync the 'selected' bits just before rendering. This isn't so bad as it may sound; if there is no selection this is a no-op. Even if there is a selection, only those cells whose 'selected' bit have been cleared are dirtied (and thus re-rendered) - these cells would have been re-rendered anyway.
2020-05-16selection: on_row_in_view() -> on_rows_in_view(), and now takes a rangeDaniel Eklöf-1/+1
This allows us to check the selection once when scrolling, instead of once for each scrolled in line.
2020-04-04selection: add selection_extend()Daniel Eklöf-0/+1
This function extends an existing selection in the following way: If the extension point is *before* the upper boundary of the current selection, extend the selection upwards. If the extension point is *after* the bottom boundary of the current selection, extend the selection downwards. If the extension point is *inside* the current selection, shrink the selection such that the new size is maximized. This means we move the *closest* start/end point from in the current selection.
2020-01-03selection: track selection type; normal or block selectionDaniel Eklöf-1/+2
2019-11-05selection: document the asynchronous behavior of text_from_{primary,clipboard}Daniel Eklöf-1/+17
2019-11-05selection: text_from_{clipboard,primary}: add 'done' callbackDaniel Eklöf-3/+4
This callback is *always* called, including when there has been an error. This is in preparation for making text_from_{clipboard,primary} asynchronous.
2019-08-09osc: implement copy/paste to/from primaryDaniel Eklöf-1/+9
2019-08-09input: don't paste from primary if client is mouse trackingDaniel Eklöf-0/+1
2019-08-06selection/input: triple click selects an entire rowDaniel Eklöf-0/+1
2019-08-05term: cancel selection when scrolling wrapsDaniel Eklöf-0/+1
If we scroll enough, we'll eventually end up wrapping around the entire scrollback buffer. At this point, a selection is no longer valid, so cancel it. Note: this was very obvious when scrolling in the alt screen, since its scrollback buffer is what you see on the screen (i.e. it has no scrollback).
2019-08-05selection: mark-word using spaces only as word separatorDaniel Eklöf-1/+3
When the user double-clicks with ctrl pressed, we now select the word under the cursor using spaces only as word separator.
2019-07-19selection: add text_from_clipboard()Daniel Eklöf-0/+4
This function reads data from the clipboard, and calls a user-provided callback for each chunk of clipboard data.
2019-07-19selection: add text_to_clipboard()Daniel Eklöf-0/+2
This function takes a string and makes it available to the clipboard.
2019-07-17selection: implement double-click-to-select-wordDaniel Eklöf-0/+1
2019-07-11selection: implement copy *to* primaryDaniel Eklöf-1/+1
2019-07-11selection: add support for pasting *from* primaryDaniel Eklöf-0/+1
2019-07-11selection: add selection_from_primary() API (stub for now)Daniel Eklöf-0/+1
2019-07-11selection: add support for pasting from clipboardDaniel Eklöf-0/+2
2019-07-11selection: initial copy-to-clipboard functionalityDaniel Eklöf-0/+5
2019-07-11selection: spell 'finalize' correctlyDaniel Eklöf-1/+1
2019-07-11selection: add a selection APIDaniel Eklöf-0/+8