838eec30a8
- Implemented a new composable `useTheme` for managing theme state. - Added functions to read and write theme preference to local storage. - Applied theme styles to the DOM based on user preference. - Introduced a toggle function to switch between light and dark themes. refactor: enhance copilot plugin functionality - Improved request handling with sequence and document versioning. - Refactored ghost text handling to improve clarity and efficiency. - Updated markdown insertion logic to handle parsed content more robustly. - Enhanced error handling and logging for better debugging. style: update global styles for light and dark themes - Defined CSS variables for light and dark themes to streamline styling. - Improved overall styling consistency and responsiveness. - Added transitions for smoother theme changes and interactions.
2 lines
22 KiB
JavaScript
2 lines
22 KiB
JavaScript
import{b as qe,F as oe,E as a,h as $,a as le,A as se,T as P,e as Ke,i as E,S as ce,j as $e,k as We}from"./cm-state-X9WpHEQO.js";import{E as x,a as je}from"./cm-view-CiSFjroV.js";import{I as ie,g as ue,a as R,s as W,m as D,b as G,i as Qe}from"./cm-language-CDsY7zq0.js";import{N as F}from"./vendor-lezer-common-tVQBIsvN.js";const Xe=e=>{let{state:t}=e,r=t.doc.lineAt(t.selection.main.from),n=Q(e.state,r.from);return n.line?Ye(e):n.block?_e(e):!1};function j(e,t){return({state:r,dispatch:n})=>{if(r.readOnly)return!1;let l=e(t,r);return l?(n(r.update(l)),!0):!1}}const Ye=j(tt,0),Ze=j(fe,0),_e=j((e,t)=>fe(e,t,et(t)),0);function Q(e,t){let r=e.languageDataAt("commentTokens",t,1);return r.length?r[0]:{}}const M=50;function we(e,{open:t,close:r},n,l){let o=e.sliceDoc(n-M,n),s=e.sliceDoc(l,l+M),c=/\s*$/.exec(o)[0].length,i=/^\s*/.exec(s)[0].length,f=o.length-c;if(o.slice(f-t.length,f)==t&&s.slice(i,i+r.length)==r)return{open:{pos:n-c,margin:c&&1},close:{pos:l+i,margin:i&&1}};let u,h;l-n<=2*M?u=h=e.sliceDoc(n,l):(u=e.sliceDoc(n,n+M),h=e.sliceDoc(l-M,l));let p=/^\s*/.exec(u)[0].length,O=/\s*$/.exec(h)[0].length,L=h.length-O-r.length;return u.slice(p,p+t.length)==t&&h.slice(L,L+r.length)==r?{open:{pos:n+p+t.length,margin:/\s/.test(u.charAt(p+t.length))?1:0},close:{pos:l-O-r.length,margin:/\s/.test(h.charAt(L-1))?1:0}}:null}function et(e){let t=[];for(let r of e.selection.ranges){let n=e.doc.lineAt(r.from),l=r.to<=n.to?n:e.doc.lineAt(r.to);l.from>n.from&&l.from==r.to&&(l=r.to==n.to+1?n:e.doc.lineAt(r.to-1));let o=t.length-1;o>=0&&t[o].to>n.from?t[o].to=l.to:t.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:l.to})}return t}function fe(e,t,r=t.selection.ranges){let n=r.map(o=>Q(t,o.from).block);if(!n.every(o=>o))return null;let l=r.map((o,s)=>we(t,n[s],o.from,o.to));if(e!=2&&!l.every(o=>o))return{changes:t.changes(r.map((o,s)=>l[s]?[]:[{from:o.from,insert:n[s].open+" "},{from:o.to,insert:" "+n[s].close}]))};if(e!=1&&l.some(o=>o)){let o=[];for(let s=0,c;s<l.length;s++)if(c=l[s]){let i=n[s],{open:f,close:u}=c;o.push({from:f.pos-i.open.length,to:f.pos+f.margin},{from:u.pos-u.margin,to:u.pos+i.close.length})}return{changes:o}}return null}function tt(e,t,r=t.selection.ranges){let n=[],l=-1;for(let{from:o,to:s}of r){let c=n.length,i=1e9,f=Q(t,o).line;if(f){for(let u=o;u<=s;){let h=t.doc.lineAt(u);if(h.from>l&&(o==s||s>h.from)){l=h.from;let p=/^\s*/.exec(h.text)[0].length,O=p==h.length,L=h.text.slice(p,p+f.length)==f?p:-1;p<h.text.length&&p<i&&(i=p),n.push({line:h,comment:L,token:f,indent:p,empty:O,single:!1})}u=h.to+1}if(i<1e9)for(let u=c;u<n.length;u++)n[u].indent<n[u].line.text.length&&(n[u].indent=i);n.length==c+1&&(n[c].single=!0)}}if(e!=2&&n.some(o=>o.comment<0&&(!o.empty||o.single))){let o=[];for(let{line:c,token:i,indent:f,empty:u,single:h}of n)(h||!u)&&o.push({from:c.from+f,insert:i+" "});let s=t.changes(o);return{changes:s,selection:t.selection.map(s,1)}}else if(e!=1&&n.some(o=>o.comment>=0)){let o=[];for(let{line:s,comment:c,token:i}of n)if(c>=0){let f=s.from+c,u=f+i.length;s.text[u-s.from]==" "&&u++,o.push({from:f,to:u})}return{changes:o}}return null}const z=se.define(),nt=se.define(),rt=oe.define(),ae=oe.define({combine(e){return Ke(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,r)=>r},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,r)=>(n,l)=>t(n,l)||r(n,l)})}}),he=qe.define({create(){return B.empty},update(e,t){let r=t.state.facet(ae),n=t.annotation(z);if(n){let i=m.fromTransaction(t,n.selection),f=n.side,u=f==0?e.undone:e.done;return i?u=v(u,u.length,r.minDepth,i):u=pe(u,t.startState.selection),new B(f==0?n.rest:u,f==0?u:n.rest)}let l=t.annotation(nt);if((l=="full"||l=="before")&&(e=e.isolate()),t.annotation(P.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let o=m.fromTransaction(t),s=t.annotation(P.time),c=t.annotation(P.userEvent);return o?e=e.addChanges(o,s,c,r,t):t.selection&&(e=e.addSelection(t.startState.selection,s,c,r.newGroupDelay)),(l=="full"||l=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new B(e.done.map(m.fromJSON),e.undone.map(m.fromJSON))}});function un(e={}){return[he,ae.of(e),x.domEventHandlers({beforeinput(t,r){let n=t.inputType=="historyUndo"?de:t.inputType=="historyRedo"?H:null;return n?(t.preventDefault(),n(r)):!1}})]}function I(e,t){return function({state:r,dispatch:n}){if(!t&&r.readOnly)return!1;let l=r.field(he,!1);if(!l)return!1;let o=l.pop(e,r,t);return o?(n(o),!0):!1}}const de=I(0,!1),H=I(1,!1),ot=I(0,!0),lt=I(1,!0);class m{constructor(t,r,n,l,o){this.changes=t,this.effects=r,this.mapped=n,this.startSelection=l,this.selectionsAfter=o}setSelAfter(t){return new m(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,r,n;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(r=this.mapped)===null||r===void 0?void 0:r.toJSON(),startSelection:(n=this.startSelection)===null||n===void 0?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(l=>l.toJSON())}}static fromJSON(t){return new m(t.changes&&$e.fromJSON(t.changes),[],t.mapped&&We.fromJSON(t.mapped),t.startSelection&&a.fromJSON(t.startSelection),t.selectionsAfter.map(a.fromJSON))}static fromTransaction(t,r){let n=g;for(let l of t.startState.facet(rt)){let o=l(t);o.length&&(n=n.concat(o))}return!n.length&&t.changes.empty?null:new m(t.changes.invert(t.startState.doc),n,void 0,r||t.startState.selection,g)}static selection(t){return new m(void 0,g,void 0,void 0,t)}}function v(e,t,r,n){let l=t+1>r+20?t-r-1:0,o=e.slice(l,t);return o.push(n),o}function st(e,t){let r=[],n=!1;return e.iterChangedRanges((l,o)=>r.push(l,o)),t.iterChangedRanges((l,o,s,c)=>{for(let i=0;i<r.length;){let f=r[i++],u=r[i++];c>=f&&s<=u&&(n=!0)}}),n}function ct(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((r,n)=>r.empty!=t.ranges[n].empty).length===0}function me(e,t){return e.length?t.length?e.concat(t):e:t}const g=[],it=200;function pe(e,t){if(e.length){let r=e[e.length-1],n=r.selectionsAfter.slice(Math.max(0,r.selectionsAfter.length-it));return n.length&&n[n.length-1].eq(t)?e:(n.push(t),v(e,e.length-1,1e9,r.setSelAfter(n)))}else return[m.selection([t])]}function ut(e){let t=e[e.length-1],r=e.slice();return r[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),r}function J(e,t){if(!e.length)return e;let r=e.length,n=g;for(;r;){let l=ft(e[r-1],t,n);if(l.changes&&!l.changes.empty||l.effects.length){let o=e.slice(0,r);return o[r-1]=l,o}else t=l.mapped,r--,n=l.selectionsAfter}return n.length?[m.selection(n)]:g}function ft(e,t,r){let n=me(e.selectionsAfter.length?e.selectionsAfter.map(c=>c.map(t)):g,r);if(!e.changes)return m.selection(n);let l=e.changes.map(t),o=t.mapDesc(e.changes,!0),s=e.mapped?e.mapped.composeDesc(o):o;return new m(l,ce.mapEffects(e.effects,t),s,e.startSelection.map(o),n)}const at=/^(input\.type|delete)($|\.)/;class B{constructor(t,r,n=0,l=void 0){this.done=t,this.undone=r,this.prevTime=n,this.prevUserEvent=l}isolate(){return this.prevTime?new B(this.done,this.undone):this}addChanges(t,r,n,l,o){let s=this.done,c=s[s.length-1];return c&&c.changes&&!c.changes.empty&&t.changes&&(!n||at.test(n))&&(!c.selectionsAfter.length&&r-this.prevTime<l.newGroupDelay&&l.joinToEvent(o,st(c.changes,t.changes))||n=="input.type.compose")?s=v(s,s.length-1,l.minDepth,new m(t.changes.compose(c.changes),me(ce.mapEffects(t.effects,c.changes),c.effects),c.mapped,c.startSelection,g)):s=v(s,s.length,l.minDepth,t),new B(s,g,r,n)}addSelection(t,r,n,l){let o=this.done.length?this.done[this.done.length-1].selectionsAfter:g;return o.length>0&&r-this.prevTime<l&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&ct(o[o.length-1],t)?this:new B(pe(this.done,t),this.undone,r,n)}addMapping(t){return new B(J(this.done,t),J(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,r,n){let l=t==0?this.done:this.undone;if(l.length==0)return null;let o=l[l.length-1],s=o.selectionsAfter[0]||r.selection;if(n&&o.selectionsAfter.length)return r.update({selection:o.selectionsAfter[o.selectionsAfter.length-1],annotations:z.of({side:t,rest:ut(l),selection:s}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(o.changes){let c=l.length==1?g:l.slice(0,l.length-1);return o.mapped&&(c=J(c,o.mapped)),r.update({changes:o.changes,selection:o.startSelection,effects:o.effects,annotations:z.of({side:t,rest:c,selection:s}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}B.empty=new B(g,g);const fn=[{key:"Mod-z",run:de,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:ot,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:lt,preventDefault:!0}];function C(e,t){return a.create(e.ranges.map(t),e.mainIndex)}function k(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function A({state:e,dispatch:t},r){let n=C(e.selection,r);return n.eq(e.selection,!0)?!1:(t(k(e,n)),!0)}function N(e,t){return a.cursor(t?e.to:e.from)}function ge(e,t){return A(e,r=>r.empty?e.moveByChar(r,t):N(r,t))}function d(e){return e.textDirectionAt(e.state.selection.main.head)==je.LTR}const ye=e=>ge(e,!d(e)),ke=e=>ge(e,d(e));function Ae(e,t){return A(e,r=>r.empty?e.moveByGroup(r,t):N(r,t))}const ht=e=>Ae(e,!d(e)),dt=e=>Ae(e,d(e));function mt(e,t,r){if(t.type.prop(r))return!0;let n=t.to-t.from;return n&&(n>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function U(e,t,r){let n=W(e).resolveInner(t.head),l=r?F.closedBy:F.openedBy;for(let i=t.head;;){let f=r?n.childAfter(i):n.childBefore(i);if(!f)break;mt(e,f,l)?n=f:i=r?f.to:f.from}let o=n.type.prop(l),s,c;return o&&(s=r?D(e,n.from,1):D(e,n.to,-1))&&s.matched?c=r?s.end.to:s.end.from:c=r?n.to:n.from,a.cursor(c,r?-1:1)}const pt=e=>A(e,t=>U(e.state,t,!d(e))),gt=e=>A(e,t=>U(e.state,t,d(e)));function Be(e,t){return A(e,r=>{if(!r.empty)return N(r,t);let n=e.moveVertically(r,t);return n.head!=r.head?n:e.moveToLineBoundary(r,t)})}const Se=e=>Be(e,!1),De=e=>Be(e,!0);function xe(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,r=0,n=0,l;if(t){for(let o of e.state.facet(x.scrollMargins)){let s=o(e);s?.top&&(r=Math.max(s?.top,r)),s?.bottom&&(n=Math.max(s?.bottom,n))}l=e.scrollDOM.clientHeight-r-n}else l=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:r,marginBottom:n,selfScroll:t,height:Math.max(e.defaultLineHeight,l-5)}}function Ce(e,t){let r=xe(e),{state:n}=e,l=C(n.selection,s=>s.empty?e.moveVertically(s,t,r.height):N(s,t));if(l.eq(n.selection))return!1;let o;if(r.selfScroll){let s=e.coordsAtPos(n.selection.main.head),c=e.scrollDOM.getBoundingClientRect(),i=c.top+r.marginTop,f=c.bottom-r.marginBottom;s&&s.top>i&&s.bottom<f&&(o=x.scrollIntoView(l.main.head,{y:"start",yMargin:s.top-i}))}return e.dispatch(k(n,l),{effects:o}),!0}const Y=e=>Ce(e,!1),q=e=>Ce(e,!0);function S(e,t,r){let n=e.lineBlockAt(t.head),l=e.moveToLineBoundary(t,r);if(l.head==t.head&&l.head!=(r?n.to:n.from)&&(l=e.moveToLineBoundary(t,r,!1)),!r&&l.head==n.from&&n.length){let o=/^\s*/.exec(e.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;o&&t.head!=n.from+o&&(l=a.cursor(n.from+o))}return l}const yt=e=>A(e,t=>S(e,t,!0)),kt=e=>A(e,t=>S(e,t,!1)),At=e=>A(e,t=>S(e,t,!d(e))),Bt=e=>A(e,t=>S(e,t,d(e))),St=e=>A(e,t=>a.cursor(e.lineBlockAt(t.head).from,1)),Dt=e=>A(e,t=>a.cursor(e.lineBlockAt(t.head).to,-1));function xt(e,t,r){let n=!1,l=C(e.selection,o=>{let s=D(e,o.head,-1)||D(e,o.head,1)||o.head>0&&D(e,o.head-1,1)||o.head<e.doc.length&&D(e,o.head+1,-1);if(!s||!s.end)return o;n=!0;let c=s.start.from==o.head?s.end.to:s.end.from;return a.cursor(c)});return n?(t(k(e,l)),!0):!1}const Ct=({state:e,dispatch:t})=>xt(e,t);function y(e,t){let r=C(e.state.selection,n=>{let l=t(n);return a.range(n.anchor,l.head,l.goalColumn,l.bidiLevel||void 0)});return r.eq(e.state.selection)?!1:(e.dispatch(k(e.state,r)),!0)}function Le(e,t){return y(e,r=>e.moveByChar(r,t))}const Me=e=>Le(e,!d(e)),Ee=e=>Le(e,d(e));function Te(e,t){return y(e,r=>e.moveByGroup(r,t))}const Lt=e=>Te(e,!d(e)),Mt=e=>Te(e,d(e)),Et=e=>y(e,t=>U(e.state,t,!d(e))),Tt=e=>y(e,t=>U(e.state,t,d(e)));function Oe(e,t){return y(e,r=>e.moveVertically(r,t))}const be=e=>Oe(e,!1),Re=e=>Oe(e,!0);function ve(e,t){return y(e,r=>e.moveVertically(r,t,xe(e).height))}const Z=e=>ve(e,!1),_=e=>ve(e,!0),Ot=e=>y(e,t=>S(e,t,!0)),bt=e=>y(e,t=>S(e,t,!1)),Rt=e=>y(e,t=>S(e,t,!d(e))),vt=e=>y(e,t=>S(e,t,d(e))),It=e=>y(e,t=>a.cursor(e.lineBlockAt(t.head).from)),Nt=e=>y(e,t=>a.cursor(e.lineBlockAt(t.head).to)),w=({state:e,dispatch:t})=>(t(k(e,{anchor:0})),!0),ee=({state:e,dispatch:t})=>(t(k(e,{anchor:e.doc.length})),!0),te=({state:e,dispatch:t})=>(t(k(e,{anchor:e.selection.main.anchor,head:0})),!0),ne=({state:e,dispatch:t})=>(t(k(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),Ut=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),Vt=({state:e,dispatch:t})=>{let r=V(e).map(({from:n,to:l})=>a.range(n,Math.min(l+1,e.doc.length)));return t(e.update({selection:a.create(r),userEvent:"select"})),!0},Pt=({state:e,dispatch:t})=>{let r=C(e.selection,n=>{let l=W(e),o=l.resolveStack(n.from,1);if(n.empty){let s=l.resolveStack(n.from,-1);s.node.from>=o.node.from&&s.node.to<=o.node.to&&(o=s)}for(let s=o;s;s=s.next){let{node:c}=s;if((c.from<n.from&&c.to>=n.to||c.to>n.to&&c.from<=n.from)&&s.next)return a.range(c.to,c.from)}return n});return r.eq(e.selection)?!1:(t(k(e,r)),!0)};function Ie(e,t){let{state:r}=e,n=r.selection,l=r.selection.ranges.slice();for(let o of r.selection.ranges){let s=r.doc.lineAt(o.head);if(t?s.to<e.state.doc.length:s.from>0)for(let c=o;;){let i=e.moveVertically(c,t);if(i.head<s.from||i.head>s.to){l.some(f=>f.head==i.head)||l.push(i);break}else{if(i.head==c.head)break;c=i}}}return l.length==n.ranges.length?!1:(e.dispatch(k(r,a.create(l,l.length-1))),!0)}const Jt=e=>Ie(e,!1),Gt=e=>Ie(e,!0),Ft=({state:e,dispatch:t})=>{let r=e.selection,n=null;return r.ranges.length>1?n=a.create([r.main]):r.main.empty||(n=a.create([a.cursor(r.main.head)])),n?(t(k(e,n)),!0):!1};function T(e,t){if(e.state.readOnly)return!1;let r="delete.selection",{state:n}=e,l=n.changeByRange(o=>{let{from:s,to:c}=o;if(s==c){let i=t(o);i<s?(r="delete.backward",i=b(e,i,!1)):i>s&&(r="delete.forward",i=b(e,i,!0)),s=Math.min(s,i),c=Math.max(c,i)}else s=b(e,s,!1),c=b(e,c,!0);return s==c?{range:o}:{changes:{from:s,to:c},range:a.cursor(s,s<o.head?-1:1)}});return l.changes.empty?!1:(e.dispatch(n.update(l,{scrollIntoView:!0,userEvent:r,effects:r=="delete.selection"?x.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function b(e,t,r){if(e instanceof x)for(let n of e.state.facet(x.atomicRanges).map(l=>l(e)))n.between(t,t,(l,o)=>{l<t&&o>t&&(t=r?o:l)});return t}const Ne=(e,t,r)=>T(e,n=>{let l=n.from,{state:o}=e,s=o.doc.lineAt(l),c,i;if(r&&!t&&l>s.from&&l<s.from+200&&!/[^ \t]/.test(c=s.text.slice(0,l-s.from))){if(c[c.length-1]==" ")return l-1;let f=$(c,o.tabSize),u=f%G(o)||G(o);for(let h=0;h<u&&c[c.length-1-h]==" ";h++)l--;i=l}else i=E(s.text,l-s.from,t,t)+s.from,i==l&&s.number!=(t?o.doc.lines:1)?i+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(s.text.slice(i-s.from,l-s.from))&&(i=E(s.text,i-s.from,!1,!1)+s.from);return i}),K=e=>Ne(e,!1,!0),Ue=e=>Ne(e,!0,!1),Ve=(e,t)=>T(e,r=>{let n=r.head,{state:l}=e,o=l.doc.lineAt(n),s=l.charCategorizer(n);for(let c=null;;){if(n==(t?o.to:o.from)){n==r.head&&o.number!=(t?l.doc.lines:1)&&(n+=t?1:-1);break}let i=E(o.text,n-o.from,t)+o.from,f=o.text.slice(Math.min(n,i)-o.from,Math.max(n,i)-o.from),u=s(f);if(c!=null&&u!=c)break;(f!=" "||n!=r.head)&&(c=u),n=i}return n}),Pe=e=>Ve(e,!1),zt=e=>Ve(e,!0),Ht=e=>T(e,t=>{let r=e.lineBlockAt(t.head).to;return t.head<r?r:Math.min(e.state.doc.length,t.head+1)}),qt=e=>T(e,t=>{let r=e.moveToLineBoundary(t,!1).head;return t.head>r?r:Math.max(0,t.head-1)}),Kt=e=>T(e,t=>{let r=e.moveToLineBoundary(t,!0).head;return t.head<r?r:Math.min(e.state.doc.length,t.head+1)}),$t=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=e.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:le.of(["",""])},range:a.cursor(n.from)}));return t(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0},Wt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=e.changeByRange(n=>{if(!n.empty||n.from==0||n.from==e.doc.length)return{range:n};let l=n.from,o=e.doc.lineAt(l),s=l==o.from?l-1:E(o.text,l-o.from,!1)+o.from,c=l==o.to?l+1:E(o.text,l-o.from,!0)+o.from;return{changes:{from:s,to:c,insert:e.doc.slice(l,c).append(e.doc.slice(s,l))},range:a.cursor(c)}});return r.changes.empty?!1:(t(e.update(r,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function V(e){let t=[],r=-1;for(let n of e.selection.ranges){let l=e.doc.lineAt(n.from),o=e.doc.lineAt(n.to);if(!n.empty&&n.to==o.from&&(o=e.doc.lineAt(n.to-1)),r>=l.number){let s=t[t.length-1];s.to=o.to,s.ranges.push(n)}else t.push({from:l.from,to:o.to,ranges:[n]});r=o.number+1}return t}function Je(e,t,r){if(e.readOnly)return!1;let n=[],l=[];for(let o of V(e)){if(r?o.to==e.doc.length:o.from==0)continue;let s=e.doc.lineAt(r?o.to+1:o.from-1),c=s.length+1;if(r){n.push({from:o.to,to:s.to},{from:o.from,insert:s.text+e.lineBreak});for(let i of o.ranges)l.push(a.range(Math.min(e.doc.length,i.anchor+c),Math.min(e.doc.length,i.head+c)))}else{n.push({from:s.from,to:o.from},{from:o.to,insert:e.lineBreak+s.text});for(let i of o.ranges)l.push(a.range(i.anchor-c,i.head-c))}}return n.length?(t(e.update({changes:n,scrollIntoView:!0,selection:a.create(l,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const jt=({state:e,dispatch:t})=>Je(e,t,!1),Qt=({state:e,dispatch:t})=>Je(e,t,!0);function Ge(e,t,r){if(e.readOnly)return!1;let n=[];for(let o of V(e))r?n.push({from:o.from,insert:e.doc.slice(o.from,o.to)+e.lineBreak}):n.push({from:o.to,insert:e.lineBreak+e.doc.slice(o.from,o.to)});let l=e.changes(n);return t(e.update({changes:l,selection:e.selection.map(l,r?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Xt=({state:e,dispatch:t})=>Ge(e,t,!1),Yt=({state:e,dispatch:t})=>Ge(e,t,!0),Zt=e=>{if(e.state.readOnly)return!1;let{state:t}=e,r=t.changes(V(t).map(({from:l,to:o})=>(l>0?l--:o<t.doc.length&&o++,{from:l,to:o}))),n=C(t.selection,l=>{let o;if(e.lineWrapping){let s=e.lineBlockAt(l.head),c=e.coordsAtPos(l.head,l.assoc||1);c&&(o=s.bottom+e.documentTop-c.bottom+e.defaultLineHeight/2)}return e.moveVertically(l,!0,o)}).map(r);return e.dispatch({changes:r,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0};function _t(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let r=W(e).resolveInner(t),n=r.childBefore(t),l=r.childAfter(t),o;return n&&l&&n.to<=t&&l.from>=t&&(o=n.type.prop(F.closedBy))&&o.indexOf(l.name)>-1&&e.doc.lineAt(n.to).from==e.doc.lineAt(l.from).from&&!/\S/.test(e.sliceDoc(n.to,l.from))?{from:n.to,to:l.from}:null}const re=Fe(!1),wt=Fe(!0);function Fe(e){return({state:t,dispatch:r})=>{if(t.readOnly)return!1;let n=t.changeByRange(l=>{let{from:o,to:s}=l,c=t.doc.lineAt(o),i=!e&&o==s&&_t(t,o);e&&(o=s=(s<=c.to?c:t.doc.lineAt(s)).to);let f=new ie(t,{simulateBreak:o,simulateDoubleBreak:!!i}),u=ue(f,o);for(u==null&&(u=$(/^\s*/.exec(t.doc.lineAt(o).text)[0],t.tabSize));s<c.to&&/\s/.test(c.text[s-c.from]);)s++;i?{from:o,to:s}=i:o>c.from&&o<c.from+100&&!/\S/.test(c.text.slice(0,o))&&(o=c.from);let h=["",R(t,u)];return i&&h.push(R(t,f.lineIndent(c.from,-1))),{changes:{from:o,to:s,insert:le.of(h)},range:a.cursor(o+1+h[1].length)}});return r(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function X(e,t){let r=-1;return e.changeByRange(n=>{let l=[];for(let s=n.from;s<=n.to;){let c=e.doc.lineAt(s);c.number>r&&(n.empty||n.to>c.from)&&(t(c,l,n),r=c.number),s=c.to+1}let o=e.changes(l);return{changes:l,range:a.range(o.mapPos(n.anchor,1),o.mapPos(n.head,1))}})}const en=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=Object.create(null),n=new ie(e,{overrideIndentation:o=>{let s=r[o];return s??-1}}),l=X(e,(o,s,c)=>{let i=ue(n,o.from);if(i==null)return;/\S/.test(o.text)||(i=0);let f=/^\s*/.exec(o.text)[0],u=R(e,i);(f!=u||c.from<o.from+f.length)&&(r[o.from]=i,s.push({from:o.from,to:o.from+f.length,insert:u}))});return l.changes.empty||t(e.update(l,{userEvent:"indent"})),!0},ze=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(X(e,(r,n)=>{n.push({from:r.from,insert:e.facet(Qe)})}),{userEvent:"input.indent"})),!0),He=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(X(e,(r,n)=>{let l=/^\s*/.exec(r.text)[0];if(!l)return;let o=$(l,e.tabSize),s=0,c=R(e,Math.max(0,o-G(e)));for(;s<l.length&&s<c.length&&l.charCodeAt(s)==c.charCodeAt(s);)s++;n.push({from:r.from+s,to:r.from+l.length,insert:c.slice(s)})}),{userEvent:"delete.dedent"})),!0),tn=e=>(e.setTabFocusMode(),!0),nn=[{key:"Ctrl-b",run:ye,shift:Me,preventDefault:!0},{key:"Ctrl-f",run:ke,shift:Ee},{key:"Ctrl-p",run:Se,shift:be},{key:"Ctrl-n",run:De,shift:Re},{key:"Ctrl-a",run:St,shift:It},{key:"Ctrl-e",run:Dt,shift:Nt},{key:"Ctrl-d",run:Ue},{key:"Ctrl-h",run:K},{key:"Ctrl-k",run:Ht},{key:"Ctrl-Alt-h",run:Pe},{key:"Ctrl-o",run:$t},{key:"Ctrl-t",run:Wt},{key:"Ctrl-v",run:q}],rn=[{key:"ArrowLeft",run:ye,shift:Me,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:ht,shift:Lt,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:At,shift:Rt,preventDefault:!0},{key:"ArrowRight",run:ke,shift:Ee,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:dt,shift:Mt,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Bt,shift:vt,preventDefault:!0},{key:"ArrowUp",run:Se,shift:be,preventDefault:!0},{mac:"Cmd-ArrowUp",run:w,shift:te},{mac:"Ctrl-ArrowUp",run:Y,shift:Z},{key:"ArrowDown",run:De,shift:Re,preventDefault:!0},{mac:"Cmd-ArrowDown",run:ee,shift:ne},{mac:"Ctrl-ArrowDown",run:q,shift:_},{key:"PageUp",run:Y,shift:Z},{key:"PageDown",run:q,shift:_},{key:"Home",run:kt,shift:bt,preventDefault:!0},{key:"Mod-Home",run:w,shift:te},{key:"End",run:yt,shift:Ot,preventDefault:!0},{key:"Mod-End",run:ee,shift:ne},{key:"Enter",run:re,shift:re},{key:"Mod-a",run:Ut},{key:"Backspace",run:K,shift:K,preventDefault:!0},{key:"Delete",run:Ue,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Pe,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:zt,preventDefault:!0},{mac:"Mod-Backspace",run:qt,preventDefault:!0},{mac:"Mod-Delete",run:Kt,preventDefault:!0}].concat(nn.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),an=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:pt,shift:Et},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:gt,shift:Tt},{key:"Alt-ArrowUp",run:jt},{key:"Shift-Alt-ArrowUp",run:Xt},{key:"Alt-ArrowDown",run:Qt},{key:"Shift-Alt-ArrowDown",run:Yt},{key:"Mod-Alt-ArrowUp",run:Jt},{key:"Mod-Alt-ArrowDown",run:Gt},{key:"Escape",run:Ft},{key:"Mod-Enter",run:wt},{key:"Alt-l",mac:"Ctrl-l",run:Vt},{key:"Mod-i",run:Pt,preventDefault:!0},{key:"Mod-[",run:He},{key:"Mod-]",run:ze},{key:"Mod-Alt-\\",run:en},{key:"Shift-Mod-k",run:Zt},{key:"Shift-Mod-\\",run:Ct},{key:"Mod-/",run:Xe},{key:"Alt-A",run:Ze},{key:"Ctrl-m",mac:"Shift-Alt-m",run:tn}].concat(rn),hn={key:"Tab",run:ze,shift:He};export{fn as a,an as d,un as h,hn as i};
|