/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{EditorSelection as e,StateField as t,Transaction as n,Facet as r,combineConfig as o,StateEffect as l,ChangeSet as s,ChangeDesc as i,Annotation as a,countColumn as c,Text as f,findClusterBreak as u}from"../../state/dist/index.js";import{EditorView as h,Direction as m}from"../../view/dist/index.js";import{IndentContext as d,getIndentation as p,indentString as g,syntaxTree as y,matchBrackets as v,getIndentUnit as A,indentUnit as k}from"../../language/dist/index.js";import{NodeProp as w}from"../../../@lezer/common/dist/index.js";const D=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=C(e.state,n.from);return r.line?x(e):!!r.block&&B(e)};function S(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let o=e(t,n);return!!o&&(r(n.update(o)),!0)}}const x=/* @__PURE__ */S(E,0),M=/* @__PURE__ */S(b,0),B=/* @__PURE__ */S((e,t)=>b(e,t,function(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),o=n.to<=r.to?r:e.doc.lineAt(n.to);o.from>r.from&&o.from==n.to&&(o=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let l=t.length-1;l>=0&&t[l].to>r.from?t[l].to=o.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:o.to})}return t}(t)),0);function C(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}const O=50;function b(e,t,n=t.selection.ranges){let r=n.map(e=>C(t,e.from).block);if(!r.every(e=>e))return null;let o=n.map((e,n)=>function(e,{open:t,close:n},r,o){let l,s,i=e.sliceDoc(r-O,r),a=e.sliceDoc(o,o+O),c=/\s*$/.exec(i)[0].length,f=/^\s*/.exec(a)[0].length,u=i.length-c;if(i.slice(u-t.length,u)==t&&a.slice(f,f+n.length)==n)return{open:{pos:r-c,margin:c&&1},close:{pos:o+f,margin:f&&1}};o-r<=2*O?l=s=e.sliceDoc(r,o):(l=e.sliceDoc(r,r+O),s=e.sliceDoc(o-O,o));let h=/^\s*/.exec(l)[0].length,m=/\s*$/.exec(s)[0].length,d=s.length-m-n.length;return l.slice(h,h+t.length)==t&&s.slice(d,d+n.length)==n?{open:{pos:r+h+t.length,margin:/\s/.test(l.charAt(h+t.length))?1:0},close:{pos:o-m-n.length,margin:/\s/.test(s.charAt(d-1))?1:0}}:null}(t,r[n],e.from,e.to));if(2!=e&&!o.every(e=>e))return{changes:t.changes(n.map((e,t)=>o[t]?[]:[{from:e.from,insert:r[t].open+" "},{from:e.to,insert:" "+r[t].close}]))};if(1!=e&&o.some(e=>e)){let e=[];for(let t,n=0;n<o.length;n++)if(t=o[n]){let o=r[n],{open:l,close:s}=t;e.push({from:l.pos-o.open.length,to:l.pos+l.margin},{from:s.pos-s.margin,to:s.pos+o.close.length})}return{changes:e}}return null}function E(e,t,n=t.selection.ranges){let r=[],o=-1;e:for(let{from:l,to:s}of n){let e,n=r.length,i=1e9;for(let a=l;a<=s;){let n=t.doc.lineAt(a);if(null==e&&(e=C(t,n.from).line,!e))continue e;if(n.from>o&&(l==s||s>n.from)){o=n.from;let t=/^\s*/.exec(n.text)[0].length,l=t==n.length,s=n.text.slice(t,t+e.length)==e?t:-1;t<n.text.length&&t<i&&(i=t),r.push({line:n,comment:s,token:e,indent:t,empty:l,single:!1})}a=n.to+1}if(i<1e9)for(let t=n;t<r.length;t++)r[t].indent<r[t].line.text.length&&(r[t].indent=i);r.length==n+1&&(r[n].single=!0)}if(2!=e&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:o,indent:l,empty:s,single:i}of r)!i&&s||e.push({from:t.from+l,insert:o+" "});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}if(1!=e&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:o}of r)if(n>=0){let r=t.from+n,l=r+o.length;" "==t.text[l-t.from]&&l++,e.push({from:r,to:l})}return{changes:e}}return null}const T=/* @__PURE__ */a.define(),V=/* @__PURE__ */a.define(),I=/* @__PURE__ */r.define(),R=/* @__PURE__ */r.define({combine:e=>o(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}),J=/* @__PURE__ */t.define({create:()=>Z.empty,update(e,t){let r=t.state.facet(R),o=t.annotation(T);if(o){let n=G.fromTransaction(t,o.selection),l=o.side,s=0==l?e.undone:e.done;return s=n?P(s,s.length,r.minDepth,n):W(s,t.startState.selection),new Z(0==l?o.rest:s,0==l?s:o.rest)}let l=t.annotation(V);if("full"!=l&&"before"!=l||(e=e.isolate()),!1===t.annotation(n.addToHistory))return t.changes.empty?e:e.addMapping(t.changes.desc);let s=G.fromTransaction(t),i=t.annotation(n.time),a=t.annotation(n.userEvent);return s?e=e.addChanges(s,i,a,r,t):t.selection&&(e=e.addSelection(t.startState.selection,i,a,r.newGroupDelay)),"full"!=l&&"after"!=l||(e=e.isolate()),e},toJSON:e=>({done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}),fromJSON:e=>new Z(e.done.map(G.fromJSON),e.undone.map(G.fromJSON))});function N(e={}){return[J,R.of(e),h.domEventHandlers({beforeinput(e,t){let n="historyUndo"==e.inputType?U:"historyRedo"==e.inputType?H:null;return!!n&&(e.preventDefault(),n(t))}})]}function L(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let o=n.field(J,!1);if(!o)return!1;let l=o.pop(e,n,t);return!!l&&(r(l),!0)}}const U=/* @__PURE__ */L(0,!1),H=/* @__PURE__ */L(1,!1),j=/* @__PURE__ */L(0,!0),z=/* @__PURE__ */L(1,!0);class G{constructor(e,t,n,r,o){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=o}setSelAfter(e){return new G(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,n;return{changes:null===(e=this.changes)||void 0===e?void 0:e.toJSON(),mapped:null===(t=this.mapped)||void 0===t?void 0:t.toJSON(),startSelection:null===(n=this.startSelection)||void 0===n?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new G(t.changes&&s.fromJSON(t.changes),[],t.mapped&&i.fromJSON(t.mapped),t.startSelection&&e.fromJSON(t.startSelection),t.selectionsAfter.map(e.fromJSON))}static fromTransaction(e,t){let n=$;for(let r of e.startState.facet(I)){let t=r(e);t.length&&(n=n.concat(t))}return!n.length&&e.changes.empty?null:new G(e.changes.invert(e.startState.doc),n,void 0,t||e.startState.selection,$)}static selection(e){return new G(void 0,$,void 0,void 0,e)}}function P(e,t,n,r){let o=t+1>n+20?t-n-1:0,l=e.slice(o,t);return l.push(r),l}function q(e,t){return e.length?t.length?e.concat(t):e:t}const $=[],F=200;function W(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-F));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),P(e,e.length-1,1e9,n.setSelAfter(r)))}return[G.selection([t])]}function K(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function Q(e,t){if(!e.length)return e;let n=e.length,r=$;for(;n;){let o=X(e[n-1],t,r);if(o.changes&&!o.changes.empty||o.effects.length){let t=e.slice(0,n);return t[n-1]=o,t}t=o.mapped,n--,r=o.selectionsAfter}return r.length?[G.selection(r)]:$}function X(e,t,n){let r=q(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):$,n);if(!e.changes)return G.selection(r);let o=e.changes.map(t),s=t.mapDesc(e.changes,!0),i=e.mapped?e.mapped.composeDesc(s):s;return new G(o,l.mapEffects(e.effects,t),i,e.startSelection.map(s),r)}const Y=/^(input\.type|delete)($|\.)/;class Z{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new Z(this.done,this.undone):this}addChanges(e,t,n,r,o){let s=this.done,i=s[s.length-1];return s=i&&i.changes&&!i.changes.empty&&e.changes&&(!n||Y.test(n))&&(!i.selectionsAfter.length&&t-this.prevTime<r.newGroupDelay&&r.joinToEvent(o,function(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,o,l)=>{for(let s=0;s<n.length;){let e=n[s++],t=n[s++];l>=e&&o<=t&&(r=!0)}}),r}(i.changes,e.changes))||"input.type.compose"==n)?P(s,s.length-1,r.minDepth,new G(e.changes.compose(i.changes),q(l.mapEffects(e.effects,i.changes),i.effects),i.mapped,i.startSelection,$)):P(s,s.length,r.minDepth,e),new Z(s,$,t,n)}addSelection(e,t,n,r){let o=this.done.length?this.done[this.done.length-1].selectionsAfter:$;return o.length>0&&t-this.prevTime<r&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&(l=o[o.length-1],s=e,l.ranges.length==s.ranges.length&&0===l.ranges.filter((e,t)=>e.empty!=s.ranges[t].empty).length)?this:new Z(W(this.done,e),this.undone,t,n);var l,s}addMapping(e){return new Z(Q(this.done,e),Q(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=0==e?this.done:this.undone;if(0==r.length)return null;let o=r[r.length-1],l=o.selectionsAfter[0]||(o.startSelection?o.startSelection.map(o.changes.invertedDesc,1):t.selection);if(n&&o.selectionsAfter.length)return t.update({selection:o.selectionsAfter[o.selectionsAfter.length-1],annotations:T.of({side:e,rest:K(r),selection:l}),userEvent:0==e?"select.undo":"select.redo",scrollIntoView:!0});if(o.changes){let n=1==r.length?$:r.slice(0,r.length-1);return o.mapped&&(n=Q(n,o.mapped)),t.update({changes:o.changes,selection:o.startSelection,effects:o.effects,annotations:T.of({side:e,rest:n,selection:l}),filter:!1,userEvent:0==e?"undo":"redo",scrollIntoView:!0})}return null}}Z.empty=/* @__PURE__ */new Z($,$);const _=[{key:"Mod-z",run:U,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:H,preventDefault:!0},{linux:"Ctrl-Shift-z",run:H,preventDefault:!0},{key:"Mod-u",run:j,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:z,preventDefault:!0}];function ee(t,n){return e.create(t.ranges.map(n),t.mainIndex)}function te(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function ne({state:e,dispatch:t},n){let r=ee(e.selection,n);return!r.eq(e.selection,!0)&&(t(te(e,r)),!0)}function re(t,n){return e.cursor(n?t.to:t.from)}function oe(e,t){return ne(e,n=>n.empty?e.moveByChar(n,t):re(n,t))}function le(e){return e.textDirectionAt(e.state.selection.main.head)==m.LTR}const se=e=>oe(e,!le(e)),ie=e=>oe(e,le(e));function ae(e,t){return ne(e,n=>n.empty?e.moveByGroup(n,t):re(n,t))}const ce=e=>ae(e,!le(e)),fe=e=>ae(e,le(e));function ue(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function he(t,n,r){let o,l,s=y(t).resolveInner(n.head),i=r?w.closedBy:w.openedBy;for(let e=n.head;;){let n=r?s.childAfter(e):s.childBefore(e);if(!n)break;ue(t,n,i)?s=n:e=r?n.to:n.from}return l=s.type.prop(i)&&(o=r?v(t,s.from,1):v(t,s.to,-1))&&o.matched?r?o.end.to:o.end.from:r?s.to:s.from,e.cursor(l,r?-1:1)}const me=e=>ne(e,t=>he(e.state,t,!le(e))),de=e=>ne(e,t=>he(e.state,t,le(e)));function pe(e,t){return ne(e,n=>{if(!n.empty)return re(n,t);let r=e.moveVertically(n,t);return r.head!=n.head?r:e.moveToLineBoundary(n,t)})}const ge=e=>pe(e,!1),ye=e=>pe(e,!0);function ve(e){let t,n=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,r=0,o=0;if(n){for(let t of e.state.facet(h.scrollMargins)){let n=t(e);(null==n?void 0:n.top)&&(r=Math.max(null==n?void 0:n.top,r)),(null==n?void 0:n.bottom)&&(o=Math.max(null==n?void 0:n.bottom,o))}t=e.scrollDOM.clientHeight-r-o}else t=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:r,marginBottom:o,selfScroll:n,height:Math.max(e.defaultLineHeight,t-5)}}function Ae(e,t){let n,r=ve(e),{state:o}=e,l=ee(o.selection,n=>n.empty?e.moveVertically(n,t,r.height):re(n,t));if(l.eq(o.selection))return!1;if(r.selfScroll){let t=e.coordsAtPos(o.selection.main.head),s=e.scrollDOM.getBoundingClientRect(),i=s.top+r.marginTop,a=s.bottom-r.marginBottom;t&&t.top>i&&t.bottom<a&&(n=h.scrollIntoView(l.main.head,{y:"start",yMargin:t.top-i}))}return e.dispatch(te(o,l),{effects:n}),!0}const ke=e=>Ae(e,!1),we=e=>Ae(e,!0);function De(t,n,r){let o=t.lineBlockAt(n.head),l=t.moveToLineBoundary(n,r);if(l.head==n.head&&l.head!=(r?o.to:o.from)&&(l=t.moveToLineBoundary(n,r,!1)),!r&&l.head==o.from&&o.length){let r=/^\s*/.exec(t.state.sliceDoc(o.from,Math.min(o.from+100,o.to)))[0].length;r&&n.head!=o.from+r&&(l=e.cursor(o.from+r))}return l}const Se=e=>ne(e,t=>De(e,t,!0)),xe=e=>ne(e,t=>De(e,t,!1)),Me=e=>ne(e,t=>De(e,t,!le(e))),Be=e=>ne(e,t=>De(e,t,le(e))),Ce=t=>ne(t,n=>e.cursor(t.lineBlockAt(n.head).from,1)),Oe=t=>ne(t,n=>e.cursor(t.lineBlockAt(n.head).to,-1));const be=({state:t,dispatch:n})=>function(t,n){let r=!1,o=ee(t.selection,n=>{let o=v(t,n.head,-1)||v(t,n.head,1)||n.head>0&&v(t,n.head-1,1)||n.head<t.doc.length&&v(t,n.head+1,-1);if(!o||!o.end)return n;r=!0;let l=o.start.from==n.head?o.end.to:o.end.from;return e.cursor(l)});return!!r&&(n(te(t,o)),!0)}(t,n);function Ee(t,n){let r=ee(t.state.selection,t=>{let r=n(t);return e.range(t.anchor,r.head,r.goalColumn,r.bidiLevel||void 0)});return!r.eq(t.state.selection)&&(t.dispatch(te(t.state,r)),!0)}function Te(e,t){return Ee(e,n=>e.moveByChar(n,t))}const Ve=e=>Te(e,!le(e)),Ie=e=>Te(e,le(e));function Re(e,t){return Ee(e,n=>e.moveByGroup(n,t))}const Je=e=>Re(e,!le(e)),Ne=e=>Re(e,le(e)),Le=e=>Ee(e,t=>he(e.state,t,!le(e))),Ue=e=>Ee(e,t=>he(e.state,t,le(e)));function He(e,t){return Ee(e,n=>e.moveVertically(n,t))}const je=e=>He(e,!1),ze=e=>He(e,!0);function Ge(e,t){return Ee(e,n=>e.moveVertically(n,t,ve(e).height))}const Pe=e=>Ge(e,!1),qe=e=>Ge(e,!0),$e=e=>Ee(e,t=>De(e,t,!0)),Fe=e=>Ee(e,t=>De(e,t,!1)),We=e=>Ee(e,t=>De(e,t,!le(e))),Ke=e=>Ee(e,t=>De(e,t,le(e))),Qe=t=>Ee(t,n=>e.cursor(t.lineBlockAt(n.head).from)),Xe=t=>Ee(t,n=>e.cursor(t.lineBlockAt(n.head).to)),Ye=({state:e,dispatch:t})=>(t(te(e,{anchor:0})),!0),Ze=({state:e,dispatch:t})=>(t(te(e,{anchor:e.doc.length})),!0),_e=({state:e,dispatch:t})=>(t(te(e,{anchor:e.selection.main.anchor,head:0})),!0),et=({state:e,dispatch:t})=>(t(te(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),tt=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),nt=({state:t,dispatch:n})=>{let r=wt(t).map(({from:n,to:r})=>e.range(n,Math.min(r+1,t.doc.length)));return n(t.update({selection:e.create(r),userEvent:"select"})),!0},rt=({state:t,dispatch:n})=>{let r=ee(t.selection,n=>{let r=y(t),o=r.resolveStack(n.from,1);if(n.empty){let e=r.resolveStack(n.from,-1);e.node.from>=o.node.from&&e.node.to<=o.node.to&&(o=e)}for(let t=o;t;t=t.next){let{node:r}=t;if((r.from<n.from&&r.to>=n.to||r.to>n.to&&r.from<=n.from)&&t.next)return e.range(r.to,r.from)}return n});return!r.eq(t.selection)&&(n(te(t,r)),!0)};function ot(t,n){let{state:r}=t,o=r.selection,l=r.selection.ranges.slice();for(let e of r.selection.ranges){let o=r.doc.lineAt(e.head);if(n?o.to<t.state.doc.length:o.from>0)for(let r=e;;){let e=t.moveVertically(r,n);if(e.head<o.from||e.head>o.to){l.some(t=>t.head==e.head)||l.push(e);break}if(e.head==r.head)break;r=e}}return l.length!=o.ranges.length&&(t.dispatch(te(r,e.create(l,l.length-1))),!0)}const lt=e=>ot(e,!1),st=e=>ot(e,!0),it=({state:t,dispatch:n})=>{let r=t.selection,o=null;return r.ranges.length>1?o=e.create([r.main]):r.main.empty||(o=e.create([e.cursor(r.main.head)])),!!o&&(n(te(t,o)),!0)};function at(t,n){if(t.state.readOnly)return!1;let r="delete.selection",{state:o}=t,l=o.changeByRange(o=>{let{from:l,to:s}=o;if(l==s){let e=n(o);e<l?(r="delete.backward",e=ct(t,e,!1)):e>l&&(r="delete.forward",e=ct(t,e,!0)),l=Math.min(l,e),s=Math.max(s,e)}else l=ct(t,l,!1),s=ct(t,s,!0);return l==s?{range:o}:{changes:{from:l,to:s},range:e.cursor(l,l<o.head?-1:1)}});return!l.changes.empty&&(t.dispatch(o.update(l,{scrollIntoView:!0,userEvent:r,effects:"delete.selection"==r?h.announce.of(o.phrase("Selection deleted")):void 0})),!0)}function ct(e,t,n){if(e instanceof h)for(let r of e.state.facet(h.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}const ft=(e,t,n)=>at(e,r=>{let o,l,s=r.from,{state:i}=e,a=i.doc.lineAt(s);if(n&&!t&&s>a.from&&s<a.from+200&&!/[^ \t]/.test(o=a.text.slice(0,s-a.from))){if("\t"==o[o.length-1])return s-1;let e=c(o,i.tabSize)%A(i)||A(i);for(let t=0;t<e&&" "==o[o.length-1-t];t++)s--;l=s}else l=u(a.text,s-a.from,t,t)+a.from,l==s&&a.number!=(t?i.doc.lines:1)?l+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(a.text.slice(l-a.from,s-a.from))&&(l=u(a.text,l-a.from,!1,!1)+a.from);return l}),ut=e=>ft(e,!1,!0),ht=e=>ft(e,!0,!1),mt=(e,t)=>at(e,n=>{let r=n.head,{state:o}=e,l=o.doc.lineAt(r),s=o.charCategorizer(r);for(let e=null;;){if(r==(t?l.to:l.from)){r==n.head&&l.number!=(t?o.doc.lines:1)&&(r+=t?1:-1);break}let i=u(l.text,r-l.from,t)+l.from,a=l.text.slice(Math.min(r,i)-l.from,Math.max(r,i)-l.from),c=s(a);if(null!=e&&c!=e)break;" "==a&&r==n.head||(e=c),r=i}return r}),dt=e=>mt(e,!1),pt=e=>mt(e,!0),gt=e=>at(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),yt=e=>at(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),vt=e=>at(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),At=({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:f.of(["",""])},range:e.cursor(t.from)}));return n(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0},kt=({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{if(!n.empty||0==n.from||n.from==t.doc.length)return{range:n};let r=n.from,o=t.doc.lineAt(r),l=r==o.from?r-1:u(o.text,r-o.from,!1)+o.from,s=r==o.to?r+1:u(o.text,r-o.from,!0)+o.from;return{changes:{from:l,to:s,insert:t.doc.slice(r,s).append(t.doc.slice(l,r))},range:e.cursor(s)}});return!r.changes.empty&&(n(t.update(r,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function wt(e){let t=[],n=-1;for(let r of e.selection.ranges){let o=e.doc.lineAt(r.from),l=e.doc.lineAt(r.to);if(r.empty||r.to!=l.from||(l=e.doc.lineAt(r.to-1)),n>=o.number){let e=t[t.length-1];e.to=l.to,e.ranges.push(r)}else t.push({from:o.from,to:l.to,ranges:[r]});n=l.number+1}return t}function Dt(t,n,r){if(t.readOnly)return!1;let o=[],l=[];for(let s of wt(t)){if(r?s.to==t.doc.length:0==s.from)continue;let n=t.doc.lineAt(r?s.to+1:s.from-1),i=n.length+1;if(r){o.push({from:s.to,to:n.to},{from:s.from,insert:n.text+t.lineBreak});for(let n of s.ranges)l.push(e.range(Math.min(t.doc.length,n.anchor+i),Math.min(t.doc.length,n.head+i)))}else{o.push({from:n.from,to:s.from},{from:s.to,insert:t.lineBreak+n.text});for(let t of s.ranges)l.push(e.range(t.anchor-i,t.head-i))}}return!!o.length&&(n(t.update({changes:o,scrollIntoView:!0,selection:e.create(l,t.selection.mainIndex),userEvent:"move.line"})),!0)}const St=({state:e,dispatch:t})=>Dt(e,t,!1),xt=({state:e,dispatch:t})=>Dt(e,t,!0);function Mt(e,t,n){if(e.readOnly)return!1;let r=[];for(let l of wt(e))n?r.push({from:l.from,insert:e.doc.slice(l.from,l.to)+e.lineBreak}):r.push({from:l.to,insert:e.lineBreak+e.doc.slice(l.from,l.to)});let o=e.changes(r);return t(e.update({changes:o,selection:e.selection.map(o,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Bt=({state:e,dispatch:t})=>Mt(e,t,!1),Ct=({state:e,dispatch:t})=>Mt(e,t,!0),Ot=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(wt(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=ee(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),o=e.coordsAtPos(t.head,t.assoc||1);o&&(n=r.bottom+e.documentTop-o.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};const bt=/* @__PURE__ */Tt(!1),Et=/* @__PURE__ */Tt(!0);function Tt(t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let o=n.changeByRange(r=>{let{from:o,to:l}=r,s=n.doc.lineAt(o),i=!t&&o==l&&function(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n,r=y(e).resolveInner(t),o=r.childBefore(t),l=r.childAfter(t);return o&&l&&o.to<=t&&l.from>=t&&(n=o.type.prop(w.closedBy))&&n.indexOf(l.name)>-1&&e.doc.lineAt(o.to).from==e.doc.lineAt(l.from).from&&!/\S/.test(e.sliceDoc(o.to,l.from))?{from:o.to,to:l.from}:null}(n,o);t&&(o=l=(l<=s.to?s:n.doc.lineAt(l)).to);let a=new d(n,{simulateBreak:o,simulateDoubleBreak:!!i}),u=p(a,o);for(null==u&&(u=c(/^\s*/.exec(n.doc.lineAt(o).text)[0],n.tabSize));l<s.to&&/\s/.test(s.text[l-s.from]);)l++;i?({from:o,to:l}=i):o>s.from&&o<s.from+100&&!/\S/.test(s.text.slice(0,o))&&(o=s.from);let h=["",g(n,u)];return i&&h.push(g(n,a.lineIndent(s.from,-1))),{changes:{from:o,to:l,insert:f.of(h)},range:e.cursor(o+1+h[1].length)}});return r(n.update(o,{scrollIntoView:!0,userEvent:"input"})),!0}}function Vt(t,n){let r=-1;return t.changeByRange(o=>{let l=[];for(let e=o.from;e<=o.to;){let s=t.doc.lineAt(e);s.number>r&&(o.empty||o.to>s.from)&&(n(s,l,o),r=s.number),e=s.to+1}let s=t.changes(l);return{changes:l,range:e.range(s.mapPos(o.anchor,1),s.mapPos(o.head,1))}})}const It=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=/* @__PURE__ */Object.create(null),r=new d(e,{overrideIndentation:e=>{let t=n[e];return null==t?-1:t}}),o=Vt(e,(t,o,l)=>{let s=p(r,t.from);if(null==s)return;/\S/.test(t.text)||(s=0);let i=/^\s*/.exec(t.text)[0],a=g(e,s);(i!=a||l.from<t.from+i.length)&&(n[t.from]=s,o.push({from:t.from,to:t.from+i.length,insert:a}))});return o.changes.empty||t(e.update(o,{userEvent:"indent"})),!0},Rt=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(Vt(e,(t,n)=>{n.push({from:t.from,insert:e.facet(k)})}),{userEvent:"input.indent"})),!0),Jt=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(Vt(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let o=c(r,e.tabSize),l=0,s=g(e,Math.max(0,o-A(e)));for(;l<r.length&&l<s.length&&r.charCodeAt(l)==s.charCodeAt(l);)l++;n.push({from:t.from+l,to:t.from+r.length,insert:s.slice(l)})}),{userEvent:"delete.dedent"})),!0),Nt=e=>(e.setTabFocusMode(),!0),Lt=[{key:"Ctrl-b",run:se,shift:Ve,preventDefault:!0},{key:"Ctrl-f",run:ie,shift:Ie},{key:"Ctrl-p",run:ge,shift:je},{key:"Ctrl-n",run:ye,shift:ze},{key:"Ctrl-a",run:Ce,shift:Qe},{key:"Ctrl-e",run:Oe,shift:Xe},{key:"Ctrl-d",run:ht},{key:"Ctrl-h",run:ut},{key:"Ctrl-k",run:gt},{key:"Ctrl-Alt-h",run:dt},{key:"Ctrl-o",run:At},{key:"Ctrl-t",run:kt},{key:"Ctrl-v",run:we}],Ut=/* @__PURE__ */[{key:"ArrowLeft",run:se,shift:Ve,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:ce,shift:Je,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Me,shift:We,preventDefault:!0},{key:"ArrowRight",run:ie,shift:Ie,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:fe,shift:Ne,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Be,shift:Ke,preventDefault:!0},{key:"ArrowUp",run:ge,shift:je,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Ye,shift:_e},{mac:"Ctrl-ArrowUp",run:ke,shift:Pe},{key:"ArrowDown",run:ye,shift:ze,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Ze,shift:et},{mac:"Ctrl-ArrowDown",run:we,shift:qe},{key:"PageUp",run:ke,shift:Pe},{key:"PageDown",run:we,shift:qe},{key:"Home",run:xe,shift:Fe,preventDefault:!0},{key:"Mod-Home",run:Ye,shift:_e},{key:"End",run:Se,shift:$e,preventDefault:!0},{key:"Mod-End",run:Ze,shift:et},{key:"Enter",run:bt,shift:bt},{key:"Mod-a",run:tt},{key:"Backspace",run:ut,shift:ut,preventDefault:!0},{key:"Delete",run:ht,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:dt,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:pt,preventDefault:!0},{mac:"Mod-Backspace",run:yt,preventDefault:!0},{mac:"Mod-Delete",run:vt,preventDefault:!0}].concat(/* @__PURE__ */Lt.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),Ht=/* @__PURE__ */[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:me,shift:Le},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:de,shift:Ue},{key:"Alt-ArrowUp",run:St},{key:"Shift-Alt-ArrowUp",run:Bt},{key:"Alt-ArrowDown",run:xt},{key:"Shift-Alt-ArrowDown",run:Ct},{key:"Mod-Alt-ArrowUp",run:lt},{key:"Mod-Alt-ArrowDown",run:st},{key:"Escape",run:it},{key:"Mod-Enter",run:Et},{key:"Alt-l",mac:"Ctrl-l",run:nt},{key:"Mod-i",run:rt,preventDefault:!0},{key:"Mod-[",run:Jt},{key:"Mod-]",run:Rt},{key:"Mod-Alt-\\",run:It},{key:"Shift-Mod-k",run:Ot},{key:"Shift-Mod-\\",run:be},{key:"Mod-/",run:D},{key:"Alt-A",run:M},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Nt}].concat(Ut),jt={key:"Tab",run:Rt,shift:Jt};export{lt as addCursorAbove,st as addCursorBelow,Ct as copyLineDown,Bt as copyLineUp,se as cursorCharLeft,ie as cursorCharRight,Ze as cursorDocEnd,Ye as cursorDocStart,ce as cursorGroupLeft,fe as cursorGroupRight,xe as cursorLineBoundaryBackward,Se as cursorLineBoundaryForward,Me as cursorLineBoundaryLeft,Be as cursorLineBoundaryRight,ye as cursorLineDown,Oe as cursorLineEnd,Ce as cursorLineStart,ge as cursorLineUp,be as cursorMatchingBracket,we as cursorPageDown,ke as cursorPageUp,me as cursorSyntaxLeft,de as cursorSyntaxRight,Ht as defaultKeymap,ut as deleteCharBackward,ht as deleteCharForward,dt as deleteGroupBackward,pt as deleteGroupForward,Ot as deleteLine,yt as deleteLineBoundaryBackward,vt as deleteLineBoundaryForward,gt as deleteToLineEnd,Lt as emacsStyleKeymap,N as history,_ as historyKeymap,Jt as indentLess,Rt as indentMore,It as indentSelection,jt as indentWithTab,Et as insertBlankLine,bt as insertNewlineAndIndent,I as invertedEffects,V as isolateHistory,xt as moveLineDown,St as moveLineUp,H as redo,z as redoSelection,tt as selectAll,Ve as selectCharLeft,Ie as selectCharRight,et as selectDocEnd,_e as selectDocStart,Je as selectGroupLeft,Ne as selectGroupRight,nt as selectLine,Fe as selectLineBoundaryBackward,$e as selectLineBoundaryForward,We as selectLineBoundaryLeft,Ke as selectLineBoundaryRight,ze as selectLineDown,Xe as selectLineEnd,Qe as selectLineStart,je as selectLineUp,qe as selectPageDown,Pe as selectPageUp,rt as selectParentSyntax,Le as selectSyntaxLeft,Ue as selectSyntaxRight,it as simplifySelection,At as splitLine,Ut as standardKeymap,M as toggleBlockComment,B as toggleBlockCommentByLine,D as toggleComment,x as toggleLineComment,Nt as toggleTabFocusMode,kt as transposeChars,U as undo,j as undoSelection};