summaryrefslogtreecommitdiff
path: root/services/Clip.qml
diff options
context:
space:
mode:
Diffstat (limited to 'services/Clip.qml')
-rw-r--r--services/Clip.qml58
1 files changed, 9 insertions, 49 deletions
diff --git a/services/Clip.qml b/services/Clip.qml
index 6fee97c..81fea60 100644
--- a/services/Clip.qml
+++ b/services/Clip.qml
@@ -3,11 +3,14 @@ pragma Singleton
import Quickshell
import Quickshell.Io
import QtQuick
-import "../utils/levendist.js" as Levendist
+import qs.components
-Singleton {
+Searchable {
id: root
+ key: "data"
+ algorithm: Searchable.SearchAlgorithm.Levendist
+
property list<string> _clipHist: []
property list<string> _clipImg: []
property list<string> _clipImgIds: _clipImg.map(p => p.split("/").pop().split(".").shift())
@@ -16,9 +19,7 @@ Singleton {
property string toCopy: ""
property string decoded: ""
- property var fuzzyQueryCache: ({});
-
- property var clipHist: {
+ list: {
const arr = [];
if (!_clipHist?.length)
return arr;
@@ -42,7 +43,7 @@ Singleton {
const n = parseInt(raw.slice(0, tab), 10);
if (!Number.isNaN(n)) {
idNum = n;
- payload = raw.slice(tab + 1); // strip "ID<TAB>"
+ payload = raw.slice(tab + 1);
}
}
@@ -60,49 +61,8 @@ Singleton {
return arr;
}
- function fuzzyQuery(search) {
- if (!search)
- return root.clipHist;
- if (root.fuzzyQueryCache[search]) {
- return root.fuzzyQueryCache[search];
- }
- let source = root.clipHist;
- let previousLists = Object.keys(root.fuzzyQueryCache).filter(key => key && search.startsWith(key));
- if (previousLists.length > 0) {
- var longest = previousLists.reduce((a, b) => a.length >= b.length ? a : b);
- source = root.fuzzyQueryCache[longest];
- }
- const p = [], f = [];
- for (const s of source) {
- const t = (s.isImage ? "image" : (s.data || "")).toLowerCase();
- if (t.startsWith(search)) {
- p.push(s);
- continue;
- }
- let pos = 0;
- for (const c of search) {
- pos = t.indexOf(c, pos);
- if (pos < 0) {
- pos = 0;
- break;
- }
- pos++;
- }
- if (pos)
- f.push({
- s,
- score: Levendist.distance(search, t)
- });
- }
- const results = p.concat(f.sort((a, b) => a.score - b.score).map(({s}) => s));
- root.fuzzyQueryCache[search] = results;
- return results;
- }
-
- component SClip_t: QtObject {
- property int index
- property bool isImage
- property string data
+ function transformSearch(search: string): string {
+ return search.toLowerCase();
}
function decodeAndCopy(text) {