Skip to content

Simplify key_press_cb

Previously key_press_cb had several checks for whether the user was holding down control or alt. There were 3 ways to handle it:

  1. Ignore it. This is what backspace and delete do. Holding down control or alt with those two did nothing.
  2. Do nothing. Some keys, like page up or page down, had special checks so they would do nothing when control or alt were held. There was also one big check that coverered most keys. In all cases, the expectation was that the user might be trying to perform a keyboard shortcut, and we should allow the GTK shortcuts system to handle this.
  3. Two keys had special handling for control: home and end. These two modified their behavior to move to the beginning or end of the document instead of just the line.

Since only two keys cared about control and none cared about alt, I moved the special handling of ctrl+home and +end to separate shortcuts. I also added documentation for them to the keyboard shortcuts overlay. Now we can skip the whole key_press_cb when control or alt is pressed.

Besides the simplification to key_press_cb, this comes with two side effects:

  1. Previously, the "are we selecting something" flag was set or reset based on whether the shift key was held, even in cases where we decided to return early because we wanted a shortcut to handle the keypress. Now keyboard shortcuts will be able to see the unmodified selection flag.
  2. Backspace and delete, which used to ignore control and alt, now do nothing when control or alt is held. As a benefit, this could make it possible to add shortcuts for ctrl+backspace, ctrl+del, etc. However, if users expected ctrl+backspace to behave the same as backspace, it no longer will.

Merge request reports