forked from Shinonome/dots-hyprland
booru: add api provider suggestions
This commit is contained in:
@@ -2,6 +2,7 @@ import "root:/"
|
|||||||
import "root:/services"
|
import "root:/services"
|
||||||
import "root:/modules/common"
|
import "root:/modules/common"
|
||||||
import "root:/modules/common/widgets"
|
import "root:/modules/common/widgets"
|
||||||
|
import "root:/modules/common/functions/fuzzysort.js" as Fuzzy
|
||||||
import "./anime/"
|
import "./anime/"
|
||||||
import Qt.labs.platform
|
import Qt.labs.platform
|
||||||
import QtQuick
|
import QtQuick
|
||||||
@@ -119,6 +120,13 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: panelWindow
|
||||||
|
function onVisibleChanged(visible) {
|
||||||
|
tagInputField.forceActiveFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Keys.onPressed: (event) => {
|
Keys.onPressed: (event) => {
|
||||||
tagInputField.forceActiveFocus()
|
tagInputField.forceActiveFocus()
|
||||||
if (event.modifiers === Qt.NoModifier) {
|
if (event.modifiers === Qt.NoModifier) {
|
||||||
@@ -346,7 +354,6 @@ Item {
|
|||||||
repeat: false
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
const inputText = tagInputField.text
|
const inputText = tagInputField.text
|
||||||
if (inputText.length === 0 || inputText.startsWith(root.commandPrefix)) return;
|
|
||||||
const words = inputText.trim().split(/\s+/);
|
const words = inputText.trim().split(/\s+/);
|
||||||
if (words.length > 0) {
|
if (words.length > 0) {
|
||||||
Booru.triggerTagSearch(words[words.length - 1]);
|
Booru.triggerTagSearch(words[words.length - 1]);
|
||||||
@@ -358,15 +365,37 @@ Item {
|
|||||||
if(tagInputField.text.length === 0) {
|
if(tagInputField.text.length === 0) {
|
||||||
root.suggestionQuery = ""
|
root.suggestionQuery = ""
|
||||||
root.suggestionList = []
|
root.suggestionList = []
|
||||||
|
searchTimer.stop();
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if(tagInputField.text.startsWith(`${root.commandPrefix}mode`)) {
|
||||||
|
root.suggestionQuery = tagInputField.text.split(" ")[1] ?? ""
|
||||||
|
const providerResults = Fuzzy.go(root.suggestionQuery, Booru.providerList.map(provider => {
|
||||||
|
return {
|
||||||
|
name: Fuzzy.prepare(provider),
|
||||||
|
obj: provider,
|
||||||
|
}
|
||||||
|
}), {
|
||||||
|
all: true,
|
||||||
|
key: "name"
|
||||||
|
})
|
||||||
|
console.log(JSON.stringify(providerResults))
|
||||||
|
root.suggestionList = providerResults.map(provider => {
|
||||||
|
return {
|
||||||
|
name: `${tagInputField.text.trim().split(" ").length == 1 ? (root.commandPrefix + "mode ") : ""}${provider.target}`,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
searchTimer.stop();
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if(tagInputField.text.startsWith(root.commandPrefix)) {
|
if(tagInputField.text.startsWith(root.commandPrefix)) {
|
||||||
root.suggestionQuery = ""
|
root.suggestionQuery = tagInputField.text
|
||||||
root.suggestionList = root.allCommands.filter(cmd => cmd.name.startsWith(tagInputField.text.substring(1))).map(cmd => {
|
root.suggestionList = root.allCommands.filter(cmd => cmd.name.startsWith(tagInputField.text.substring(1))).map(cmd => {
|
||||||
return {
|
return {
|
||||||
name: `${root.commandPrefix}${cmd.name}`,
|
name: `${root.commandPrefix}${cmd.name}`,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
searchTimer.stop();
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
searchTimer.restart();
|
searchTimer.restart();
|
||||||
|
|||||||
Reference in New Issue
Block a user