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.
3 lines
20 KiB
JavaScript
3 lines
20 KiB
JavaScript
import{E as S,V as J,c as U,e as oe,D as f,d as he,r as ue}from"./cm-view-CiSFjroV.js";import{b as fe,S as Q,P as de,E as p,F as X,e as Y,c as me,d as ge,f as pe,C as g,l as xe,m as Se,i as Z}from"./cm-state-X9WpHEQO.js";import{c as m}from"./vendor-crelt-C8TCjufn.js";const K=typeof String.prototype.normalize=="function"?r=>r.normalize("NFKD"):r=>r;class C{constructor(e,t,n=0,i=e.length,s,l){this.test=l,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(n,i),this.bufferStart=n,this.normalize=s?c=>s(K(c)):K,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return me(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=pe(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=ge(e);let i=this.normalize(t);if(i.length)for(let s=0,l=n;;s++){let c=i.charCodeAt(s),a=this.match(c,l,this.bufferPos+this.bufferStart);if(s==i.length-1){if(a)return this.value=a,this;break}l==n&&s<t.length&&t.charCodeAt(s)==c&&l++}}}match(e,t,n){let i=null;for(let s=0;s<this.matches.length;s+=2){let l=this.matches[s],c=!1;this.query.charCodeAt(l)==e&&(l==this.query.length-1?i={from:this.matches[s+1],to:n}:(this.matches[s]++,c=!0)),c||(this.matches.splice(s,2),s-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?i={from:t,to:n}:this.matches.push(1,t)),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null),i}}typeof Symbol<"u"&&(C.prototype[Symbol.iterator]=function(){return this});const ee={from:-1,to:-1,match:/.*/.exec("")},_="gm"+(/x/.unicode==null?"":"u");class te{constructor(e,t,n,i=0,s=e.length){if(this.text=e,this.to=s,this.curLine="",this.done=!1,this.value=ee,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new re(e,t,n,i,s);this.re=new RegExp(t,_+(n?.ignoreCase?"i":"")),this.test=n?.test,this.iter=e.iter();let l=e.lineAt(i);this.curLineStart=l.from,this.matchPos=D(e,i),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,i=n+t[0].length;if(this.matchPos=D(this.text,i+(n==i?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<i||n>this.value.to)&&(!this.test||this.test(n,i,t)))return this.value={from:n,to:i,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const T=new WeakMap;class v{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,n){let i=T.get(e);if(!i||i.from>=n||i.to<=t){let c=new v(t,e.sliceString(t,n));return T.set(e,c),c}if(i.from==t&&i.to==n)return i;let{text:s,from:l}=i;return l>t&&(s=e.sliceString(t,l)+s,l=t),i.to<n&&(s+=e.sliceString(i.to,n)),T.set(e,new v(l,s)),new v(t,s.slice(t-l,n-l))}}class re{constructor(e,t,n,i,s){this.text=e,this.to=s,this.done=!1,this.value=ee,this.matchPos=D(e,i),this.re=new RegExp(t,_+(n?.ignoreCase?"i":"")),this.test=n?.test,this.flat=v.get(e,i,this.chunkEnd(i+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let n=this.flat.from+t.index,i=n+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(n,i,t)))return this.value={from:n,to:i,match:t},this.matchPos=D(this.text,i+(n==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=v.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(te.prototype[Symbol.iterator]=re.prototype[Symbol.iterator]=function(){return this});function Me(r){try{return new RegExp(r,_),!0}catch{return!1}}function D(r,e){if(e>=r.length)return e;let t=r.lineAt(e),n;for(;e<t.to&&(n=t.text.charCodeAt(e-t.from))>=56320&&n<57344;)e++;return e}const ye=r=>{let{state:e}=r,t=String(e.doc.lineAt(r.state.selection.main.head).number),{close:n,result:i}=oe(r,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:t},focus:!0,submitLabel:e.phrase("go")});return i.then(s=>{let l=s&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(s.elements.line.value);if(!l){r.dispatch({effects:n});return}let c=e.doc.lineAt(e.selection.main.head),[,a,o,h,d]=l,A=h?+h.slice(1):0,k=o?+o:c.number;if(o&&d){let I=k/100;a&&(I=I*(a=="-"?-1:1)+c.number/e.doc.lines),k=Math.round(e.doc.lines*I)}else o&&a&&(k=k*(a=="-"?-1:1)+c.number);let V=e.doc.line(Math.max(1,Math.min(e.doc.lines,k))),H=p.cursor(V.from+Math.max(0,Math.min(A,V.length)));r.dispatch({effects:[n,S.scrollIntoView(H.from,{y:"center"})],selection:H})}),!0},ve={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Ce=X.define({combine(r){return Y(r,ve,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Je(r){return[Ae,We]}const be=f.mark({class:"cm-selectionMatch"}),ke=f.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function G(r,e,t,n){return(t==0||r(e.sliceDoc(t-1,t))!=g.Word)&&(n==e.doc.length||r(e.sliceDoc(n,n+1))!=g.Word)}function Le(r,e,t,n){return r(e.sliceDoc(t,t+1))==g.Word&&r(e.sliceDoc(n-1,n))==g.Word}const We=J.fromClass(class{constructor(r){this.decorations=this.getDeco(r)}update(r){(r.selectionSet||r.docChanged||r.viewportChanged)&&(this.decorations=this.getDeco(r.view))}getDeco(r){let e=r.state.facet(Ce),{state:t}=r,n=t.selection;if(n.ranges.length>1)return f.none;let i=n.main,s,l=null;if(i.empty){if(!e.highlightWordAroundCursor)return f.none;let a=t.wordAt(i.head);if(!a)return f.none;l=t.charCategorizer(i.head),s=t.sliceDoc(a.from,a.to)}else{let a=i.to-i.from;if(a<e.minSelectionLength||a>200)return f.none;if(e.wholeWords){if(s=t.sliceDoc(i.from,i.to),l=t.charCategorizer(i.head),!(G(l,t,i.from,i.to)&&Le(l,t,i.from,i.to)))return f.none}else if(s=t.sliceDoc(i.from,i.to),!s)return f.none}let c=[];for(let a of r.visibleRanges){let o=new C(t.doc,s,a.from,a.to);for(;!o.next().done;){let{from:h,to:d}=o.value;if((!l||G(l,t,h,d))&&(i.empty&&h<=i.from&&d>=i.to?c.push(ke.range(h,d)):(h>=i.to||d<=i.from)&&c.push(be.range(h,d)),c.length>e.maxMatches))return f.none}}return f.set(c)}},{decorations:r=>r.decorations}),Ae=S.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),Ee=({state:r,dispatch:e})=>{let{selection:t}=r,n=p.create(t.ranges.map(i=>r.wordAt(i.head)||p.cursor(i.head)),t.mainIndex);return n.eq(t)?!1:(e(r.update({selection:n})),!0)};function Fe(r,e){let{main:t,ranges:n}=r.selection,i=r.wordAt(t.head),s=i&&i.from==t.from&&i.to==t.to;for(let l=!1,c=new C(r.doc,e,n[n.length-1].to);;)if(c.next(),c.done){if(l)return null;c=new C(r.doc,e,0,Math.max(0,n[n.length-1].from-1)),l=!0}else{if(l&&n.some(a=>a.from==c.value.from))continue;if(s){let a=r.wordAt(c.value.from);if(!a||a.from!=c.value.from||a.to!=c.value.to)continue}return c.value}}const De=({state:r,dispatch:e})=>{let{ranges:t}=r.selection;if(t.some(s=>s.from===s.to))return Ee({state:r,dispatch:e});let n=r.sliceDoc(t[0].from,t[0].to);if(r.selection.ranges.some(s=>r.sliceDoc(s.from,s.to)!=n))return!1;let i=Fe(r,n);return i?(e(r.update({selection:r.selection.addRange(p.range(i.from,i.to),!1),effects:S.scrollIntoView(i.to)})),!0):!1},b=X.define({combine(r){return Y(r,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Ne(e),scrollToMatch:e=>S.scrollIntoView(e)})}});class ne{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||Me(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,n)=>n=="n"?`
|
||
`:n=="r"?"\r":n=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new Te(this):new we(this)}getCursor(e,t=0,n){let i=e.doc?e:xe.create({doc:e});return n==null&&(n=i.doc.length),this.regexp?y(this,i,t,n):M(this,i,t,n)}}class ie{constructor(e){this.spec=e}}function Re(r,e,t){return(n,i,s,l)=>{if(t&&!t(n,i,s,l))return!1;let c=n>=l&&i<=l+s.length?s.slice(n-l,i-l):e.doc.sliceString(n,i);return r(c,e,n,i)}}function M(r,e,t,n){let i;return r.wholeWord&&(i=qe(e.doc,e.charCategorizer(e.selection.main.head))),r.test&&(i=Re(r.test,e,i)),new C(e.doc,r.unquoted,t,n,r.caseSensitive?void 0:s=>s.toLowerCase(),i)}function qe(r,e){return(t,n,i,s)=>((s>t||s+i.length<n)&&(s=Math.max(0,t-2),i=r.sliceString(s,Math.min(r.length,n+2))),(e(R(i,t-s))!=g.Word||e(q(i,t-s))!=g.Word)&&(e(q(i,n-s))!=g.Word||e(R(i,n-s))!=g.Word))}class we extends ie{constructor(e){super(e)}nextMatch(e,t,n){let i=M(this.spec,e,n,e.doc.length).nextOverlapping();if(i.done){let s=Math.min(e.doc.length,t+this.spec.unquoted.length);i=M(this.spec,e,0,s).nextOverlapping()}return i.done||i.value.from==t&&i.value.to==n?null:i.value}prevMatchInRange(e,t,n){for(let i=n;;){let s=Math.max(t,i-1e4-this.spec.unquoted.length),l=M(this.spec,e,s,i),c=null;for(;!l.nextOverlapping().done;)c=l.value;if(c)return c;if(s==t)return null;i-=1e4}}prevMatch(e,t,n){let i=this.prevMatchInRange(e,0,t);return i||(i=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length)),i&&(i.from!=t||i.to!=n)?i:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=M(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=t)return null;i.push(n.value)}return i}highlight(e,t,n,i){let s=M(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!s.next().done;)i(s.value.from,s.value.to)}}function Pe(r,e,t){return(n,i,s)=>(!t||t(n,i,s))&&r(s[0],e,n,i)}function y(r,e,t,n){let i;return r.wholeWord&&(i=Ie(e.charCategorizer(e.selection.main.head))),r.test&&(i=Pe(r.test,e,i)),new te(e.doc,r.search,{ignoreCase:!r.caseSensitive,test:i},t,n)}function R(r,e){return r.slice(Z(r,e,!1),e)}function q(r,e){return r.slice(e,Z(r,e))}function Ie(r){return(e,t,n)=>!n[0].length||(r(R(n.input,n.index))!=g.Word||r(q(n.input,n.index))!=g.Word)&&(r(q(n.input,n.index+n[0].length))!=g.Word||r(R(n.input,n.index+n[0].length))!=g.Word)}class Te extends ie{nextMatch(e,t,n){let i=y(this.spec,e,n,e.doc.length).next();return i.done&&(i=y(this.spec,e,0,t).next()),i.done?null:i.value}prevMatchInRange(e,t,n){for(let i=1;;i++){let s=Math.max(t,n-i*1e4),l=y(this.spec,e,s,n),c=null;for(;!l.next().done;)c=l.value;if(c&&(s==t||c.from>s+10))return c;if(s==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n=="&")return e.match[0];if(n=="$")return"$";for(let i=n.length;i>0;i--){let s=+n.slice(0,i);if(s>0&&s<e.match.length)return e.match[s]+n.slice(i)}return t})}matchAll(e,t){let n=y(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=t)return null;i.push(n.value)}return i}highlight(e,t,n,i){let s=y(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!s.next().done;)i(s.value.from,s.value.to)}}const L=Q.define(),z=Q.define(),x=fe.define({create(r){return new O($(r).create(),null)},update(r,e){for(let t of e.effects)t.is(L)?r=new O(t.value.create(),r.panel):t.is(z)&&(r=new O(r.query,t.value?B:null));return r},provide:r=>he.from(r,e=>e.panel)});class O{constructor(e,t){this.query=e,this.panel=t}}const Oe=f.mark({class:"cm-searchMatch"}),$e=f.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Qe=J.fromClass(class{constructor(r){this.view=r,this.decorations=this.highlight(r.state.field(x))}update(r){let e=r.state.field(x);(e!=r.startState.field(x)||r.docChanged||r.selectionSet||r.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:r,panel:e}){if(!e||!r.spec.valid)return f.none;let{view:t}=this,n=new Se;for(let i=0,s=t.visibleRanges,l=s.length;i<l;i++){let{from:c,to:a}=s[i];for(;i<l-1&&a>s[i+1].from-500;)a=s[++i].to;r.highlight(t.state,c,a,(o,h)=>{let d=t.state.selection.ranges.some(A=>A.from==o&&A.to==h);n.add(o,h,d?$e:Oe)})}return n.finish()}},{decorations:r=>r.decorations});function W(r){return e=>{let t=e.state.field(x,!1);return t&&t.query.spec.valid?r(e,t):ce(e)}}const w=W((r,{query:e})=>{let{to:t}=r.state.selection.main,n=e.nextMatch(r.state,t,t);if(!n)return!1;let i=p.single(n.from,n.to),s=r.state.facet(b);return r.dispatch({selection:i,effects:[N(r,n),s.scrollToMatch(i.main,r)],userEvent:"select.search"}),le(r),!0}),P=W((r,{query:e})=>{let{state:t}=r,{from:n}=t.selection.main,i=e.prevMatch(t,n,n);if(!i)return!1;let s=p.single(i.from,i.to),l=r.state.facet(b);return r.dispatch({selection:s,effects:[N(r,i),l.scrollToMatch(s.main,r)],userEvent:"select.search"}),le(r),!0}),_e=W((r,{query:e})=>{let t=e.matchAll(r.state,1e3);return!t||!t.length?!1:(r.dispatch({selection:p.create(t.map(n=>p.range(n.from,n.to))),userEvent:"select.search.matches"}),!0)}),ze=({state:r,dispatch:e})=>{let t=r.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:n,to:i}=t.main,s=[],l=0;for(let c=new C(r.doc,r.sliceDoc(n,i));!c.next().done;){if(s.length>1e3)return!1;c.value.from==n&&(l=s.length),s.push(p.range(c.value.from,c.value.to))}return e(r.update({selection:p.create(s,l),userEvent:"select.search.matches"})),!0},j=W((r,{query:e})=>{let{state:t}=r,{from:n,to:i}=t.selection.main;if(t.readOnly)return!1;let s=e.nextMatch(t,n,n);if(!s)return!1;let l=s,c=[],a,o,h=[];l.from==n&&l.to==i&&(o=t.toText(e.getReplacement(l)),c.push({from:l.from,to:l.to,insert:o}),l=e.nextMatch(t,l.from,l.to),h.push(S.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(n).number)+".")));let d=r.state.changes(c);return l&&(a=p.single(l.from,l.to).map(d),h.push(N(r,l)),h.push(t.facet(b).scrollToMatch(a.main,r))),r.dispatch({changes:d,selection:a,effects:h,userEvent:"input.replace"}),!0}),Be=W((r,{query:e})=>{if(r.state.readOnly)return!1;let t=e.matchAll(r.state,1e9).map(i=>{let{from:s,to:l}=i;return{from:s,to:l,insert:e.getReplacement(i)}});if(!t.length)return!1;let n=r.state.phrase("replaced $ matches",t.length)+".";return r.dispatch({changes:t,effects:S.announce.of(n),userEvent:"input.replace.all"}),!0});function B(r){return r.state.facet(b).createPanel(r)}function $(r,e){var t,n,i,s,l;let c=r.selection.main,a=c.empty||c.to>c.from+100?"":r.sliceDoc(c.from,c.to);if(e&&!a)return e;let o=r.facet(b);return new ne({search:((t=e?.literal)!==null&&t!==void 0?t:o.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(n=e?.caseSensitive)!==null&&n!==void 0?n:o.caseSensitive,literal:(i=e?.literal)!==null&&i!==void 0?i:o.literal,regexp:(s=e?.regexp)!==null&&s!==void 0?s:o.regexp,wholeWord:(l=e?.wholeWord)!==null&&l!==void 0?l:o.wholeWord})}function se(r){let e=U(r,B);return e&&e.dom.querySelector("[main-field]")}function le(r){let e=se(r);e&&e==r.root.activeElement&&e.select()}const ce=r=>{let e=r.state.field(x,!1);if(e&&e.panel){let t=se(r);if(t&&t!=r.root.activeElement){let n=$(r.state,e.query.spec);n.valid&&r.dispatch({effects:L.of(n)}),t.focus(),t.select()}}else r.dispatch({effects:[z.of(!0),e?L.of($(r.state,e.query.spec)):Q.appendConfig.of(He)]});return!0},ae=r=>{let e=r.state.field(x,!1);if(!e||!e.panel)return!1;let t=U(r,B);return t&&t.dom.contains(r.root.activeElement)&&r.focus(),r.dispatch({effects:z.of(!1)}),!0},Ue=[{key:"Mod-f",run:ce,scope:"editor search-panel"},{key:"F3",run:w,shift:P,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:w,shift:P,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:ae,scope:"editor search-panel"},{key:"Mod-Shift-l",run:ze},{key:"Mod-Alt-g",run:ye},{key:"Mod-d",run:De,preventDefault:!0}];class Ne{constructor(e){this.view=e;let t=this.query=e.state.field(x).query.spec;this.commit=this.commit.bind(this),this.searchField=m("input",{value:t.search,placeholder:u(e,"Find"),"aria-label":u(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=m("input",{value:t.replace,placeholder:u(e,"Replace"),"aria-label":u(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=m("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=m("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=m("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function n(i,s,l){return m("button",{class:"cm-button",name:i,onclick:s,type:"button"},l)}this.dom=m("div",{onkeydown:i=>this.keydown(i),class:"cm-search"},[this.searchField,n("next",()=>w(e),[u(e,"next")]),n("prev",()=>P(e),[u(e,"previous")]),n("select",()=>_e(e),[u(e,"all")]),m("label",null,[this.caseField,u(e,"match case")]),m("label",null,[this.reField,u(e,"regexp")]),m("label",null,[this.wordField,u(e,"by word")]),...e.state.readOnly?[]:[m("br"),this.replaceField,n("replace",()=>j(e),[u(e,"replace")]),n("replaceAll",()=>Be(e),[u(e,"replace all")])],m("button",{name:"close",onclick:()=>ae(e),"aria-label":u(e,"close"),type:"button"},["×"])])}commit(){let e=new ne({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:L.of(e)}))}keydown(e){ue(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?P:w)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),j(this.view))}update(e){for(let t of e.transactions)for(let n of t.effects)n.is(L)&&!n.value.eq(this.query)&&this.setQuery(n.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(b).top}}function u(r,e){return r.state.phrase(e)}const E=30,F=/[\s\.,:;?!]/;function N(r,{from:e,to:t}){let n=r.state.doc.lineAt(e),i=r.state.doc.lineAt(t).to,s=Math.max(n.from,e-E),l=Math.min(i,t+E),c=r.state.sliceDoc(s,l);if(s!=n.from){for(let a=0;a<E;a++)if(!F.test(c[a+1])&&F.test(c[a])){c=c.slice(a);break}}if(l!=i){for(let a=c.length-1;a>c.length-E;a--)if(!F.test(c[a-1])&&F.test(c[a])){c=c.slice(0,a);break}}return S.announce.of(`${r.state.phrase("current match")}. ${c} ${r.state.phrase("on line")} ${n.number}.`)}const Ve=S.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),He=[x,de.low(Qe),Ve];export{Je as h,Ue as s};
|