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.3 KB
Raw Blame
import type { DatabaseType, TreeNode } from "@/types/database";

interface SidebarTreeDeleteShortcutContext {
  activeNode: TreeNode;
  selectedNodes: readonly TreeNode[];
  databaseTypeForNode: (node: TreeNode) => DatabaseType | undefined;
  requestHBaseTableDelete: () => boolean;
  requestDefaultDelete: () => boolean;
}

function isUnmodifiedDeleteShortcut(event: KeyboardEvent): boolean {
  return !event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey && (event.key === "Delete" || event.key === "Backspace");
}

export function handleSidebarTreeDeleteShortcut(event: KeyboardEvent, context: SidebarTreeDeleteShortcutContext): boolean {
  if (!isUnmodifiedDeleteShortcut(event)) return false;

  const activeHBaseTable = context.activeNode.type === "table" && context.databaseTypeForNode(context.activeNode) === "hbase";
  const hasActiveMultiSelection = context.selectedNodes.length > 1 && context.selectedNodes.some((node) => node.id === context.activeNode.id);
  if (activeHBaseTable && hasActiveMultiSelection) {
    event.preventDefault();
    event.stopPropagation();
    return true;
  }

  const handled = activeHBaseTable ? context.requestHBaseTableDelete() : context.requestDefaultDelete();
  if (!handled) return false;

  event.preventDefault();
  event.stopPropagation();
  return true;
}