<feed xmlns='http://www.w3.org/2005/Atom'>
<title>mirrors/foot.git/selection.c, branch 1.8.1</title>
<subtitle>A fast, lightweight and minimalistic Wayland terminal emulator</subtitle>
<id>https://git.0x0f.dev/mirrors/foot.git/atom?h=1.8.1</id>
<link rel='self' href='https://git.0x0f.dev/mirrors/foot.git/atom?h=1.8.1'/>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/'/>
<updated>2021-06-24T15:30:49Z</updated>
<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>selection: add support for TEXT/STRING/UTF8_STRING mime-types in incoming offers</title>
<updated>2021-06-09T09:23:55Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-09T07:51:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=49bb00fb64a2af6c677530e07378dafe6d9cbfa2'/>
<id>urn:sha1:49bb00fb64a2af6c677530e07378dafe6d9cbfa2</id>
<content type='text'>
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
</content>
</entry>
<entry>
<title>selection: reset ‘empty_count’ after we’ve emitted the empty cells</title>
<updated>2021-06-05T11:41:17Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-05T11:41:17Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=0de55182ac6f9f69843aa3bbcaaba0adf896e323'/>
<id>urn:sha1:0de55182ac6f9f69843aa3bbcaaba0adf896e323</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>selection: fix bad assertion</title>
<updated>2021-06-02T18:13:52Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-02T17:29:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=cb83d60089d9acad356d731323dca3f9fdfcc3b2'/>
<id>urn:sha1:cb83d60089d9acad356d731323dca3f9fdfcc3b2</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>selection: pay attention to hard linebreaks when search for word boundaries</title>
<updated>2021-05-31T15:15:20Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-31T15:12:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=f0041882f1dab1fda828c3b9ac7e37cb3682640d'/>
<id>urn:sha1:f0041882f1dab1fda828c3b9ac7e37cb3682640d</id>
<content type='text'>
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
</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>extract: add extract_finish_wide(), and optionally skip stripping trailing empty cells</title>
<updated>2021-05-17T16:14:09Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-28T19:04:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=1bc9fd5fe14a60db861fb317f731a5e27e857bf3'/>
<id>urn:sha1:1bc9fd5fe14a60db861fb317f731a5e27e857bf3</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>selection: expose find_word_boundary_{left,right}()</title>
<updated>2021-05-17T16:14:09Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-28T19:03:53Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=eab874eb06de11763683f312e6c1557319788cee'/>
<id>urn:sha1:eab874eb06de11763683f312e6c1557319788cee</id>
<content type='text'>
</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>selection: don’t strip formatting C0 control characters in bracketed paste mode</title>
<updated>2021-02-12T14:59:07Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-02-12T09:03:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=0da766e50540fbb92b2cb510dab13eee054b097c'/>
<id>urn:sha1:0da766e50540fbb92b2cb510dab13eee054b097c</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>Convert all but 2 remaining uses of xassert(false) to BUG("...")</title>
<updated>2021-02-10T09:01:51Z</updated>
<author>
<name>Craig Barnes</name>
<email>craigbarnes@protonmail.com</email>
</author>
<published>2021-02-10T09:01:51Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=3c86af52c2a3e9352a88e969392575e55c3b6f74'/>
<id>urn:sha1:3c86af52c2a3e9352a88e969392575e55c3b6f74</id>
<content type='text'>
</content>
</entry>
<entry>
<title>selection: remove selection_enabled()</title>
<updated>2021-02-02T08:52:22Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-02-02T08:52:22Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=eff8481cdc6c37407faaa3167ea6f6897b12f544'/>
<id>urn:sha1:eff8481cdc6c37407faaa3167ea6f6897b12f544</id>
<content type='text'>
Its name did not reflect its semantics. Since it was only used in a
single place, “inline” it there, and get rid of it.
</content>
</entry>
<entry>
<title>selection: don’t replace \r\n and \n with \r in bracketed paste mode</title>
<updated>2021-01-27T09:44:28Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-01-27T09:44:28Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=81fb756ea7d10c623b9720548c3a6ce12e381971'/>
<id>urn:sha1:81fb756ea7d10c623b9720548c3a6ce12e381971</id>
<content type='text'>
</content>
</entry>
<entry>
<title>selection: remove duplicate ‘ESC’ in switch case</title>
<updated>2021-01-26T18:31:23Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-01-23T10:30:32Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=49d6dbd761af1dded9e78076dd1a6049c68f82a0'/>
<id>urn:sha1:49d6dbd761af1dded9e78076dd1a6049c68f82a0</id>
<content type='text'>
</content>
</entry>
<entry>
<title>selection: DEL is 0x7f, not 0x1f</title>
<updated>2021-01-26T18:31:23Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-01-23T10:29:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=e70776fc8c24dee1d34029b3aa51a89ab899ef4d'/>
<id>urn:sha1:e70776fc8c24dee1d34029b3aa51a89ab899ef4d</id>
<content type='text'>
</content>
</entry>
<entry>
<title>selection: codespell: stript -&gt; strip</title>
<updated>2021-01-26T18:31:23Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-01-23T10:28:41Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=9e5ef6efac995672ea608b04927a5a5d3ce8b51c'/>
<id>urn:sha1:9e5ef6efac995672ea608b04927a5a5d3ce8b51c</id>
<content type='text'>
</content>
</entry>
<entry>
<title>selection: strip non-formatting C0, BS, HT and DEL from pasted text</title>
<updated>2021-01-26T18:31:21Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-01-23T10:22:22Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=357af41d7e8889efb369deb7c61def5efd89b12e'/>
<id>urn:sha1:357af41d7e8889efb369deb7c61def5efd89b12e</id>
<content type='text'>
</content>
</entry>
<entry>
<title>selection: unbreak text/uri-list decoding: we’re not using \r, not \n</title>
<updated>2021-01-26T18:31:12Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-01-21T14:18:33Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=b31d0c080b705f910132fe6b77aff09ff0bddd3e'/>
<id>urn:sha1:b31d0c080b705f910132fe6b77aff09ff0bddd3e</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>selection: replace \r\n and \n with \r, and strip \e from pasted text</title>
<updated>2021-01-26T18:31:12Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-01-20T18:20:03Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5168aa72cd43f42572ea32358c115a38f52a6032'/>
<id>urn:sha1:5168aa72cd43f42572ea32358c115a38f52a6032</id>
<content type='text'>
Closes #305
Closes #306
</content>
</entry>
</feed>
