Skip to content

Commit 811caf2

Browse files
committed
Avoid modifying data in display commands
Fixes #2837
1 parent c9248f7 commit 811caf2

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/item/persistentdisplayitem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "persistentdisplayitem.h"
44

5+
#include "common/mimetypes.h"
56
#include "gui/traymenu.h"
67
#include "item/itemdelegate.h"
78

@@ -27,6 +28,9 @@ PersistentDisplayItem::PersistentDisplayItem(ItemDelegate *delegate,
2728
, m_widget(widget)
2829
, m_delegate(delegate)
2930
{
31+
// Avoid accessing current selection in Display commands.
32+
if ( !m_data.contains(mimeCurrentTab) )
33+
m_data[mimeSelectedItems] = QByteArray();
3034
}
3135

3236
PersistentDisplayItem::PersistentDisplayItem(QAction *action, const QVariantMap &data)

src/scriptable/scriptable.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,9 @@ QJSValue Scriptable::setData()
16411641
if ( !toItemData(argument(1), mime, &m_data) )
16421642
return false;
16431643

1644-
m_proxy->setSelectedItemsData(mime, m_data.value(mime));
1644+
if (!m_modifyDisplayDataOnly)
1645+
m_proxy->setSelectedItemsData(mime, m_data.value(mime));
1646+
16451647
return true;
16461648
}
16471649

@@ -1651,7 +1653,10 @@ QJSValue Scriptable::removeData()
16511653

16521654
const QString mime = arg(0);
16531655
m_data.remove(mime);
1654-
m_proxy->setSelectedItemsData(mime, QVariant());
1656+
1657+
if (!m_modifyDisplayDataOnly)
1658+
m_proxy->setSelectedItemsData(mime, QVariant());
1659+
16551660
return true;
16561661
}
16571662

@@ -2487,6 +2492,8 @@ QJSValue Scriptable::runAutomaticCommands()
24872492

24882493
void Scriptable::runDisplayCommands()
24892494
{
2495+
m_modifyDisplayDataOnly = true;
2496+
24902497
QEventLoop loop;
24912498
connect(this, &Scriptable::finished, &loop, [&]() {
24922499
if (m_abort == Abort::AllEvaluations)
@@ -2526,6 +2533,8 @@ void Scriptable::runDisplayCommands()
25262533

25272534
if (m_abort == Abort::None)
25282535
loop.exec();
2536+
2537+
m_modifyDisplayDataOnly = false;
25292538
}
25302539

25312540
void Scriptable::runMenuCommandFilters()

src/scriptable/scriptable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ public slots:
488488
Abort m_abort = Abort::None;
489489
int m_skipArguments = 0;
490490

491-
bool m_displayFunctionsLock = false;
491+
bool m_modifyDisplayDataOnly = false;
492492

493493
QJSValue m_plugins;
494494

0 commit comments

Comments
 (0)