Skip to content

Commit f9909f2

Browse files
committed
itemsync: Fix missing data in the last item when tab is full
1 parent 2eece2e commit f9909f2

File tree

6 files changed

+81
-6
lines changed

6 files changed

+81
-6
lines changed

docs/scripting-api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,7 @@ Types
20092009
:returns: self
20102010
:rtype: ItemSelection
20112011

2012-
.. js:method:: sort(row)
2012+
.. js:method:: sort(comparisonFunction)
20132013

20142014
Sort items with a comparison function.
20152015

plugins/itemsync/filewatcher.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ BaseNameExtensionsList listFiles(const QStringList &files,
314314
int i = fileMap.value(baseName, -1);
315315
if (i == -1) {
316316
i = fileList.size();
317+
if (i >= maxItemCount)
318+
break;
317319
fileList.append( BaseNameExtensions(baseName, {ext}) );
318320
fileMap.insert(baseName, i);
319-
if (fileList.size() >= maxItemCount)
320-
break;
321321
} else {
322322
fileList[i].exts.push_back(ext);
323323
}

plugins/itemsync/tests/itemsynctests.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,3 +817,66 @@ void ItemSyncTests::saveLargeItem()
817817
RUN(args << "getItem(0)['application/x-copyq-test-data'].left(26)", "abcdefghijklmnopqrstuvwxyz");
818818
RUN(args << "getItem(0)['application/x-copyq-test-data'].length", "260000\n");
819819
}
820+
821+
void ItemSyncTests::sortItemsSimple()
822+
{
823+
TestDir dir1(1);
824+
const QString tab1 = testTab(1);
825+
RUN(Args() << "show" << tab1, "");
826+
827+
const Args args = Args() << "tab" << tab1 << "separator" << ",";
828+
829+
RUN("config" << "maxitems" << "4", "4\n");
830+
const QString initScript = R"(
831+
add(1,2,0,3);
832+
read(0,1,2,3);
833+
)";
834+
RUN(args << initScript, "3,0,2,1");
835+
RUN(args << "size", "4\n");
836+
837+
const QString sortScript = R"(
838+
let sel = ItemSelection().selectAll();
839+
let items = sel.itemsFormat(mimeText);
840+
serverLog("SORT BEGIN");
841+
sel.sort((i, j) => items[i] < items[j]);
842+
serverLog("SORT END");
843+
read(0,1,2,3);
844+
)";
845+
RUN(args << sortScript, "0,1,2,3");
846+
RUN(args << "size", "4\n");
847+
}
848+
849+
void ItemSyncTests::sortItems()
850+
{
851+
TestDir dir1(1);
852+
const QString tab1 = testTab(1);
853+
RUN(Args() << "show" << tab1, "");
854+
855+
const Args args = Args() << "tab" << tab1 << "separator" << ",";
856+
857+
RUN("config" << "maxitems" << "4", "4\n");
858+
const QString initScript = R"(
859+
add(
860+
{[mimeText]: 1, [mimeHtml]: "I"},
861+
{[mimeText]: 2, [mimeHtml]: "II"},
862+
{[mimeText]: 0, [mimeHtml]: "O"},
863+
{[mimeText]: 3, [mimeHtml]: "III"},
864+
);
865+
read(0,1,2,3);
866+
)";
867+
RUN(args << initScript, "3,0,2,1");
868+
RUN(args << "read(mimeHtml,0,1,2,3)", "III,O,II,I");
869+
RUN(args << "size", "4\n");
870+
871+
const QString sortScript = R"(
872+
let sel = ItemSelection().selectAll();
873+
let items = sel.itemsFormat(mimeText);
874+
serverLog("SORT BEGIN");
875+
sel.sort((i, j) => items[i] < items[j]);
876+
serverLog("SORT END");
877+
read(0,1,2,3);
878+
)";
879+
RUN(args << sortScript, "0,1,2,3");
880+
RUN(args << "read(mimeHtml,0,1,2,3)", "O,I,II,III");
881+
RUN(args << "size", "4\n");
882+
}

plugins/itemsync/tests/itemsynctests.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ private slots:
5454

5555
void saveLargeItem();
5656

57+
void sortItemsSimple();
58+
void sortItems();
59+
5760
private:
5861
TestInterfacePtr m_test;
5962
};

src/item/clipboardmodel.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <QStringList>
99

1010
#include <algorithm>
11-
#include <functional>
1211

1312
namespace {
1413

src/tests/tests_classes.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,17 @@ void Tests::classItemSelectionSort()
368368
const QString outRows("ItemSelection(tab=\"" + tab1 + "\", rows=[%1])\n");
369369
RUN("setCurrentTab" << tab1, "");
370370

371-
RUN(args << "add(2,5,1,3,4)", "");
372-
RUN(args << "read(0,1,2,3,4)", "4,3,1,5,2");
371+
const QString initScript = R"(
372+
add(
373+
{[mimeText]: 2, [mimeHtml]: "two"},
374+
{[mimeText]: 5, [mimeHtml]: "five"},
375+
{[mimeText]: 1, [mimeHtml]: "one"},
376+
{[mimeText]: 3, [mimeHtml]: "three"},
377+
{[mimeText]: 4, [mimeHtml]: "four"},
378+
);
379+
read(0,1,2,3,4);
380+
)";
381+
RUN(args << initScript, "4,3,1,5,2");
373382

374383
const auto script = R"(
375384
var sel = ItemSelection().selectAll();
@@ -381,6 +390,7 @@ void Tests::classItemSelectionSort()
381390
)";
382391
RUN(args << script, outRows.arg("3,2,0,4,1"));
383392
RUN(args << "read(0,1,2,3,4)", "1,2,3,4,5");
393+
RUN(args << "read(mimeHtml,0,1,2,3,4)", "one,two,three,four,five");
384394
RUN(args << "size", "5\n");
385395
}
386396

0 commit comments

Comments
 (0)