Skip to content

Commit dbecf3b

Browse files
authored
itemsync: Avoid duplicate items from clipboard (#2236)
Fixes #2228
1 parent 182404f commit dbecf3b

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

plugins/itemsync/tests/itemsynctests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,3 +731,23 @@ void ItemSyncTests::moveOwnItemsSortsBaseNames()
731731
RUN(args << "read(0,1,2,3)", "B,C,D,A");
732732
RUN(args << testScript, "");
733733
}
734+
735+
void ItemSyncTests::avoidDuplicateItemsAddedFromClipboard()
736+
{
737+
TestDir dir1(1);
738+
const QString tab1 = testTab(1);
739+
RUN("show" << tab1, "");
740+
741+
const Args args = Args() << "separator" << "," << "tab" << tab1;
742+
743+
RUN("config" << "clipboard_tab" << tab1, tab1 + "\n");
744+
745+
TEST( m_test->setClipboard("one") );
746+
WAIT_ON_OUTPUT(args << "read(0,1,2,3)", "one,,,");
747+
748+
TEST( m_test->setClipboard("two") );
749+
WAIT_ON_OUTPUT(args << "read(0,1,2,3)", "two,one,,");
750+
751+
TEST( m_test->setClipboard("one") );
752+
WAIT_ON_OUTPUT(args << "read(0,1,2,3)", "one,two,,");
753+
}

plugins/itemsync/tests/itemsynctests.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ private slots:
5050

5151
void moveOwnItemsSortsBaseNames();
5252

53+
void avoidDuplicateItemsAddedFromClipboard();
54+
5355
private:
5456
TestInterfacePtr m_test;
5557
};

src/common/textdata.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace {
1515

16+
const QLatin1String mimePluginPrefix(COPYQ_MIME_PREFIX "item");
17+
1618
QString escapeHtmlSpaces(const QString &str)
1719
{
1820
QString str2 = str;
@@ -21,6 +23,13 @@ QString escapeHtmlSpaces(const QString &str)
2123
.replace('\n', "<br />");
2224
}
2325

26+
bool isPluginFormat(const QString &mime)
27+
{
28+
return mime.startsWith(mimePluginPrefix)
29+
&& mime.size() > mimePluginPrefix.size()
30+
&& mime[mimePluginPrefix.size()] != '-';
31+
}
32+
2433
} // namespace
2534

2635
uint hash(const QVariantMap &data)
@@ -35,6 +44,9 @@ uint hash(const QVariantMap &data)
3544
if (mime == mimeWindowTitle || mime == mimeOwner || mime == mimeClipboardMode)
3645
continue;
3746

47+
if ( isPluginFormat(mime) )
48+
continue;
49+
3850
seed = hash(seed, mime);
3951
seed = hash(seed, data[mime].toByteArray());
4052
}

0 commit comments

Comments
 (0)