Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.1 KB
Raw Blame
import type { EditorView } from "@codemirror/view";

type CompletionSelectionMover = (forward: boolean) => (view: EditorView) => boolean;

export function queryEditorCompletionNavigationDirection(event: Pick<KeyboardEvent, "key" | "ctrlKey" | "metaKey" | "altKey" | "shiftKey" | "isComposing">): boolean | null {
  // IME composition keys must never drive editor shortcuts (repo convention:
  // composition-period keys are ignored everywhere else in the editor).
  if (event.isComposing) return null;
  if (!event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return null;
  const key = event.key.toLowerCase();
  if (key === "n") return true;
  if (key === "p") return false;
  return null;
}

export function handleQueryEditorCompletionNavigation(view: EditorView, event: KeyboardEvent, moveCompletionSelection: CompletionSelectionMover | null | undefined): boolean {
  const direction = queryEditorCompletionNavigationDirection(event);
  if (direction === null || !moveCompletionSelection) return false;
  const handled = moveCompletionSelection(direction)(view);
  if (handled) event.preventDefault();
  return handled;
}