mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
feat: improve searchbar
This commit is contained in:
@@ -64,7 +64,7 @@
|
|||||||
isCalculating = true;
|
isCalculating = true;
|
||||||
|
|
||||||
// Let mathjs handle everything
|
// Let mathjs handle everything
|
||||||
const evaluated = math.evaluate(input);
|
const evaluated = math.evaluate(input.replace('**', '^'));
|
||||||
|
|
||||||
// Format the result
|
// Format the result
|
||||||
if (evaluated !== undefined) {
|
if (evaluated !== undefined) {
|
||||||
@@ -103,7 +103,7 @@
|
|||||||
} finally {
|
} finally {
|
||||||
isCalculating = false;
|
isCalculating = false;
|
||||||
}
|
}
|
||||||
}, 3);
|
}, 2);
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
processInput(searchTerm);
|
processInput(searchTerm);
|
||||||
@@ -119,17 +119,17 @@
|
|||||||
<p class="text-[0.85rem] p-1 pb-0.5 font-semibold text-zinc-500 dark:text-zinc-400">Calculator</p>
|
<p class="text-[0.85rem] p-1 pb-0.5 font-semibold text-zinc-500 dark:text-zinc-400">Calculator</p>
|
||||||
<div class="flex items-center justify-between gap-8 rounded-lg border border-transparent {isSelected ? 'bg-zinc-900/5 dark:bg-white/10 border-zinc-900/5 dark:border-zinc-100/5' : ''}">
|
<div class="flex items-center justify-between gap-8 rounded-lg border border-transparent {isSelected ? 'bg-zinc-900/5 dark:bg-white/10 border-zinc-900/5 dark:border-zinc-100/5' : ''}">
|
||||||
<div class="flex flex-col flex-1 items-center py-4 pl-4">
|
<div class="flex flex-col flex-1 items-center py-4 pl-4">
|
||||||
<div class="text-3xl font-semibold text-zinc-900 dark:text-white">
|
<div class="py-2 text-4xl font-semibold text-zinc-900 dark:text-white">
|
||||||
{searchTerm}
|
{searchTerm}
|
||||||
</div>
|
</div>
|
||||||
<div class="px-3 py-1 mt-1 text-sm rounded-md text-zinc-600 dark:text-zinc-400 bg-zinc-100 dark:bg-zinc-800">
|
<div class="px-3 py-1 mt-1 text-sm rounded-md text-zinc-900 dark:text-zinc-300 bg-zinc-100 dark:bg-zinc-100/10">
|
||||||
{inputUnit || 'Question'}
|
{inputUnit || 'Question'}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col justify-center items-center w-12">
|
<div class="flex flex-col justify-center items-center w-12">
|
||||||
<div class="h-8 w-[1px] bg-zinc-900/5 dark:bg-zinc-100/5"></div>
|
<div class="h-8 w-[1px] bg-zinc-900/5 dark:bg-zinc-100/5"></div>
|
||||||
<div class="text-2xl text-zinc-600 dark:text-zinc-400">
|
<div class="text-2xl text-zinc-900 dark:text-zinc-100">
|
||||||
→
|
→
|
||||||
</div>
|
</div>
|
||||||
<div class="h-8 w-[1px] bg-zinc-900/5 dark:bg-zinc-100/5"></div>
|
<div class="h-8 w-[1px] bg-zinc-900/5 dark:bg-zinc-100/5"></div>
|
||||||
@@ -137,10 +137,10 @@
|
|||||||
|
|
||||||
{#if !isCalculating}
|
{#if !isCalculating}
|
||||||
<div class="flex flex-col flex-1 items-center py-4 pr-4">
|
<div class="flex flex-col flex-1 items-center py-4 pr-4">
|
||||||
<div class="text-3xl font-semibold text-zinc-900 dark:text-white">
|
<div class="py-2 text-4xl font-semibold text-zinc-900 dark:text-white">
|
||||||
{result}
|
{result}
|
||||||
</div>
|
</div>
|
||||||
<div class="px-3 py-1 mt-1 text-sm rounded-md text-zinc-600 dark:text-zinc-400 bg-zinc-100 dark:bg-zinc-800">
|
<div class="px-3 py-1 mt-1 text-sm rounded-md text-zinc-900 dark:text-zinc-300 bg-zinc-100 dark:bg-zinc-100/10">
|
||||||
{outputUnit || 'Result'}
|
{outputUnit || 'Result'}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -113,10 +113,15 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (combinedResults.length === 0 && calculatorResult && commandPalleteOpen) {
|
||||||
|
selectedIndex = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const selectNext = () => {
|
const selectNext = () => {
|
||||||
if (calculatorResult && selectedIndex === -1) {
|
const maxIndex = (calculatorResult ? 1 : 0) + combinedResults.length - 1;
|
||||||
selectedIndex = 0; // Move from calculator to first search result
|
if (selectedIndex < maxIndex) {
|
||||||
} else if (selectedIndex < combinedResults.length - 1) {
|
|
||||||
selectedIndex++;
|
selectedIndex++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -124,18 +129,15 @@
|
|||||||
const selectPrev = () => {
|
const selectPrev = () => {
|
||||||
if (selectedIndex > 0) {
|
if (selectedIndex > 0) {
|
||||||
selectedIndex--;
|
selectedIndex--;
|
||||||
} else if (selectedIndex === 0 && calculatorResult) {
|
|
||||||
selectedIndex = -1; // Move from first search result to calculator
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const executeSelected = () => {
|
const executeSelected = () => {
|
||||||
if (selectedIndex === -1 && calculatorResult) {
|
if (calculatorResult && selectedIndex === 0) {
|
||||||
if (calculatorResult) {
|
navigator.clipboard.writeText(calculatorResult);
|
||||||
navigator.clipboard.writeText(calculatorResult);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
combinedResults[selectedIndex]?.item.action();
|
const resultIndex = calculatorResult ? selectedIndex - 1 : selectedIndex;
|
||||||
|
combinedResults[resultIndex]?.item.action();
|
||||||
}
|
}
|
||||||
commandPalleteOpen = false;
|
commandPalleteOpen = false;
|
||||||
};
|
};
|
||||||
@@ -196,21 +198,21 @@
|
|||||||
|
|
||||||
<Calculator
|
<Calculator
|
||||||
searchTerm={searchTerm}
|
searchTerm={searchTerm}
|
||||||
isSelected={selectedIndex === -1}
|
isSelected={selectedIndex === 0}
|
||||||
on:hasResult={(e) => updateCalculatorState(e.detail)}
|
on:hasResult={(e) => updateCalculatorState(e.detail)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{#if combinedResults.length > 0}
|
{#if combinedResults.length > 0}
|
||||||
<ul class="overflow-y-auto max-h-[32rem] text-base scroll-py-2 p-1 gap-0.5 flex flex-col">
|
<ul class="overflow-y-auto max-h-[32rem] text-base scroll-py-2 p-1 gap-0.5 flex flex-col">
|
||||||
{#each combinedResults as result, i (result.id)}
|
{#each combinedResults as result, i (result.id)}
|
||||||
{@const isSelected = selectedIndex === i}
|
{@const isSelected = selectedIndex === (calculatorResult ? i + 1 : i)}
|
||||||
{@const item = result.item}
|
{@const item = result.item}
|
||||||
<li>
|
<li>
|
||||||
{#if result.type === 'command'}
|
{#if result.type === 'command'}
|
||||||
<!-- Render Static Command -->
|
<!-- Render Static Command -->
|
||||||
{@const staticItem = item as StaticCommandItem}
|
{@const staticItem = item as StaticCommandItem}
|
||||||
<button
|
<button
|
||||||
class="w-full flex items-center px-2 py-1.5 rounded-lg transition duration-150 select-none cursor-pointer group
|
class="w-full flex items-center px-2 py-1.5 rounded-lg select-none cursor-pointer group
|
||||||
{isSelected ? 'bg-zinc-900/5 dark:bg-white/10 text-zinc-900 dark:text-white' : 'hover:bg-zinc-500/5 dark:hover:bg-white/5 text-zinc-800 dark:text-zinc-200'}"
|
{isSelected ? 'bg-zinc-900/5 dark:bg-white/10 text-zinc-900 dark:text-white' : 'hover:bg-zinc-500/5 dark:hover:bg-white/5 text-zinc-800 dark:text-zinc-200'}"
|
||||||
onclick={() => { staticItem.action(); commandPalleteOpen = false; }}
|
onclick={() => { staticItem.action(); commandPalleteOpen = false; }}
|
||||||
>
|
>
|
||||||
@@ -228,7 +230,7 @@
|
|||||||
<!-- Render Dynamic Content Item -->
|
<!-- Render Dynamic Content Item -->
|
||||||
{@const dynamicItem = item as DynamicContentItem}
|
{@const dynamicItem = item as DynamicContentItem}
|
||||||
<button
|
<button
|
||||||
class="w-full flex flex-col px-2 py-1.5 rounded-lg transition duration-150 select-none cursor-pointer group
|
class="w-full flex flex-col px-2 py-1.5 rounded-lg select-none cursor-pointer group
|
||||||
{isSelected ? 'bg-zinc-900/5 dark:bg-white/10 text-zinc-900 dark:text-white' : 'hover:bg-zinc-500/5 dark:hover:bg-white/5 text-zinc-800 dark:text-zinc-200'}"
|
{isSelected ? 'bg-zinc-900/5 dark:bg-white/10 text-zinc-900 dark:text-white' : 'hover:bg-zinc-500/5 dark:hover:bg-white/5 text-zinc-800 dark:text-zinc-200'}"
|
||||||
onclick={() => { dynamicItem.action(); commandPalleteOpen = false; }}
|
onclick={() => { dynamicItem.action(); commandPalleteOpen = false; }}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const staticCommands: StaticCommandItem[] = [
|
|||||||
id: 'messages',
|
id: 'messages',
|
||||||
icon: '\uea6e',
|
icon: '\uea6e',
|
||||||
category: 'navigation',
|
category: 'navigation',
|
||||||
text: 'Messages',
|
text: 'Messages 4',
|
||||||
keybind: ['alt+m'],
|
keybind: ['alt+m'],
|
||||||
keybindLabel: 'Alt+M',
|
keybindLabel: 'Alt+M',
|
||||||
action: () => {
|
action: () => {
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ export function createSearchIndexes() {
|
|||||||
keys: ['text', 'category', 'keywords'],
|
keys: ['text', 'category', 'keywords'],
|
||||||
includeScore: true,
|
includeScore: true,
|
||||||
includeMatches: true,
|
includeMatches: true,
|
||||||
threshold: 0.4,
|
threshold: 0.6,
|
||||||
minMatchCharLength: 2,
|
minMatchCharLength: 1,
|
||||||
ignoreLocation: true,
|
ignoreLocation: true,
|
||||||
useExtendedSearch: true
|
useExtendedSearch: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const dynamicOptions = {
|
const dynamicOptions = {
|
||||||
@@ -45,10 +45,10 @@ export function createSearchIndexes() {
|
|||||||
],
|
],
|
||||||
includeScore: true,
|
includeScore: true,
|
||||||
includeMatches: true,
|
includeMatches: true,
|
||||||
threshold: 0.4,
|
threshold: 0.6,
|
||||||
minMatchCharLength: 2,
|
minMatchCharLength: 1,
|
||||||
ignoreLocation: true,
|
ignoreLocation: true,
|
||||||
useExtendedSearch: true
|
useExtendedSearch: false
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user