#246 fuzzy search in ctrl+p+capital search

This commit is contained in:
Jan Prochazka
2022-12-22 17:10:23 +01:00
parent b712e3c6ae
commit 2213cda1c6
4 changed files with 32 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
import _compact from 'lodash/compact';
import _isString from 'lodash/isString';
import _startCase from 'lodash/startCase';
export interface FilterNameDefinition {
childName: string;
@@ -64,16 +65,10 @@ function camelMatch(filter: string, text: string): boolean {
if (!filter) return true;
if (filter.replace(/[A-Z]/g, '').length == 0) {
const camelVariants = [text.replace(/[^A-Z]/g, '')];
let s = text,
s0;
do {
s0 = s;
s = s.replace(/([A-Z])([A-Z])([A-Z])/, '$1$3');
} while (s0 != s);
camelVariants.push(s.replace(/[^A-Z]/g, ''));
const camelContains = !!camelVariants.find(x => x.includes(filter.toUpperCase()));
return camelContains;
const textCapitals = _startCase(text).replace(/[^A-Z]/g, '');
const pattern = '.*' + filter.split('').join('.*') + '.*';
const re = new RegExp(pattern);
return re.test(textCapitals);
} else {
return text.toUpperCase().includes(filter.toUpperCase());
}

View File

@@ -58,6 +58,7 @@
"chartjs-plugin-zoom": "^1.2.0",
"date-fns": "^2.28.0",
"debug": "^4.3.4",
"fuzzy": "^0.1.3",
"interval-operations": "^1.0.7",
"leaflet": "^1.8.0",
"wellknown": "^0.5.0"

View File

@@ -64,6 +64,7 @@
import _ from 'lodash';
import { onMount } from 'svelte';
import fuzzy from 'fuzzy';
import { databaseObjectIcons, handleDatabaseObjectClick } from '../appobj/DatabaseObjectAppObject.svelte';
import FontIcon from '../icons/FontIcon.svelte';
import {
@@ -106,12 +107,25 @@
$: databaseInfo = useDatabaseInfo({ conid, database });
$: connectionList = useConnectionList();
$: filteredItems = ($visibleCommandPalette == 'database'
? extractDbItems($databaseInfo, { conid, database }, $connectionList)
: parentCommand
? parentCommand.getSubCommands()
: sortedComands
).filter(x => !x.isGroupCommand && filterName(filter, x.text));
$: filteredItems = fuzzy
.filter(
filter,
($visibleCommandPalette == 'database'
? extractDbItems($databaseInfo, { conid, database }, $connectionList)
: parentCommand
? parentCommand.getSubCommands()
: sortedComands
).filter(x => !x.isGroupCommand),
{
extract: x => x.text,
pre: '<b>',
post: '</b>',
}
)
.map(x => ({
...x.original,
text: x.string,
}));
function handleCommand(command) {
if (command.getSubCommands) {
@@ -194,7 +208,7 @@
{#if command.icon}
<span class="mr-1"><FontIcon icon={command.icon} /></span>
{/if}
{command.text}
{@html command.text}
</div>
{#if command.keyText}
<div class="shortcut">{command.keyText}</div>

View File

@@ -4580,6 +4580,11 @@ functions-have-names@^1.2.2, functions-have-names@^1.2.3:
resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834"
integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==
fuzzy@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/fuzzy/-/fuzzy-0.1.3.tgz#4c76ec2ff0ac1a36a9dccf9a00df8623078d4ed8"
integrity sha512-/gZffu4ykarLrCiP3Ygsa86UAo1E5vEVlvTrpkKywXSbP9Xhln3oSp9QSV57gEq3JFFpGJ4GZ+5zdEp3FcUh4w==
gauge@~2.7.3:
version "2.7.4"
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"