Commit graph

113 commits

Author SHA1 Message Date
Daniel Eklöf
96b19212d3
search: match_to_end_of_word(): we update the selection ourselves
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.
2021-05-17 18:14:10 +02:00
Daniel Eklöf
a6d9f01c0d
extract: move ‘strip_trailing_empty’ parameter from extra_finish() to extract_begin() 2021-05-17 18:14:10 +02:00
Daniel Eklöf
0945e71572
search: find_next(): correctly wrap row number 2021-05-17 18:14:10 +02:00
Daniel Eklöf
5e621bbdb9
search: match_to_end_of_word(): use a local macro to bump coord 2021-05-17 18:14:10 +02:00
Daniel Eklöf
1c8bdf34ce
search: match_to_end_of_word(): use has_wrapped_around() while extracting text 2021-05-17 18:14:10 +02:00
Daniel Eklöf
11f7a6616b
search: match_to_end_of_word(): we always extend the selection with at least one character 2021-05-17 18:14:10 +02:00
Daniel Eklöf
7cf0e2aae4
search: match_to_end_of_word(): skip newlines when copying from extraction buffer 2021-05-17 18:14:10 +02:00
Daniel Eklöf
e460727afd
search: match_to_end_of_word(): refactor
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.
2021-05-17 18:14:10 +02:00
Daniel Eklöf
e415f85829
search: find_next(): proper check for scrollback wrap around
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.
2021-05-17 18:14:09 +02:00
Daniel Eklöf
d9e1aefb91
term: rename CELL_MULT_COL_SPACER -> CELL_SPACER, and change its definition
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-05-14 14:41:02 +02:00
Daniel Eklöf
2b7c5db188
search: when matching cell content, treat empty cells as spaces 2021-03-28 13:21:18 +02:00
Daniel Eklöf
5e64e06a55
input: rewrite of how we match foot’s own key bindings
Bindings are matched in one out of three ways:

* By translated (by XKB) symbols
* By untranslated symbols
* By raw key codes

A translated symbol is affected by pressed modifiers, some of which
can be “consumed”. Consumed modifiers to not partake in the comparison
with the binding’s modifiers. In this mode, ctrl+shift+2 maps to
ctrl+@ on a US layout.

Untranslated symbols, or un-shifted symbols refer to the “base” symbol
of the pressed key, i.e. it’s unaffected by modifiers. In this mode,
consumed modifiers *do* partake in the comparison with the binding’s
modifiers, and ctrl+shift+2 maps to ctrl+shift+2 on a US layout.

More examples: ctrl+shift+u maps to ctrl+U in the translated lookup,
while ctrl+shift+u maps to ctrl+shift+u in the untranslated lookup.

Finally, we also match raw key codes. This allows our bindings to work
using the same physical keys when the user switches between latin and
non-latin layouts.

This means key bindings in foot.ini *must* not include both +shift+
and a *shifted* key. I.e. ctrl+shift+U is not a valid combo as it
cannot be triggered. Unfortunately, this was how you were supposed to
write bindings up until now... so, we try to detect such bindings, log
a deprecation warning and then “fix” the binding for the user.

When specifying bindings in foot.ini, both ctrl+U and ctrl+shift+u are
valid, and will work. The latter is preferred though, since we cannot
detect the raw key code for the former variant. Personally, I also
prefer the latter one because it is more explicit; it’s more obvious
which keys are involved.

