code icon indicating copy to clipboard operation
code copied to clipboard

Bug: Ctrl+U does not clear current line in embedded terminal

Open lobre opened this issue 1 month ago • 7 comments

What Happened?

In the embedded terminal inside Code, the keyboard shortcut Ctrl+U doesn’t work as expected.

In most terminals (and in any standard shell using GNU Readline or similar), Ctrl+U is the default shortcut to clear the current line — deleting all text from the cursor back to the start of the line.

This behavior works correctly in elementary Terminal and most other terminal emulators, but not inside Code’s embedded terminal.

Steps to Reproduce

  1. Open Code.
  2. Open the embedded terminal (bottom panel).
  3. Type any command (e.g., echo hello world).
  4. Press Ctrl+U.

Expected Behavior

Expected result:

The current line should be cleared, just like in any standard readline-based terminal.

Actual result:

Nothing happens — the keybinding appears to be ignored.

OS Version

8.x (Circe)

OS Architecture

amd64 (on most hardwares)

Session Type

Secure Session (Wayland)

Software Version

Latest release (I have run all updates)

Log Output


Hardware Info

No response

lobre avatar Nov 06 '25 13:11 lobre

After some investigation I got it to work in Code by disabling the system shortcut for "Enable Unicode Typing" (<Shift><Control>U) This shortcut then has the required effect in the terminal pane. However <Ctrl>U is still not working and it is not at all obvious why. In fact it is not obvious why it works in Terminal. Smart copy-paste (which is not currently implemented in Code) allows you to use e.g. <Ctrl>C instead of <Shift><Ctrl>C but I didnt think it affected the <Ctrl>U shortcut. I'll investigate further.

jeremypw avatar Nov 06 '25 15:11 jeremypw

Can it be because of this?

https://github.com/elementary/code/blob/dca3a350a61e784e049ac012e4396158cd2028df/src/MainWindow.vala#L224

lobre avatar Nov 06 '25 17:11 lobre

Yes! I missed that - thanks. I've never used that accelerator tbh. I don't know how useful it is. I guess it could be changed to something else if it is not standard.

jeremypw avatar Nov 06 '25 18:11 jeremypw

Seems Visual Studioand NotePad use <Control><Shift>U. Outlook and Word use <Shift>F3 I would prefer the former - we could change to that (as well as the corresponding shortcut for lowercase) - except that would clash with the UniCode shortcut 😞

jeremypw avatar Nov 06 '25 18:11 jeremypw

Would it make sense to scope editor-only bindings to the editor widget instead?

Like:

  1. Remove the case-change accelerators from MainWindow.action_accelerators.
  2. Add a Gtk.ShortcutController (or Gtk.EventControllerKey) to DocumentView/SourceView that registers the text-only shortcuts.
  3. In those controller callbacks, call the existing upper/lower functions (or dispatch to the same actions) so behaviour stays identical while the shortcuts only exist when a document view has focus.

That approach could also cover other text-editing bindings—things like duplicate line, clear line, toggle comment, "sort lines", maybe even undo/redo if we ever want the terminal to keep its shell-centric bindings. Meanwhile, global shortcuts (new tab, open folder, toggle sidebar/terminal, global search, quit, etc.) would continue to live in the main action group.

Does that sound too complex?

lobre avatar Nov 08 '25 17:11 lobre

@lobre Yes, I also thought of using ShortcutController to localize the accelerator. It shouldn't cause any confusion I guess because the context is clear. We'll have to wait for the Gtk4 port for that though. I am not sure if is possible in Gtk3.

jeremypw avatar Nov 08 '25 17:11 jeremypw

Good catch, that seems accurate, as there doesn't seem to be a clean, built-in way to scope shortcuts per widget in Gtk3.

It might be a wise decision to keep that aside and wait for the Gtk4 port, then?

lobre avatar Nov 08 '25 20:11 lobre