mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-21 17:09:09 +01:00
Stop autocomplete from jumping around
This commit is contained in:
5
Makefile
5
Makefile
@@ -1,4 +1,7 @@
|
|||||||
.PHONY: sqlx-prepare
|
.PHONY: sqlx-prepare, dev
|
||||||
|
|
||||||
sqlx-prepare:
|
sqlx-prepare:
|
||||||
cd src-tauri && cargo sqlx prepare --database-url 'sqlite://db.sqlite'
|
cd src-tauri && cargo sqlx prepare --database-url 'sqlite://db.sqlite'
|
||||||
|
|
||||||
|
dev:
|
||||||
|
npm run tauri-dev
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ import { useActiveEnvironmentId } from '../hooks/useActiveEnvironmentId';
|
|||||||
import { WorkspaceActionsDropdown } from './WorkspaceActionsDropdown';
|
import { WorkspaceActionsDropdown } from './WorkspaceActionsDropdown';
|
||||||
import { IconButton } from './core/IconButton';
|
import { IconButton } from './core/IconButton';
|
||||||
import { useCreateRequest } from '../hooks/useCreateRequest';
|
import { useCreateRequest } from '../hooks/useCreateRequest';
|
||||||
import { appWindow } from '@tauri-apps/api/window';
|
|
||||||
import { invoke } from '@tauri-apps/api';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
className?: string;
|
className?: string;
|
||||||
|
|||||||
@@ -17,13 +17,19 @@ export interface GenericCompletionConfig {
|
|||||||
|
|
||||||
export function genericCompletion({ options, minMatch = 1 }: GenericCompletionConfig) {
|
export function genericCompletion({ options, minMatch = 1 }: GenericCompletionConfig) {
|
||||||
return function completions(context: CompletionContext) {
|
return function completions(context: CompletionContext) {
|
||||||
const toMatch = context.matchBefore(/^.*/);
|
const toMatch = context.matchBefore(/\w*/);
|
||||||
if (toMatch === null) return null;
|
|
||||||
|
// Only match if we're at the start of the line
|
||||||
|
if (toMatch === null || toMatch.from > 0) return null;
|
||||||
|
|
||||||
const matchedMinimumLength = toMatch.to - toMatch.from >= minMatch;
|
const matchedMinimumLength = toMatch.to - toMatch.from >= minMatch;
|
||||||
if (!matchedMinimumLength && !context.explicit) return null;
|
if (!matchedMinimumLength && !context.explicit) return null;
|
||||||
|
|
||||||
const optionsWithoutExactMatches = options.filter((o) => o.label !== toMatch.text);
|
const optionsWithoutExactMatches = options.filter((o) => o.label !== toMatch.text);
|
||||||
return { from: toMatch.from, options: optionsWithoutExactMatches, info: 'hello', };
|
return {
|
||||||
|
validFor: () => true, // Not really sure why this is all it needs
|
||||||
|
from: toMatch.from,
|
||||||
|
options: optionsWithoutExactMatches,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { CompletionContext } from '@codemirror/autocomplete';
|
import type { CompletionContext } from '@codemirror/autocomplete';
|
||||||
|
import { w } from '@tauri-apps/api/clipboard-79413165';
|
||||||
|
|
||||||
const openTag = '${[ ';
|
const openTag = '${[ ';
|
||||||
const closeTag = ' ]}';
|
const closeTag = ' ]}';
|
||||||
@@ -12,7 +13,7 @@ export interface TwigCompletionConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const MIN_MATCH_VAR = 2;
|
const MIN_MATCH_VAR = 2;
|
||||||
const MIN_MATCH_NAME = 3;
|
const MIN_MATCH_NAME = 1;
|
||||||
|
|
||||||
export function twigCompletion({ options }: TwigCompletionConfig) {
|
export function twigCompletion({ options }: TwigCompletionConfig) {
|
||||||
return function completions(context: CompletionContext) {
|
return function completions(context: CompletionContext) {
|
||||||
@@ -37,16 +38,17 @@ export function twigCompletion({ options }: TwigCompletionConfig) {
|
|||||||
// TODO: Figure out how to make autocomplete stay open if opened explicitly. It sucks when you explicitly
|
// TODO: Figure out how to make autocomplete stay open if opened explicitly. It sucks when you explicitly
|
||||||
// open it, then it closes when you type the next character.
|
// open it, then it closes when you type the next character.
|
||||||
return {
|
return {
|
||||||
|
validFor: () => true, // Not really sure why this is all it needs
|
||||||
from: toMatch.from,
|
from: toMatch.from,
|
||||||
options: options
|
options: options
|
||||||
.map((v) => ({
|
.map((v) => ({
|
||||||
label: toStartOfVariable ? `${openTag}${v.name}${closeTag}` : v.name,
|
label: toStartOfVariable ? `${openTag}${v.name}${closeTag}` : v.name,
|
||||||
apply: `${openTag}${v.name}${closeTag}`,
|
apply: `${openTag}${v.name}${closeTag}`,
|
||||||
type: 'variable',
|
type: 'variable',
|
||||||
matchLen,
|
matchLen: matchLen,
|
||||||
}))
|
}))
|
||||||
// Filter out exact matches
|
// Filter out exact matches
|
||||||
.filter((o) => o.label !== toMatch.text),
|
.filter((o) => o.label !== toMatch.text),
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user