forked from qt-creator/qt-creator
Terminal: Support Alt+Left / Alt+Right cursor move
Fixes: QTCREATORBUG-28941 Change-Id: I7c8e012733f6dcb2851e8e1b840d53317e413cd8 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -18,6 +18,8 @@ namespace Terminal {
|
|||||||
constexpr char COPY[] = "Terminal.Copy";
|
constexpr char COPY[] = "Terminal.Copy";
|
||||||
constexpr char PASTE[] = "Terminal.Paste";
|
constexpr char PASTE[] = "Terminal.Paste";
|
||||||
constexpr char CLEARSELECTION[] = "Terminal.ClearSelection";
|
constexpr char CLEARSELECTION[] = "Terminal.ClearSelection";
|
||||||
|
constexpr char MOVECURSORWORDLEFT[] = "Terminal.MoveCursorWordLeft";
|
||||||
|
constexpr char MOVECURSORWORDRIGHT[] = "Terminal.MoveCursorWordRight";
|
||||||
|
|
||||||
constexpr char NEWTERMINAL[] = "Terminal.NewTerminal";
|
constexpr char NEWTERMINAL[] = "Terminal.NewTerminal";
|
||||||
constexpr char CLOSETERMINAL[] = "Terminal.CloseTerminal";
|
constexpr char CLOSETERMINAL[] = "Terminal.CloseTerminal";
|
||||||
@@ -60,6 +62,16 @@ void TerminalCommands::initWidgetActions(const Core::Context &context)
|
|||||||
CLEARSELECTION);
|
CLEARSELECTION);
|
||||||
command->setDefaultKeySequence(QKeySequence("Esc"));
|
command->setDefaultKeySequence(QKeySequence("Esc"));
|
||||||
m_commands.push_back(command);
|
m_commands.push_back(command);
|
||||||
|
|
||||||
|
command = ActionManager::instance()->registerAction(&m_widgetActions.moveCursorWordLeft,
|
||||||
|
MOVECURSORWORDLEFT);
|
||||||
|
command->setDefaultKeySequence(QKeySequence("Alt+Left"));
|
||||||
|
m_commands.push_back(command);
|
||||||
|
|
||||||
|
command = ActionManager::instance()->registerAction(&m_widgetActions.moveCursorWordRight,
|
||||||
|
MOVECURSORWORDRIGHT);
|
||||||
|
command->setDefaultKeySequence(QKeySequence("Alt+Right"));
|
||||||
|
m_commands.push_back(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalCommands::initPaneActions(const Core::Context &context)
|
void TerminalCommands::initPaneActions(const Core::Context &context)
|
||||||
@@ -113,12 +125,19 @@ void TerminalCommands::initGlobalCommands()
|
|||||||
|
|
||||||
bool TerminalCommands::triggerAction(QKeyEvent *event)
|
bool TerminalCommands::triggerAction(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
|
QKeyCombination combination = event->keyCombination();
|
||||||
|
|
||||||
|
// On macOS, the arrow keys include the KeypadModifier, which we don't want.
|
||||||
|
if (HostOsInfo::isMacHost() && combination.keyboardModifiers() & Qt::KeypadModifier)
|
||||||
|
combination = QKeyCombination(combination.keyboardModifiers() & ~Qt::KeypadModifier,
|
||||||
|
combination.key());
|
||||||
|
|
||||||
for (const auto &command : TerminalCommands::instance().m_commands) {
|
for (const auto &command : TerminalCommands::instance().m_commands) {
|
||||||
if (!command->action()->isEnabled())
|
if (!command->action()->isEnabled())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (const auto &shortcut : command->keySequences()) {
|
for (const auto &shortcut : command->keySequences()) {
|
||||||
const auto result = shortcut.matches(QKeySequence(event->keyCombination()));
|
const auto result = shortcut.matches(QKeySequence(combination));
|
||||||
if (result == QKeySequence::ExactMatch) {
|
if (result == QKeySequence::ExactMatch) {
|
||||||
command->action()->trigger();
|
command->action()->trigger();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ struct WidgetActions
|
|||||||
QAction paste{Tr::tr("Paste")};
|
QAction paste{Tr::tr("Paste")};
|
||||||
QAction clearSelection{Tr::tr("Clear Selection")};
|
QAction clearSelection{Tr::tr("Clear Selection")};
|
||||||
QAction clearTerminal{Tr::tr("Clear Terminal")};
|
QAction clearTerminal{Tr::tr("Clear Terminal")};
|
||||||
|
QAction moveCursorWordLeft{Tr::tr("Move Cursor Word Left")};
|
||||||
|
QAction moveCursorWordRight{Tr::tr("Move Cursor Word Right")};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PaneActions
|
struct PaneActions
|
||||||
|
|||||||
@@ -234,6 +234,8 @@ void TerminalWidget::setupActions()
|
|||||||
connect(&a.paste, &QAction::triggered, this, ifHasFocus(&TerminalWidget::pasteFromClipboard));
|
connect(&a.paste, &QAction::triggered, this, ifHasFocus(&TerminalWidget::pasteFromClipboard));
|
||||||
connect(&a.clearSelection, &QAction::triggered, this, ifHasFocus(&TerminalWidget::clearSelection));
|
connect(&a.clearSelection, &QAction::triggered, this, ifHasFocus(&TerminalWidget::clearSelection));
|
||||||
connect(&a.clearTerminal, &QAction::triggered, this, ifHasFocus(&TerminalWidget::clearContents));
|
connect(&a.clearTerminal, &QAction::triggered, this, ifHasFocus(&TerminalWidget::clearContents));
|
||||||
|
connect(&a.moveCursorWordLeft, &QAction::triggered, this, ifHasFocus(&TerminalWidget::moveCursorWordLeft));
|
||||||
|
connect(&a.moveCursorWordRight, &QAction::triggered, this, ifHasFocus(&TerminalWidget::moveCursorWordRight));
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,6 +404,16 @@ void TerminalWidget::zoomOut()
|
|||||||
setFont(m_font);
|
setFont(m_font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TerminalWidget::moveCursorWordLeft()
|
||||||
|
{
|
||||||
|
writeToPty("\x1b\x62");
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalWidget::moveCursorWordRight()
|
||||||
|
{
|
||||||
|
writeToPty("\x1b\x66");
|
||||||
|
}
|
||||||
|
|
||||||
void TerminalWidget::clearContents()
|
void TerminalWidget::clearContents()
|
||||||
{
|
{
|
||||||
m_surface->clearAll();
|
m_surface->clearAll();
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ public:
|
|||||||
void zoomIn();
|
void zoomIn();
|
||||||
void zoomOut();
|
void zoomOut();
|
||||||
|
|
||||||
|
void moveCursorWordLeft();
|
||||||
|
void moveCursorWordRight();
|
||||||
|
|
||||||
void clearContents();
|
void clearContents();
|
||||||
|
|
||||||
struct Selection
|
struct Selection
|
||||||
|
|||||||
Reference in New Issue
Block a user