Skip to content

Commit be54ae9

Browse files
authored
Add Shortcut to Cancel current selection (flameshot-org#3751)
This PR adds the ability to close the selection using the Ctrl + Backspace key combination, addressing issue flameshot-org#3319. The new shortcut allows users to quickly exit the selection mode without relying on mouse interactions.
1 parent 45c47eb commit be54ae9

File tree

7 files changed

+27
-1
lines changed

7 files changed

+27
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ These shortcuts are available in GUI mode:
214214
| <kbd>Ctrl</kbd> + <kbd>Q</kbd> | Leave the capture screen |
215215
| <kbd>Ctrl</kbd> + <kbd>O</kbd> | Choose an app to open the capture |
216216
| <kbd>Ctrl</kbd> + <kbd>Return</kbd> | Commit text in text area|
217+
| <kbd>Ctrl</kbd> + <kbd>Backspace</kbd> | Cancel current selection |
217218
| <kbd>Return</kbd> | Upload the selection to Imgur |
218219
| <kbd>Spacebar</kbd> | Toggle visibility of sidebar with options of the selected tool, color picker for the drawing color and history menu |
219220
| Right Click | Show the color wheel |

flameshot.example.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
;; Shortcut Settings for all tools
103103
;[Shortcuts]
104104
;TYPE_ARROW=A
105+
;TYPE_CANCEL=Ctrl+Backspace
105106
;TYPE_CIRCLE=C
106107
;TYPE_CIRCLECOUNT=
107108
;TYPE_COMMIT_CURRENT_TOOL=Ctrl+Return

src/config/shortcutswidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ void ShortcutsWidget::loadShortcuts()
192192
appendShortcut("TYPE_COMMIT_CURRENT_TOOL", tr("Commit text in text area"));
193193
appendShortcut("TYPE_DELETE_CURRENT_TOOL",
194194
tr("Delete selected drawn object"));
195+
appendShortcut("TYPE_CANCEL", tr("Cancel current selection"));
195196

196197
// non-editable shortcuts have an empty shortcut name
197198

src/tools/capturetool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CaptureTool : public QObject
4848
TYPE_SIZEDECREASE = 21,
4949
TYPE_INVERT = 22,
5050
TYPE_ACCEPT = 23,
51+
TYPE_CANCEL = 24,
5152
};
5253
Q_ENUM(Type);
5354

src/utils/confighandler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {
146146
SHORTCUT("TYPE_SAVE" , "Ctrl+S" ),
147147
SHORTCUT("TYPE_ACCEPT" , "Return" ),
148148
SHORTCUT("TYPE_EXIT" , "Ctrl+Q" ),
149+
SHORTCUT("TYPE_CANCEL" , "Ctrl+Backspace" ),
149150
SHORTCUT("TYPE_IMAGEUPLOADER" , ),
150151
#if !defined(Q_OS_MACOS)
151152
SHORTCUT("TYPE_OPEN_APP" , "Ctrl+O" ),

src/widgets/capture/capturewidget.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,6 @@ void CaptureWidget::mousePressEvent(QMouseEvent* e)
796796
if (m_selection->getMouseSide(e->pos()) != SelectionWidget::CENTER) {
797797
m_panel->setActiveLayer(-1);
798798
}
799-
800799
if (e->button() == Qt::RightButton) {
801800
if (m_activeTool && m_activeTool->editMode()) {
802801
return;
@@ -1603,6 +1602,10 @@ void CaptureWidget::initShortcuts()
16031602
m_selection,
16041603
SLOT(moveDown()));
16051604

1605+
newShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_CANCEL")),
1606+
this,
1607+
SLOT(cancel()));
1608+
16061609
newShortcut(
16071610
QKeySequence(ConfigHandler().shortcut("TYPE_DELETE_CURRENT_TOOL")),
16081611
this,
@@ -1914,6 +1917,23 @@ void CaptureWidget::redo()
19141917
restoreCircleCountState();
19151918
}
19161919

1920+
void CaptureWidget::cancel()
1921+
{
1922+
if (m_activeButton != nullptr) {
1923+
uncheckActiveTool();
1924+
}
1925+
if (m_panel) {
1926+
m_panel->setActiveLayer(-1);
1927+
}
1928+
if (m_toolWidget) {
1929+
m_toolWidget->hide();
1930+
delete m_toolWidget;
1931+
m_toolWidget = nullptr;
1932+
}
1933+
m_selection->hide();
1934+
emit m_selection->geometrySettled();
1935+
}
1936+
19171937
QRect CaptureWidget::extendedSelection() const
19181938
{
19191939
if (m_selection == nullptr) {

src/widgets/capture/capturewidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public slots:
7070
private slots:
7171
void undo();
7272
void redo();
73+
void cancel();
7374
void togglePanel();
7475
void childEnter();
7576
void childLeave();

0 commit comments

Comments
 (0)