<feed xmlns='http://www.w3.org/2005/Atom'>
<title>mirrors/foot.git/search.c, branch 1.9.0</title>
<subtitle>A fast, lightweight and minimalistic Wayland terminal emulator</subtitle>
<id>https://git.0x0f.dev/mirrors/foot.git/atom?h=1.9.0</id>
<link rel='self' href='https://git.0x0f.dev/mirrors/foot.git/atom?h=1.9.0'/>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/'/>
<updated>2021-07-22T15:57:52Z</updated>
<entry>
<title>search: redraw search box after selection has been cancelled</title>
<updated>2021-07-22T15:57:52Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-22T15:57:25Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=7092a72ce4554ac8b5261eeb7a26182cda8f927e'/>
<id>urn:sha1:7092a72ce4554ac8b5261eeb7a26182cda8f927e</id>
<content type='text'>
</content>
</entry>
<entry>
<title>search: reset match state when selection is cancelled</title>
<updated>2021-07-22T15:57:43Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-22T15:53:29Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=251545203baa65364e491ddbe71ab3f8080bfe25'/>
<id>urn:sha1:251545203baa65364e491ddbe71ab3f8080bfe25</id>
<content type='text'>
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
</content>
</entry>
<entry>
<title>composed: store compose chains in a binary search tree</title>
<updated>2021-06-24T15:30:49Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-24T11:17:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=fe8ca23cfee77a6cac433892755dd7455e354a9d'/>
<id>urn:sha1:fe8ca23cfee77a6cac433892755dd7455e354a9d</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>wip: grapheme shaping</title>
<updated>2021-06-24T15:30:45Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2020-08-20T17:25:35Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=b9ef703eb14ba2357b847b62a715b4e97f690209'/>
<id>urn:sha1:b9ef703eb14ba2357b847b62a715b4e97f690209</id>
<content type='text'>
</content>
</entry>
<entry>
<title>search: don’t crash when we don’t have any XKB compose state</title>
<updated>2021-06-16T15:44:14Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-16T15:44:14Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=11829931a78dab3a36412c9a012ce7bd17eb5449'/>
<id>urn:sha1:11829931a78dab3a36412c9a012ce7bd17eb5449</id>
<content type='text'>
</content>
</entry>
<entry>
<title>search: match_to_end_of_word(): we update the selection ourselves</title>
<updated>2021-05-17T16:14:10Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-30T12:40:59Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=96b19212d34ffb713927d28669ad0b2f011f4598'/>
<id>urn:sha1:96b19212d34ffb713927d28669ad0b2f011f4598</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>extract: move ‘strip_trailing_empty’ parameter from extra_finish() to extract_begin()</title>
<updated>2021-05-17T16:14:10Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-30T12:40:21Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=a6d9f01c0d1d914362b73eacd89e1e09877632cb'/>
<id>urn:sha1:a6d9f01c0d1d914362b73eacd89e1e09877632cb</id>
<content type='text'>
</content>
</entry>
<entry>
<title>search: find_next(): correctly wrap row number</title>
<updated>2021-05-17T16:14:10Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-30T12:29:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=0945e71572c853dfdeedc90b512668ab946a5468'/>
<id>urn:sha1:0945e71572c853dfdeedc90b512668ab946a5468</id>
<content type='text'>
</content>
</entry>
<entry>
<title>search: match_to_end_of_word(): use a local macro to bump coord</title>
<updated>2021-05-17T16:14:10Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-30T11:49:30Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5e621bbdb9aa612b79d2e2e2278561a9602d3f8f'/>
<id>urn:sha1:5e621bbdb9aa612b79d2e2e2278561a9602d3f8f</id>
<content type='text'>
</content>
</entry>
<entry>
<title>search: match_to_end_of_word(): use has_wrapped_around() while extracting text</title>
<updated>2021-05-17T16:14:10Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-28T19:16:42Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=1c8bdf34ced8f263d61293f3559b2dd570a1c23c'/>
<id>urn:sha1:1c8bdf34ced8f263d61293f3559b2dd570a1c23c</id>
<content type='text'>
</content>
</entry>
<entry>
<title>search: match_to_end_of_word(): we always extend the selection with at least one character</title>
<updated>2021-05-17T16:14:10Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-28T19:15:39Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=11f7a6616b8d4636c8df513cd5626f7ca66017b5'/>
<id>urn:sha1:11f7a6616b8d4636c8df513cd5626f7ca66017b5</id>
<content type='text'>
</content>
</entry>
<entry>
<title>search: match_to_end_of_word(): skip newlines when copying from extraction buffer</title>
<updated>2021-05-17T16:14:10Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-28T19:11:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=7cf0e2aae40f83d6a830165776d52476a457596a'/>
<id>urn:sha1:7cf0e2aae40f83d6a830165776d52476a457596a</id>
<content type='text'>
</content>
</entry>
<entry>
<title>search: match_to_end_of_word(): refactor</title>
<updated>2021-05-17T16:14:10Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-28T19:06:21Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=e460727afd5fb19ed8bf42d6ecbbd9e9f98a20c5'/>
<id>urn:sha1:e460727afd5fb19ed8bf42d6ecbbd9e9f98a20c5</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>search: find_next(): proper check for scrollback wrap around</title>
<updated>2021-05-17T16:14:09Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-28T18:59:35Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=e415f858295ced5dbb1a0af961c4307c92b0c634'/>
<id>urn:sha1:e415f858295ced5dbb1a0af961c4307c92b0c634</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>term: rename CELL_MULT_COL_SPACER -&gt; CELL_SPACER, and change its definition</title>
<updated>2021-05-14T12:41:02Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-14T12:41:02Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=d9e1aefb9173857f0632227de5ac368a505c69bf'/>
<id>urn:sha1:d9e1aefb9173857f0632227de5ac368a505c69bf</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>search: when matching cell content, treat empty cells as spaces</title>
<updated>2021-03-28T11:21:18Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-27T21:15:44Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=2b7c5db1880b54120841c441518108795cb85815'/>
<id>urn:sha1:2b7c5db1880b54120841c441518108795cb85815</id>
<content type='text'>
</content>
</entry>
<entry>
<title>input: rewrite of how we match foot’s own key bindings</title>
<updated>2021-03-04T08:43:43Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-02-27T19:42:31Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5e64e06a550c2499a23f03749986791136cbbcb9'/>
<id>urn:sha1:5e64e06a550c2499a23f03749986791136cbbcb9</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>wayland: drop ‘_surface’ suffix from subsurface struct instances</title>
<updated>2021-02-17T20:48:08Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-02-12T11:00:40Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5c8579043dd22a08e872d90a20011f5d6d8d3dc1'/>
<id>urn:sha1:5c8579043dd22a08e872d90a20011f5d6d8d3dc1</id>
<content type='text'>
</content>
</entry>
<entry>
<title>search: use wayl_win_subsurface_new/destroy()</title>
<updated>2021-02-17T20:48:07Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-02-12T10:47:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=e049124f6d57fb2fd444138ec588b5b3cab80ecc'/>
<id>urn:sha1:e049124f6d57fb2fd444138ec588b5b3cab80ecc</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Convert some more uses of xassert(false) to BUG("...")</title>
<updated>2021-02-09T15:16:19Z</updated>
<author>
<name>Craig Barnes</name>
<email>craigbarnes@protonmail.com</email>
</author>
<published>2021-02-09T15:16:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=2f81a1d07c3828391bf1b5656a9143aaf3822089'/>
<id>urn:sha1:2f81a1d07c3828391bf1b5656a9143aaf3822089</id>
<content type='text'>
</content>
</entry>
</feed>
