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
/**
 * WebKit (Safari / macOS WKWebView) bug: after CodeMirror replaces DOM text
 * nodes for a paste, `document.getSelection()` reports the correct caret
 * position, but WebKit's native typing insertion point silently keeps
 * pointing at the pre-paste position — the next typed character lands there
 * instead of after the pasted text (e.g. typing "," after pasting "2" into
 * "1,|)" produces "1,,2)" instead of "1,2,)"). A genuine subsequent selection
 * change (as from an arrow key) forces WebKit to re-anchor correctly.
 *
 * Returns a nearby position to briefly move the caret to (and back from)
 * to replicate that nudge, or null if there is nowhere to nudge to.
 */
export interface PasteCaretSelection {
  ranges: readonly unknown[];
  main: { empty: boolean; head: number };
}

export function computePasteCaretResyncTarget(selection: PasteCaretSelection, docLength: number): number | null {
  if (selection.ranges.length !== 1 || !selection.main.empty) return null;
  const head = selection.main.head;
  const nudged = head < docLength ? head + 1 : head - 1;
  if (nudged === head || nudged < 0) return null;
  return nudged;
}