Terminal: Add keyboard shortcuts for backspace

Adds Keyboard shortcuts to delete a word to the left
and the full line to the left.

Fixes: QTCREATORBUG-30635
Change-Id: I73681728af9662d104a24d43a73794e33a4a961c
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-11-21 13:48:36 +01:00
parent a18e24f94f
commit bfbe49f81a
3 changed files with 24 additions and 0 deletions

View File

@@ -18,5 +18,7 @@ constexpr char MOVECURSORWORDRIGHT[] = "Terminal.MoveCursorWordRight";
constexpr char CLEAR_TERMINAL[] = "Terminal.ClearTerminal";
constexpr char TOGGLE_KEYBOARD_LOCK[] = "Terminal.ToggleKeyboardLock";
constexpr char SELECTALL[] = "Terminal.SelectAll";
constexpr char DELETE_WORD_LEFT[] = "Terminal.DeleteWordLeft";
constexpr char DELETE_LINE_LEFT[] = "Terminal.DeleteLineLeft";
} // namespace Terminal::Constants

View File

@@ -313,6 +313,16 @@ void TerminalWidget::setupActions()
selectAllAction.addOnTriggered(this, &TerminalWidget::selectAll);
m_selectAll = make_registered(selectAllAction);
ActionBuilder deleteWordLeft(this, Constants::DELETE_WORD_LEFT);
deleteWordLeft.setContext(m_context);
deleteWordLeft.addOnTriggered(this, [this]() { writeToPty("\x17"); });
m_deleteWordLeft = make_registered(deleteWordLeft);
ActionBuilder deleteLineLeft(this, Constants::DELETE_LINE_LEFT);
deleteLineLeft.setContext(m_context);
deleteLineLeft.addOnTriggered(this, [this]() { writeToPty("\x15"); });
m_deleteLineLeft = make_registered(deleteLineLeft);
// Ctrl+Q, the default "Quit" shortcut, is a useful key combination in a shell.
// It can be used in combination with Ctrl+S to pause a program, and resume it with Ctrl+Q.
// So we unlock the EXIT command only for macOS where the default is Cmd+Q to quit.
@@ -692,6 +702,16 @@ void TerminalWidget::initActions(QObject *parent)
moveCursorWordRightAction.setText(Tr::tr("Move Cursor Word Right"));
moveCursorWordRightAction.setContext(context);
moveCursorWordRightAction.setDefaultKeySequence({QKeySequence("Alt+Right")});
ActionBuilder deleteWordLeft(parent, Constants::DELETE_WORD_LEFT);
deleteWordLeft.setText(Tr::tr("Delete Word Left"));
deleteWordLeft.setContext(context);
deleteWordLeft.setDefaultKeySequence({QKeySequence("Alt+Backspace")});
ActionBuilder deleteLineLeft(parent, Constants::DELETE_LINE_LEFT);
deleteLineLeft.setText(Tr::tr("Delete Line Left"));
deleteLineLeft.setContext(context);
deleteLineLeft.setDefaultKeySequence({QKeySequence("Ctrl+Backspace")});
}
void TerminalWidget::unlockGlobalAction(const Utils::Id &commandId)

View File

@@ -107,6 +107,8 @@ private:
RegisteredAction m_selectAll;
RegisteredAction m_moveCursorWordLeft;
RegisteredAction m_moveCursorWordRight;
RegisteredAction m_deleteWordLeft;
RegisteredAction m_deleteLineLeft;
Internal::ShortcutMap m_shortcutMap;