mirror of
https://github.com/epasveer/seer.git
synced 2026-08-31 09:30:41 +08:00
Merge branch 'main' into 419-automatically-refresh-editor-view-if-source-file-is-modified
This commit is contained in:
@@ -69,6 +69,9 @@ SeerEditorWidgetSourceArea::SeerEditorWidgetSourceArea(QWidget* parent) : SeerPl
|
||||
QObject::connect(this, &SeerEditorWidgetSourceArea::updateRequest, this, &SeerEditorWidgetSourceArea::updateBreakPointArea);
|
||||
QObject::connect(this, &SeerEditorWidgetSourceArea::highlighterSettingsChanged, this, &SeerEditorWidgetSourceArea::handleHighlighterSettingsChanged);
|
||||
|
||||
// Connect cursor position changed signal.
|
||||
QObject::connect(this, &QPlainTextEdit::cursorPositionChanged, this, &SeerEditorWidgetSourceArea::handleCursorPositionChanged);
|
||||
|
||||
setCurrentLine(0);
|
||||
|
||||
updateMarginAreasWidth(0);
|
||||
@@ -2035,3 +2038,43 @@ void SeerEditorWidgetSourceBreakPointArea::mouseReleaseEvent (QMouseEvent* event
|
||||
QWidget::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Functions for mouse navigation feature *
|
||||
**********************************************************************************************************************/
|
||||
void SeerEditorWidgetSourceArea::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::XButton1 || event->button() == Qt::XButton2) {
|
||||
// Avoid the default back/forward action
|
||||
_ignoreThumbMouseEvent ++;
|
||||
SeerCurrentFile firstInfo = readCurrentPosition();
|
||||
// _ignoreThumbMouseEvent will incremented in mousePressEvent when thumb mouse button is pressed but it may not be decremented
|
||||
// if user just click the thumb mouse button without moving the cursor. So here we check if the position is the same as last time,
|
||||
// which means cursor didn't move, then we reset _ignoreThumbMouseEvent to 0 to avoid blocking future events.
|
||||
QTimer::singleShot(30, this, [this, firstInfo]() { // let's give 30 ms for cursor to move to new position
|
||||
SeerCurrentFile secondInfo = readCurrentPosition();
|
||||
if (firstInfo == secondInfo) { // cursor didn't move
|
||||
_ignoreThumbMouseEvent = 0; // reset to 0
|
||||
}
|
||||
} );
|
||||
}
|
||||
QPlainTextEdit::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void SeerEditorWidgetSourceArea::handleCursorPositionChanged()
|
||||
{
|
||||
// Emit signal to SeerEditorManagerWidget.cpp and save position
|
||||
// Read current position, deploy a timer
|
||||
SeerCurrentFile firstInfo = readCurrentPosition();
|
||||
if (_ignoreThumbMouseEvent > 0)
|
||||
{
|
||||
_ignoreThumbMouseEvent --;
|
||||
return;
|
||||
}
|
||||
|
||||
QTimer::singleShot(2000, this, [this, firstInfo]() {
|
||||
SeerCurrentFile secondInfo = readCurrentPosition();
|
||||
if (firstInfo == secondInfo) {
|
||||
emit addToMouseNavigation(firstInfo);
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user