{"version":3,"file":"multi-cursor.cjs","sources":["../../../app/extensions/multi-cursor.ts"],"sourcesContent":["import { EditorSelection } from \"@codemirror/state\"\nimport type { Command } from \"@codemirror/view\"\n\nconst createAddCursor =\n  (direction: \"up\" | \"down\"): Command =>\n  (view) => {\n    const forward = direction === \"down\"\n\n    let selection = view.state.selection\n\n    for (const r of selection.ranges) {\n      selection = selection.addRange(view.moveVertically(r, forward))\n    }\n\n    view.dispatch({ selection })\n\n    return true\n  }\n\nexport const addCursorUp = createAddCursor(\"up\")\nexport const addCursorDown = createAddCursor(\"down\")\n\nexport const addCursorAtEachSelectionLine: Command = (view) => {\n  let selection: EditorSelection | null = null\n  for (const r of view.state.selection.ranges) {\n    if (r.empty) {\n      continue\n    }\n\n    for (let pos = r.from; pos <= r.to; ) {\n      const line = view.state.doc.lineAt(pos)\n\n      const anchor = Math.min(line.to, r.to)\n\n      if (selection) {\n        selection = selection.addRange(EditorSelection.range(anchor, anchor))\n      } else {\n        selection = EditorSelection.single(anchor)\n      }\n\n      pos = line.to + 1\n    }\n  }\n\n  if (!selection) {\n    return false\n  }\n\n  view.dispatch({ selection })\n\n  return true\n}\n"],"names":["EditorSelection"],"mappings":";;;AAGA,MAAM,kBACJ,CAAC,cACD,CAAC,SAAS;AACR,QAAM,UAAU,cAAc;AAE9B,MAAI,YAAY,KAAK,MAAM;AAE3B,aAAW,KAAK,UAAU,QAAQ;AAChC,gBAAY,UAAU,SAAS,KAAK,eAAe,GAAG,OAAO,CAAC;AAAA,EAChE;AAEA,OAAK,SAAS,EAAE,WAAW;AAE3B,SAAO;AACT;AAEK,MAAM,cAAc,gBAAgB,IAAI;AACxC,MAAM,gBAAgB,gBAAgB,MAAM;AAE5C,MAAM,+BAAwC,CAAC,SAAS;AAC7D,MAAI,YAAoC;AACxC,aAAW,KAAK,KAAK,MAAM,UAAU,QAAQ;AAC3C,QAAI,EAAE,OAAO;AACX;AAAA,IACF;AAEA,aAAS,MAAM,EAAE,MAAM,OAAO,EAAE,MAAM;AACpC,YAAM,OAAO,KAAK,MAAM,IAAI,OAAO,GAAG;AAEtC,YAAM,SAAS,KAAK,IAAI,KAAK,IAAI,EAAE,EAAE;AAErC,UAAI,WAAW;AACb,oBAAY,UAAU,SAASA,MAAAA,gBAAgB,MAAM,QAAQ,MAAM,CAAC;AAAA,MACtE,OAAO;AACL,oBAAYA,MAAAA,gBAAgB,OAAO,MAAM;AAAA,MAC3C;AAEA,YAAM,KAAK,KAAK;AAAA,IAClB;AAAA,EACF;AAEA,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AAEA,OAAK,SAAS,EAAE,WAAW;AAE3B,SAAO;AACT;;;;"}