mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 18:34:01 +00:00
#246 fuzzy search in ctrl+p+capital search
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import _compact from 'lodash/compact';
|
import _compact from 'lodash/compact';
|
||||||
import _isString from 'lodash/isString';
|
import _isString from 'lodash/isString';
|
||||||
|
import _startCase from 'lodash/startCase';
|
||||||
|
|
||||||
export interface FilterNameDefinition {
|
export interface FilterNameDefinition {
|
||||||
childName: string;
|
childName: string;
|
||||||
@@ -64,16 +65,10 @@ function camelMatch(filter: string, text: string): boolean {
|
|||||||
if (!filter) return true;
|
if (!filter) return true;
|
||||||
|
|
||||||
if (filter.replace(/[A-Z]/g, '').length == 0) {
|
if (filter.replace(/[A-Z]/g, '').length == 0) {
|
||||||
const camelVariants = [text.replace(/[^A-Z]/g, '')];
|
const textCapitals = _startCase(text).replace(/[^A-Z]/g, '');
|
||||||
let s = text,
|
const pattern = '.*' + filter.split('').join('.*') + '.*';
|
||||||
s0;
|
const re = new RegExp(pattern);
|
||||||
do {
|
return re.test(textCapitals);
|
||||||
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;
|
|
||||||
} else {
|
} else {
|
||||||
return text.toUpperCase().includes(filter.toUpperCase());
|
return text.toUpperCase().includes(filter.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
"chartjs-plugin-zoom": "^1.2.0",
|
"chartjs-plugin-zoom": "^1.2.0",
|
||||||
"date-fns": "^2.28.0",
|
"date-fns": "^2.28.0",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
|
"fuzzy": "^0.1.3",
|
||||||
"interval-operations": "^1.0.7",
|
"interval-operations": "^1.0.7",
|
||||||
"leaflet": "^1.8.0",
|
"leaflet": "^1.8.0",
|
||||||
"wellknown": "^0.5.0"
|
"wellknown": "^0.5.0"
|
||||||
|
|||||||
@@ -64,6 +64,7 @@
|
|||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
import fuzzy from 'fuzzy';
|
||||||
import { databaseObjectIcons, handleDatabaseObjectClick } from '../appobj/DatabaseObjectAppObject.svelte';
|
import { databaseObjectIcons, handleDatabaseObjectClick } from '../appobj/DatabaseObjectAppObject.svelte';
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
import {
|
import {
|
||||||
@@ -106,12 +107,25 @@
|
|||||||
$: databaseInfo = useDatabaseInfo({ conid, database });
|
$: databaseInfo = useDatabaseInfo({ conid, database });
|
||||||
$: connectionList = useConnectionList();
|
$: connectionList = useConnectionList();
|
||||||
|
|
||||||
$: filteredItems = ($visibleCommandPalette == 'database'
|
$: filteredItems = fuzzy
|
||||||
? extractDbItems($databaseInfo, { conid, database }, $connectionList)
|
.filter(
|
||||||
: parentCommand
|
filter,
|
||||||
? parentCommand.getSubCommands()
|
($visibleCommandPalette == 'database'
|
||||||
: sortedComands
|
? extractDbItems($databaseInfo, { conid, database }, $connectionList)
|
||||||
).filter(x => !x.isGroupCommand && filterName(filter, x.text));
|
: 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) {
|
function handleCommand(command) {
|
||||||
if (command.getSubCommands) {
|
if (command.getSubCommands) {
|
||||||
@@ -194,7 +208,7 @@
|
|||||||
{#if command.icon}
|
{#if command.icon}
|
||||||
<span class="mr-1"><FontIcon icon={command.icon} /></span>
|
<span class="mr-1"><FontIcon icon={command.icon} /></span>
|
||||||
{/if}
|
{/if}
|
||||||
{command.text}
|
{@html command.text}
|
||||||
</div>
|
</div>
|
||||||
{#if command.keyText}
|
{#if command.keyText}
|
||||||
<div class="shortcut">{command.keyText}</div>
|
<div class="shortcut">{command.keyText}</div>
|
||||||
|
|||||||
@@ -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"
|
resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834"
|
||||||
integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==
|
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:
|
gauge@~2.7.3:
|
||||||
version "2.7.4"
|
version "2.7.4"
|
||||||
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"
|
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"
|
||||||
|
|||||||
Reference in New Issue
Block a user