Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DisAsm: double-click and tripple-click should select text at cursor. #3252

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions docs/source/user-docs/menus/disassembly-context-menu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ Copy
----------------------------------------
**Description:** Copy the selected text.

**Steps:** Right-click on a selected text and choose ``Copy``
**Steps:** Double click to select word or triple click to select line under cursor.

**Shortcut:** :kbd:`Ctrl` + :kbd:`C`
**Shortcut:** :kbd:`Ctrl` + :kbd:`C`

Jump to address
----------------------------------------
**Description** Jump to the address or function

**Steps** Hold :kbd:`Ctrl` and double click

Copy Address
----------------------------------------
Expand Down
25 changes: 10 additions & 15 deletions src/widgets/DisassemblyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main)
QTextDocument *asm_docu = mDisasTextEdit->document();
asm_docu->setDocumentMargin(10);

// Event filter to intercept double clicks in the textbox
// and showing tooltips when hovering above those offsets
// Event filter to intercept showing tooltips when hovering above those offsets
mDisasTextEdit->viewport()->installEventFilter(this);

// Set Disas context menu
Expand Down Expand Up @@ -627,19 +626,9 @@ void DisassemblyWidget::jumpToOffsetUnderCursor(const QTextCursor &cursor)

bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseButtonDblClick
&& (obj == mDisasTextEdit || obj == mDisasTextEdit->viewport())) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);

if (mouseEvent->button() == Qt::LeftButton) {
const QTextCursor &cursor = mDisasTextEdit->cursorForPosition(mouseEvent->pos());
jumpToOffsetUnderCursor(cursor);

return true;
}
} else if ((Config()->getPreviewValue() || Config()->getShowVarTooltips())
&& event->type() == QEvent::ToolTip && obj == mDisasTextEdit->viewport()) {
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
if ((Config()->getPreviewValue() || Config()->getShowVarTooltips())
&& event->type() == QEvent::ToolTip && obj == mDisasTextEdit->viewport()) {
auto *helpEvent = dynamic_cast<QHelpEvent *>(event);
auto cursorForWord = mDisasTextEdit->cursorForPosition(helpEvent->pos());
cursorForWord.select(QTextCursor::WordUnderCursor);

Expand Down Expand Up @@ -791,6 +780,12 @@ void DisassemblyTextEdit::keyPressEvent(QKeyEvent *event)

void DisassemblyTextEdit::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && event->modifiers() & Qt::ControlModifier) {
if (mDisassemblyWidget) {
mDisassemblyWidget->jumpToOffsetUnderCursor(textCursor());
}
}

QPlainTextEdit::mousePressEvent(event);

if (event->button() == Qt::RightButton && !textCursor().hasSelection()) {
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/DisassemblyWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public slots:
void setPreviewMode(bool previewMode);
QFontMetrics getFontMetrics();
QList<DisassemblyLine> getLines();
void jumpToOffsetUnderCursor(const QTextCursor &);

protected slots:
void on_seekChanged(RVA offset, CutterCore::SeekHistoryType type);
Expand Down Expand Up @@ -101,8 +102,6 @@ protected slots:
void connectCursorPositionChanged(bool disconnect);

void moveCursorRelative(bool up, bool page);

void jumpToOffsetUnderCursor(const QTextCursor &);
};

class DisassemblyScrollArea : public QAbstractScrollArea
Expand All @@ -128,8 +127,8 @@ class DisassemblyTextEdit : public QPlainTextEdit
Q_OBJECT

public:
explicit DisassemblyTextEdit(QWidget *parent = nullptr)
: QPlainTextEdit(parent), lockScroll(false)
explicit DisassemblyTextEdit(DisassemblyWidget *parent = nullptr)
: QPlainTextEdit(parent), lockScroll(false), mDisassemblyWidget(parent)
{
}

Expand All @@ -145,6 +144,7 @@ class DisassemblyTextEdit : public QPlainTextEdit

private:
bool lockScroll;
DisassemblyWidget *mDisassemblyWidget;
};

/**
Expand Down
Loading