However, in some cases it makes more sense to use the other
variant. Typically for non-letter combos.
2021-03-04 09:43:43 +01:00
Daniel Eklöf
5c8579043d
wayland: drop ‘_surface’ suffix from subsurface struct instances 2021-02-17 21:48:08 +01:00
Daniel Eklöf
e049124f6d
search: use wayl_win_subsurface_new/destroy() 2021-02-17 21:48:07 +01:00
Craig Barnes
2f81a1d07c Convert some more uses of xassert(false) to BUG("...") 2021-02-09 15:16:19 +00:00
Daniel Eklöf
03bac9dada
key-bindings: refactor: use a single type for all key bindings
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.
2021-02-08 10:09:14 +01:00
Daniel Eklöf
2310ffd1b8
search: match composed characters when extending the search string to the next word boundary 2021-01-26 20:26:34 +01:00
Daniel Eklöf
fc33619b19
search: fix matching of multi-column characters
We were matching the sub-sequence SPACERs as if they were regular
characters, which obviously failed.
2021-01-26 20:05:14 +01:00
Daniel Eklöf
dd8a6fdd4d
search: don’t re-scan the scrollback unless the search string actually has changed 2021-01-26 19:29:05 +01:00
Daniel Eklöf
89b810261e
Merge branch 'search-match-composed-characters' 2021-01-26 19:28:21 +01:00
Daniel Eklöf
d3d5897bb7
search: fix matching against composed characters 2021-01-24 12:05:57 +01:00
Daniel Eklöf
cbf90d67a2
search: filter out non-printable characters
Don’t allow non-printable characters in the search input string.
2021-01-24 11:32:45 +01:00
Craig Barnes
e56136ce11 debug: rename assert() to xassert(), to avoid clashing with <assert.h> 2021-01-16 20:16:00 +00:00
Craig Barnes
22f25a9e4f Print stack trace on assert() failure or when calling fatal_error()
Note: this uses the __sanitizer_print_stack_trace() function from the
AddressSanitizer runtime, so it only works when AddressSanitizer is
in use.
2021-01-16 19:56:33 +00:00
Daniel Eklöf
3a9172342f
selection: combine enum selection_kind with selection_semantic 2021-01-06 10:53:27 +01:00
Daniel Eklöf
3afc5a723e
selection: use selection_start() to initialize word/row-based selection
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-04 19:48:41 +01:00
Daniel Eklöf
30de262d29
selection: wip: update selection word-wise when initial selection was by word 2021-01-04 19:48:26 +01:00
Daniel Eklöf
fc2bcf9bc0
search: reset IME state when entering/exiting search mode 2020-12-07 20:44:15 +01:00
Daniel Eklöf
b4a0f5b13b
render: search: glyph_offset is in *cells*, cursor position in *characters*
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*.
2020-12-07 20:44:13 +01:00
Daniel Eklöf
f51ce34753
search: new function: search_add_chars()
This function inserts a string into the search buffer, at the current
insertion point (i.e. where the cursor is).
2020-12-07 20:44:12 +01:00
Daniel Eklöf
f3e6941c9a
search: add {clipboard,primary}-paste key bindings
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
2020-11-01 12:39:57 +01:00
Daniel Eklöf
49f4b3da64
config: add ‘[default].word-delimiters’
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
2020-10-09 19:44:23 +02:00
Daniel Eklöf
dabdffafa5
don't use empty struct initializers 2020-08-23 10:07:00 +02:00
Daniel Eklöf
8626b4bc1a
search: don't update/refresh match when modifier keys are pressed 2020-08-12 19:40:50 +02:00
Daniel Eklöf
b01431e38f
search: fix viewport not moving if we tried to move it past the scrollback start
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.
2020-08-12 19:40:40 +02:00
Daniel Eklöf
019b6bc039
fix printf-format errors in 32-bit builds 2020-08-06 23:20:46 +02:00
Daniel Eklöf
9f82cbaa49
search: fix crash when searching the scrollback history
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.
2020-07-25 11:23:54 +02:00
Daniel Eklöf
8d81dde5b8
search: improve viewport movements
* 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.
2020-07-24 17:49:50 +02:00
Daniel Eklöf
ac7b229f7c
search: re-enable search-commit action
This was disabled while implementing multi-seat support, and I forgot
to fix and re-enable before that feature was merged.
2020-07-22 17:51:27 +02:00
Daniel Eklöf
04e566492c
multi-seat: re-enable scrollback search support 2020-07-08 18:20:34 +02:00
Daniel Eklöf
c470825067
wip: multi-seat support
Compiles and runs, but mouse, clipboard and other things have been
disabled.
2020-07-08 16:45:26 +02:00
Daniel Eklöf
69c3e74498
util.h: new header file defining commonly used macros 2020-05-01 11:46:24 +02:00
Daniel Eklöf
c96a0b3b3c
misc: replace all explicit zero-initializers with empty initializers 2020-04-13 12:03:11 +02:00
Daniel Eklöf
d67f437458
mbstate: fix compile warning on systems where mbstate_t isn't an integral
An empty initializer still ensures the entire object is
zero-initialized.
2020-04-13 11:58:38 +02:00
Daniel Eklöf
0419156494
search: replace hard-coded key bindings with "user configurable" ones
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.
2020-03-18 15:30:14 +01:00
Daniel Eklöf
a69b818a62
input: bindings: don't match raw key code alone - mods must also match 2020-03-18 14:52:39 +01:00
Daniel Eklöf
6d30e7d15d
input: bind key bindings to raw key codes too
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).
2020-03-18 14:29:34 +01:00
Daniel Eklöf
0d188895c3
search: add support for user configurable key bindings
No default bindings defined yet, though.
2020-03-08 15:28:47 +01:00
Daniel Eklöf
c5a1af4e53
render: never render CSD and/or search box "immediately"
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.
2020-03-06 19:16:54 +01:00
Daniel Eklöf
7b3fffc6ec
search: don't mark the entire sub-surface as opaque 2020-03-01 13:06:30 +01:00