Ikcelaks / qmk_sequence_transform

Sequence-Transform is a user library for QMK that enables a rich declarative ruleset for transforming a sequence of keypresses into any output you would like.
Apache License 2.0
6 stars 3 forks source link

Enhanced Backspace #18

Closed Ikcelaks closed 8 months ago

Ikcelaks commented 8 months ago

This feature will enhance the handling of backspace so that tapping backspace will undo the entire action of the previous keypress, and leave the buffer in a state where the recent context is identical to before the previous keypress, even if the previous keypress triggered a complicated action.

This draft contains my refactor st_trie_search_result_t so that every feature can get the info they need where and how they need it. Specifically, my feature will need to be able to extract an st_trie_payload_t using just the trie and an offset to the matching node on the trie. The

Please take a look at it and give feedback.

Ikcelaks commented 8 months ago

The code is functional. There are just a few issues remaining.

  1. We need a default method of extending the buffer beyond the max sequence length, since the context shrinks when backspace is use. For example, if these are your rules:
    s*t -> something
    s*m -> sometime

    Your longest sequence is 3. If you type a*ts and then realized that you meant to write "sometimes" and not "somethings", your buffer context is now *ts, so hitting backspace twice and tapping m does not trigger s*m as you would hope, and you caught the error almost as soon as possible. So we need to add some amount of extra headroom in the buffer over just the maximum sequence length.

Ikcelaks commented 8 months ago
  1. Similar to number 1, it is possible that you can run into a situation where it is possible to know how many characters need to be backspaced to undo an action, but the information needed to actually retype the necessary characters has fallen off the bottom of the buffer. With sufficient excess buffer space, this is less likely to occur, but it needs to be handled gracefully. Write now the undo just has amnesia and does a partial restore, where the missing part of the redo is in the middle of the word. It's pretty awful (but hard to trigger).

My suggested solution to this is to delay sending the backspaces until we know that the full undo can be done atomically, and if the full undo cannot be done, fall back to resetting the buffer and send a single backspace like default.

Ikcelaks commented 8 months ago
  1. Holding backspace currently sends only a single tap of backspace. This is a non-trivial issue that we need to experiment with
Ikcelaks commented 8 months ago
  1. We need to retain the Shift status of all key presses. This has a reasonably straight forward solution that I will implement soon.
Ikcelaks commented 8 months ago

I think this is good enough for testing.

The capitalization and incomplete undos when the buffer is too short are still outstanding, but I think this is good enough to be usable now. Please test! This needs so much testing, because it is bad if it breaks in unexpected ways.

Ikcelaks commented 8 months ago

With the last commit, incomplete undies should no longer happen. If the buffer doesn't go back enough to complete an undo, only the single automatic backspace will be sent