"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../_vendor/@codemirror/autocomplete/dist-index.cjs");
const index$2 = require("../_vendor/@codemirror/commands/dist-index.cjs");
const index$1 = require("../_vendor/@codemirror/search/dist-index.cjs");
const index$3 = require("../_vendor/@codemirror/language/dist-index.cjs");
const index$4 = require("../_vendor/@codemirror/lint/dist-index.cjs");
const index$5 = require("../_vendor/@codemirror/state/dist-index.cjs");
const multiCursor = require("./multi-cursor.cjs");
const format = require("./format.cjs");
const SELECTED_AUTOCOMPLETE_OPTION_SELECTOR = ".cm-tooltip-autocomplete li[aria-selected]";
const onAutocompleteNavigate = (dir) => (view) => {
  var _a;
  if (index.completionStatus(view.state) !== null) {
    index.moveCompletionSelection(dir === "down")(view);
    (_a = document.querySelector(SELECTED_AUTOCOMPLETE_OPTION_SELECTOR)) == null ? void 0 : _a.scrollIntoView({ block: "nearest" });
    return true;
  }
  return false;
};
const editorKeymap = [
  { key: "Ctrl-Space", run: index.startCompletion },
  { key: "Escape", run: index.closeCompletion },
  {
    key: "Escape",
    run: (view) => {
      if (view.state.selection.ranges.length > 1) {
        view.dispatch({
          selection: index$5.EditorSelection.single(view.state.selection.main.head)
        });
        return true;
      }
      return false;
    }
  },
  {
    key: "ArrowDown",
    run: onAutocompleteNavigate("down")
  },
  {
    key: "ArrowUp",
    run: onAutocompleteNavigate("up")
  },
  { key: "PageDown", run: index.moveCompletionSelection(true, "page") },
  { key: "PageUp", run: index.moveCompletionSelection(false, "page") },
  { key: "Enter", run: index.acceptCompletion },
  { key: "Tab", run: index.acceptCompletion },
  { key: "Mod-f", run: index$1.openSearchPanel, scope: "editor search-panel" },
  { key: "Escape", run: index$1.closeSearchPanel, scope: "editor search-panel" },
  { key: "Alt-Enter", run: index$1.selectMatches, scope: "editor search-panel" },
  { key: "Mod-Alt-Enter", run: index$1.replaceAll, scope: "editor search-panel" },
  { key: "Ctrl-g", run: index$1.gotoLine },
  { key: "Mod-d", run: index$1.selectNextOccurrence, preventDefault: true },
  { key: "Shift-Mod-l", run: index$1.selectSelectionMatches },
  { key: "Enter", run: index$2.insertNewlineAndIndent, shift: index$2.insertNewlineAndIndent },
  {
    key: "ArrowLeft",
    run: index$2.cursorCharLeft,
    shift: index$2.selectCharLeft,
    preventDefault: true
  },
  {
    key: "Mod-ArrowLeft",
    mac: "Alt-ArrowLeft",
    run: index$2.cursorGroupLeft,
    shift: index$2.selectGroupLeft
  },
  {
    key: "ArrowRight",
    run: index$2.cursorCharRight,
    shift: index$2.selectCharRight,
    preventDefault: true
  },
  {
    key: "Mod-ArrowRight",
    mac: "Alt-ArrowRight",
    run: index$2.cursorGroupRight,
    shift: index$2.selectGroupRight
  },
  {
    key: "ArrowUp",
    run: index$2.cursorLineUp,
    shift: index$2.selectLineUp,
    preventDefault: true
  },
  {
    key: "ArrowDown",
    run: index$2.cursorLineDown,
    shift: index$2.selectLineDown,
    preventDefault: true
  },
  {
    key: "Home",
    run: index$2.cursorLineBoundaryBackward,
    shift: index$2.selectLineBoundaryBackward
  },
  {
    mac: "Cmd-ArrowLeft",
    run: index$2.cursorLineBoundaryBackward,
    shift: index$2.selectLineBoundaryBackward
  },
  { key: "Mod-Home", run: index$2.cursorDocStart, shift: index$2.selectDocStart },
  { mac: "Cmd-ArrowUp", run: index$2.cursorDocStart, shift: index$2.selectDocStart },
  { key: "PageUp", run: index$2.cursorPageUp, shift: index$2.selectPageUp },
  { mac: "Ctrl-ArrowUp", run: index$2.cursorPageUp, shift: index$2.selectPageUp },
  { key: "PageDown", run: index$2.cursorPageDown, shift: index$2.selectPageDown },
  { mac: "Ctrl-ArrowDown", run: index$2.cursorPageDown, shift: index$2.selectPageDown },
  {
    key: "End",
    run: index$2.cursorLineBoundaryForward,
    shift: index$2.selectLineBoundaryForward
  },
  {
    mac: "Cmd-ArrowRight",
    run: index$2.cursorLineBoundaryForward,
    shift: index$2.selectLineBoundaryForward
  },
  {
    key: "Mod-Alt-ArrowUp",
    linux: "Shift-Alt-ArrowUp",
    run: multiCursor.addCursorUp,
    preventDefault: true
  },
  {
    key: "Mod-Alt-ArrowDown",
    linux: "Shift-Alt-ArrowDown",
    run: multiCursor.addCursorDown,
    preventDefault: true
  },
  {
    key: "Shift-Alt-i",
    run: multiCursor.addCursorAtEachSelectionLine
  },
  { key: "Mod-End", run: index$2.cursorDocEnd, shift: index$2.selectDocEnd },
  { mac: "Cmd-ArrowDown", run: index$2.cursorDocEnd, shift: index$2.selectDocEnd },
  { key: "Mod-a", run: index$2.selectAll },
  { key: "Backspace", run: index.deleteBracketPair },
  { key: "Backspace", run: index$2.deleteCharBackward, shift: index$2.deleteCharBackward },
  { key: "Delete", run: index$2.deleteCharForward },
  { key: "Mod-Backspace", mac: "Alt-Backspace", run: index$2.deleteGroupBackward },
  { key: "Mod-Delete", mac: "Alt-Delete", run: index$2.deleteGroupForward },
  { mac: "Mod-Backspace", run: index$2.deleteToLineStart },
  { mac: "Mod-Delete", run: index$2.deleteToLineEnd },
  {
    mac: "Ctrl-b",
    run: index$2.cursorCharLeft,
    shift: index$2.selectCharLeft,
    preventDefault: true
  },
  { mac: "Ctrl-f", run: index$2.cursorCharRight, shift: index$2.selectCharRight },
  { mac: "Ctrl-p", run: index$2.cursorLineUp, shift: index$2.selectLineUp },
  { mac: "Ctrl-n", run: index$2.cursorLineDown, shift: index$2.selectLineDown },
  { mac: "Ctrl-a", run: index$2.cursorLineStart, shift: index$2.selectLineStart },
  { mac: "Ctrl-e", run: index$2.cursorLineEnd, shift: index$2.selectLineEnd },
  { mac: "Ctrl-d", run: index$2.deleteCharForward },
  { mac: "Ctrl-h", run: index$2.deleteCharBackward },
  { mac: "Ctrl-k", run: index$2.deleteToLineEnd },
  { mac: "Ctrl-Alt-h", run: index$2.deleteGroupBackward },
  { mac: "Ctrl-o", run: index$2.splitLine },
  { mac: "Ctrl-t", run: index$2.transposeChars },
  { mac: "Ctrl-v", run: index$2.cursorPageDown },
  { mac: "Alt-v", run: index$2.cursorPageUp },
  { key: "Shift-Mod-k", run: index$2.deleteLine },
  { key: "Alt-ArrowDown", run: index$2.moveLineDown },
  { key: "Alt-ArrowUp", run: index$2.moveLineUp },
  { win: "Shift-Alt-ArrowDown", mac: "Shift-Alt-ArrowDown", run: index$2.copyLineDown },
  { win: "Shift-Alt-ArrowUp", mac: "Shift-Alt-ArrowUp", run: index$2.copyLineUp },
  { key: "Mod-l", run: index$2.selectLine, preventDefault: true },
  { key: "Shift-Mod-\\", run: index$2.cursorMatchingBracket },
  {
    any(view, event) {
      if (event.key === "Tab" || event.key === "Escape" && index.completionStatus(view.state) !== null) {
        event.stopPropagation();
      }
      return false;
    }
  },
  { key: "Tab", run: index$2.indentMore, shift: index$2.indentLess, preventDefault: true },
  { key: "Mod-[", run: index$2.indentLess },
  { key: "Mod-]", run: index$2.indentMore },
  { key: "Ctrl-Shift-[", mac: "Cmd-Alt-[", run: index$3.foldCode },
  { key: "Ctrl-Shift-]", mac: "Cmd-Alt-]", run: index$3.unfoldCode },
  { key: "Mod-k Mod-0", run: index$3.foldAll },
  { key: "Mod-k Mod-j", run: index$3.unfoldAll },
  { key: "Mod-k Mod-c", run: index$2.lineComment },
  { key: "Mod-k Mod-u", run: index$2.lineUncomment },
  { key: "Mod-/", run: index$2.toggleComment },
  { key: "Shift-Alt-a", run: index$2.toggleBlockComment },
  { key: "Mod-z", run: index$2.undo, preventDefault: true },
  { key: "Mod-y", run: index$2.redo, preventDefault: true },
  { key: "Mod-Shift-z", run: index$2.redo, preventDefault: true },
  { key: "Mod-u", run: index$2.undoSelection, preventDefault: true },
  { key: "Mod-Shift-m", run: index$4.openLintPanel },
  { key: "F8", run: index$4.nextDiagnostic },
  { key: "Shift-F8", run: index$4.previousDiagnostic },
  { key: "Shift-Alt-f", linux: "Ctrl-Shift-i", run: format.formatDocument },
  {
    key: "Mod-Enter",
    run: (view) => {
      const { state } = view;
      const { from } = state.selection.main;
      const line = state.doc.lineAt(from);
      const lineEnd = line.to;
      const lineText = line.text;
      const match = lineText.match(/^(\s*)/);
      const indent = match ? match[1] : "";
      const insertText = "\n" + indent;
      view.dispatch({
        changes: {
          from: lineEnd,
          to: lineEnd,
          insert: insertText
        },
        selection: {
          anchor: lineEnd + insertText.length
        }
      });
      return true;
    },
    preventDefault: true
  },
  {
    key: "Mod-s",
    run: (view) => {
      format.formatDocument(view);
      return true;
    },
    preventDefault: true
  }
];
exports.editorKeymap = editorKeymap;
//# sourceMappingURL=keymap.cjs.map
