Skip to content

Commit

Permalink
chore: 为Ctrl+鼠标左键点击移动光标功能新增配置
Browse files Browse the repository at this point in the history
放置影响用户使用,新增配置,允许用户在配置中选择是否启用
默认不启用

Log: 为Ctrl+鼠标左键点击移动光标功能新增配置
  • Loading branch information
DaiZW007 authored and ArchieMeng committed May 7, 2024
1 parent 01f2122 commit eb4bd19
Show file tree
Hide file tree
Showing 9 changed files with 1,678 additions and 1,845 deletions.
3,482 changes: 1,638 additions & 1,844 deletions 3rdparty/terminalwidget/lib/TerminalDisplay.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions 3rdparty/terminalwidget/lib/TerminalDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ private slots:
bool _blinking; // hide text in paintEvent
bool _hasBlinker; // has characters to blink
bool _cursorBlinking; // hide cursor in paintEvent
bool _cursorPositionSetEnable; // set cursor position enable
bool _hasBlinkingCursor; // has blinking cursor enabled
bool _allowBlinkingText; // allow text to blink
bool _ctrlDrag; // require Ctrl key for drag
Expand Down Expand Up @@ -926,6 +927,7 @@ private slots:
}

QScrollBar* getScrollBar() {return _scrollBar;}
void setCursorPositionEnable(bool enable);
};

class AutoScrollHandler : public QObject
Expand Down
7 changes: 6 additions & 1 deletion 3rdparty/terminalwidget/lib/qtermwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void QTermWidget::addSnapShotTimer()
m_termDisplay = m_impl->m_terminalDisplay;
connect(m_interactionTimer, &QTimer::timeout, this, &QTermWidget::snapshot);
connect(m_termDisplay.data(), &Konsole::TerminalDisplay::keyPressedSignal, this, &QTermWidget::interactionHandler);
connect(currSession, &Session::almostFinished, m_termDisplay, [=] {
connect(currSession, &Session::almostFinished, m_termDisplay, [ = ] {
connect(m_termDisplay, &TerminalDisplay::keyPressedSignal, currSession, &Session::finished);
});

Expand Down Expand Up @@ -372,6 +372,11 @@ void QTermWidget::setNoHasSelect()
m_bHasSelect = false;
}

void QTermWidget::enableSetCursorPosition(bool enable)
{
m_impl->m_terminalDisplay->setCursorPositionEnable(enable);
}

/*******************************************************************************
1. @函数: getisAllowScroll
2. @作者: ut000610 戴正文
Expand Down
2 changes: 2 additions & 0 deletions 3rdparty/terminalwidget/lib/qtermwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ class TERMINALWIDGET_EXPORT QTermWidget : public QWidget
//避免搜索框隐藏再显示之后,继续走m_bHasSelect为true流程,导致崩溃
void setNoHasSelect();

// 是否允许ctrl + 鼠标左键移动光标
void enableSetCursorPosition(bool enable);
signals:
void finished();
void copyAvailable(bool);
Expand Down
6 changes: 6 additions & 0 deletions src/assets/other/default-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@
"type": "checkbox",
"text": "Copy on select",
"default": true
},
{
"key": "set_cursor_position",
"type": "checkbox",
"text": "Allow Ctrl + left mouse click to set cursor position",
"default": false
}
]
},
Expand Down
10 changes: 10 additions & 0 deletions src/settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ void Settings::initConnection()
emit wordCharactersChanged(value.toString());
});

QPointer<DSettingsOption> cursorPositionSet = settings->option("advanced.cursor.set_cursor_position");
connect(cursorPositionSet, &Dtk::Core::DSettingsOption::valueChanged, this, [ = ](QVariant value) {
emit enableSetCursorPosition(value.toBool());
});

QPointer<DSettingsOption> backgroundBlur = settings->option("basic.interface.blurred_background");
connect(backgroundBlur, &Dtk::Core::DSettingsOption::valueChanged, this, [ = ](QVariant value) {
emit backgroundBlurChanged(value.toBool());
Expand Down Expand Up @@ -472,6 +477,11 @@ bool Settings::cursorBlink() const
return settings->option("advanced.cursor.cursor_blink")->value().toBool();
}

bool Settings::enableSetCursorPosition() const
{
return settings->option("advanced.cursor.set_cursor_position")->value().toBool();
}

bool Settings::backgroundBlur() const
{
return settings->option("basic.interface.blurred_background")->value().toBool();
Expand Down
6 changes: 6 additions & 0 deletions src/settings/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class Settings : public QObject
* @return
*/
bool cursorBlink() const;
/**
* @brief enableSetCursorPosition
* @return
*/
bool enableSetCursorPosition() const;
/**
* @brief 设置界面获取背景模糊属性
* @author ut001121 zhangmeng
Expand Down Expand Up @@ -296,6 +301,7 @@ class Settings : public QObject
void opacityChanged(qreal opacity);
void cursorShapeChanged(int shape);
void cursorBlinkChanged(bool blink);
void enableSetCursorPosition(bool enable);
void backgroundBlurChanged(bool enabled);
void pressingScrollChanged(bool enabled);
void OutputScrollChanged(bool enabled);
Expand Down
2 changes: 2 additions & 0 deletions src/settings/settings_translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,6 @@ void GenerateSettingTranslate()
Q_UNUSED(history_size);
auto include_special_characters_in_double_click_selectionisText = QObject::tr("Include special character(s) in double click selections");
Q_UNUSED(include_special_characters_in_double_click_selectionisText);
auto set_cursor_position = QObject::tr("Allow Ctrl + left mouse click to set cursor position");
Q_UNUSED(set_cursor_position);
}
6 changes: 6 additions & 0 deletions src/views/termwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ TermWidget::TermWidget(const TermProperties &properties, QWidget *parent) : QTer
setKeyboardCursorShape(static_cast<QTermWidget::KeyboardCursorShape>(Settings::instance()->cursorShape()));
// 光标闪烁
setBlinkingCursor(Settings::instance()->cursorBlink());
// 是否允许移动光标
enableSetCursorPosition(Settings::instance()->enableSetCursorPosition());

// 按键滚动
setPressingScroll(Settings::instance()->PressingScroll());
Expand Down Expand Up @@ -1127,6 +1129,10 @@ void TermWidget::onSettingValueChanged(const QString &keyName)
return;
}

if ("advanced.cursor.set_cursor_position" == keyName) {
enableSetCursorPosition(Settings::instance()->enableSetCursorPosition());
}

if ("advanced.scroll.scroll_on_key" == keyName) {
setPressingScroll(Settings::instance()->PressingScroll());
return;
Expand Down

0 comments on commit eb4bd19

Please sign in to comment.