1// @codemirror/[email protected] downloaded from https://ga.jspm.io/npm:@codemirror/[email protected]/dist/index.js 2 3import{EditorView as e,showPanel as t,getPanel as r,ViewPlugin as i,Decoration as n,runScopeHandlers as s}from"@codemirror/view";import{codePointAt as o,fromCodePoint as l,codePointSize as a,StateEffect as c,EditorSelection as h,StateField as u,Facet as f,combineConfig as d,CharCategory as m,Prec as p,EditorState as g,findClusterBreak as v,RangeSetBuilder as x}from"@codemirror/state";import y from"crelt";const b=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e;class SearchCursor{constructor(e,t,r=0,i=e.length,n,s){this.test=s;this.value={from:0,to:0};this.done=false;this.matches=[];this.buffer="";this.bufferPos=0;this.iter=e.iterRange(r,i);this.bufferStart=r;this.normalize=n?e=>n(b(e)):b;this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){this.bufferStart+=this.buffer.length;this.iter.next();if(this.iter.done)return-1;this.bufferPos=0;this.buffer=this.iter.value}return o(this.buffer,this.bufferPos)}next(){while(this.matches.length)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0){this.done=true;return this}let t=l(e),r=this.bufferStart+this.bufferPos;this.bufferPos+=a(e);let i=this.normalize(t);if(i.length)for(let e=0,n=r;;e++){let s=i.charCodeAt(e);let o=this.match(s,n,this.bufferPos+this.bufferStart);if(e==i.length-1){if(o){this.value=o;return this}break}n==r&&e<t.length&&t.charCodeAt(e)==s&&n++}}}match(e,t,r){let i=null;for(let t=0;t<this.matches.length;t+=2){let n=this.matches[t],s=false;if(this.query.charCodeAt(n)==e)if(n==this.query.length-1)i={from:this.matches[t+1],to:r};else{this.matches[t]++;s=true}if(!s){this.matches.splice(t,2);t-=2}}this.query.charCodeAt(0)==e&&(this.query.length==1?i={from:t,to:r}:this.matches.push(1,t));i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null);return i}}typeof Symbol!="undefined"&&(SearchCursor.prototype[Symbol.iterator]=function(){return this});const w={from:-1,to:-1,match:/.*/.exec("")};const S="gm"+(/x/.unicode==null?"":"u");class RegExpCursor{constructor(e,t,r,i=0,n=e.length){this.text=e;this.to=n;this.curLine="";this.done=false;this.value=w;if(/\\[sWDnr]|\n|\r|\[\^/.test(t))return new MultilineRegExpCursor(e,t,r,i,n);this.re=new RegExp(t,S+((r===null||r===void 0?void 0:r.ignoreCase)?"i":""));this.test=r===null||r===void 0?void 0:r.test;this.iter=e.iter();let s=e.lineAt(i);this.curLineStart=s.from;this.matchPos=C(e,i);this.getLine(this.curLineStart)}getLine(e){this.iter.next(e);if(this.iter.lineBreak)this.curLine="";else{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 r=this.curLineStart+t.index,i=r+t[0].length;this.matchPos=C(this.text,i+(r==i?1:0));r==this.curLineStart+this.curLine.length&&this.nextLine();if((r<i||r>this.value.to)&&(!this.test||this.test(r,i,t))){this.value={from:r,to:i,match:t};return this}e=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length<this.to)){this.done=true;return this}this.nextLine();e=0}}}}const M=new WeakMap;class FlattenedDoc{constructor(e,t){this.from=e;this.text=t}get to(){return this.from+this.text.length}static get(e,t,r){let i=M.get(e);if(!i||i.from>=r||i.to<=t){let i=new FlattenedDoc(t,e.sliceString(t,r));M.set(e,i);return i}if(i.from==t&&i.to==r)return i;let{text:n,from:s}=i;if(s>t){n=e.sliceString(t,s)+n;s=t}i.to<r&&(n+=e.sliceString(i.to,r));M.set(e,new FlattenedDoc(s,n));return new FlattenedDoc(t,n.slice(t-s,r-s))}}class MultilineRegExpCursor{constructor(e,t,r,i,n){this.text=e;this.to=n;this.done=false;this.value=w;this.matchPos=C(e,i);this.re=new RegExp(t,S+((r===null||r===void 0?void 0:r.ignoreCase)?"i":""));this.test=r===null||r===void 0?void 0:r.test;this.flat=FlattenedDoc.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;let 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)}if(t){let e=this.flat.from+t.index,r=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,r,t))){this.value={from:e,to:r,match:t};this.matchPos=C(this.text,r+(e==r?1:0));return this}}if(this.flat.to==this.to){this.done=true;return this}this.flat=FlattenedDoc.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol!="undefined"&&(RegExpCursor.prototype[Symbol.iterator]=MultilineRegExpCursor.prototype[Symbol.iterator]=function(){return this});function k(e){try{new RegExp(e,S);return true}catch(e){return false}}function C(e,t){if(t>=e.length)return t;let r,i=e.lineAt(t);while(t<i.to&&(r=i.text.charCodeAt(t-i.from))>=56320&&r<57344)t++;return t}function q(t){let r=String(t.state.doc.lineAt(t.state.selection.main.head).number);let i=y("input",{class:"cm-textfield",name:"line",value:r});let n=y("form",{class:"cm-gotoLine",onkeydown:e=>{if(e.keyCode==27){e.preventDefault();t.dispatch({effects:L.of(false)});t.focus()}else if(e.keyCode==13){e.preventDefault();s()}},onsubmit:e=>{e.preventDefault();s()}},y("label",t.state.phrase("Go to line"),": ",i)," ",y("button",{class:"cm-button",type:"submit"},t.state.phrase("go")),y("button",{name:"close",onclick:()=>{t.dispatch({effects:L.of(false)});t.focus()},"aria-label":t.state.phrase("close"),type:"button"},["Ã"]));function s(){let r=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(i.value);if(!r)return;let{state:n}=t,s=n.doc.lineAt(n.selection.main.head);let[,o,l,a,c]=r;let u=a?+a.slice(1):0;let f=l?+l:s.number;if(l&&c){let e=f/100;o&&(e=e*(o=="-"?-1:1)+s.number/n.doc.lines);f=Math.round(n.doc.lines*e)}else l&&o&&(f=f*(o=="-"?-1:1)+s.number);let d=n.doc.line(Math.max(1,Math.min(n.doc.lines,f)));let m=h.cursor(d.from+Math.max(0,Math.min(u,d.length)));t.dispatch({effects:[L.of(false),e.scrollIntoView(m.from,{y:"center"})],selection:m});t.focus()}return{dom:n}}const L=c.define();const F=u.define({create(){return true},update(e,t){for(let r of t.effects)r.is(L)&&(e=r.value);return e},provide:e=>t.from(e,(e=>e?q:null))});const D=e=>{let t=r(e,q);if(!t){let i=[L.of(true)];e.state.field(F,false)==null&&i.push(c.appendConfig.of([F,W]));e.dispatch({effects:i});t=r(e,q)}t&&t.dom.querySelector("input").select();return true};const W=e.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px",position:"relative","& label":{fontSize:"80%"},"& [name=close]":{position:"absolute",top:"0",bottom:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:"0"}}});const R={highlightWordAroundCursor:false,minSelectionLength:1,maxMatches:100,wholeWords:false};const A=f.define({combine(e){return d(e,R,{highlightWordAroundCursor:(e,t)=>
3e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function E(e){let t=[$,T];e&&t.push(A.of(e));return t}const P=n.mark({class:"cm-selectionMatch"});const I=n.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Q(e,t,r,i){return(r==0||e(t.sliceDoc(r-1,r))!=m.Word)&&(i==t.doc.length||e(t.sliceDoc(i,i+1))!=m.Word)}function z(e,t,r,i){return e(t.sliceDoc(r,r+1))==m.Word&&e(t.sliceDoc(i-1,i))==m.Word}const T=i.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(A);let{state:r}=e,i=r.selection;if(i.ranges.length>1)return n.none;let s,o=i.main,l=null;if(o.empty){if(!t.highlightWordAroundCursor)return n.none;let e=r.wordAt(o.head);if(!e)return n.none;l=r.charCategorizer(o.head);s=r.sliceDoc(e.from,e.to)}else{let e=o.to-o.from;if(e<t.minSelectionLength||e>200)return n.none;if(t.wholeWords){s=r.sliceDoc(o.from,o.to);l=r.charCategorizer(o.head);if(!(Q(l,r,o.from,o.to)&&z(l,r,o.from,o.to)))return n.none}else{s=r.sliceDoc(o.from,o.to);if(!s)return n.none}}let a=[];for(let i of e.visibleRanges){let e=new SearchCursor(r.doc,s,i.from,i.to);while(!e.next().done){let{from:i,to:s}=e.value;if(!l||Q(l,r,i,s)){o.empty&&i<=o.from&&s>=o.to?a.push(I.range(i,s)):(i>=o.to||s<=o.from)&&a.push(P.range(i,s));if(a.length>t.maxMatches)return n.none}}}return n.set(a)}},{decorations:e=>e.decorations});const $=e.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const O=({state:e,dispatch:t})=>{let{selection:r}=e;let i=h.create(r.ranges.map((t=>e.wordAt(t.head)||h.cursor(t.head))),r.mainIndex);if(i.eq(r))return false;t(e.update({selection:i}));return true};function V(e,t){let{main:r,ranges:i}=e.selection;let n=e.wordAt(r.head),s=n&&n.from==r.from&&n.to==r.to;for(let r=false,n=new SearchCursor(e.doc,t,i[i.length-1].to);;){n.next();if(!n.done){if(r&&i.some((e=>e.from==n.value.from)))continue;if(s){let t=e.wordAt(n.value.from);if(!t||t.from!=n.value.from||t.to!=n.value.to)continue}return n.value}if(r)return null;n=new SearchCursor(e.doc,t,0,Math.max(0,i[i.length-1].from-1));r=true}}const K=({state:t,dispatch:r})=>{let{ranges:i}=t.selection;if(i.some((e=>e.from===e.to)))return O({state:t,dispatch:r});let n=t.sliceDoc(i[0].from,i[0].to);if(t.selection.ranges.some((e=>t.sliceDoc(e.from,e.to)!=n)))return false;let s=V(t,n);if(!s)return false;r(t.update({selection:t.selection.addRange(h.range(s.from,s.to),false),effects:e.scrollIntoView(s.to)}));return true};const B=f.define({combine(t){return d(t,{top:false,caseSensitive:false,literal:false,regexp:false,wholeWord:false,createPanel:e=>new SearchPanel(e),scrollToMatch:t=>e.scrollIntoView(t)})}});function G(e){return e?[B.of(e),ke]:ke}class SearchQuery{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||k(this.search));this.unquoted=this.unquote(this.search);this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,((e,t)=>t=="n"?"\n":t=="r"?"\r":t=="t"?"\t":"\\"))}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new RegExpQuery(this):new StringQuery(this)}getCursor(e,t=0,r){let i=e.doc?e:g.create({doc:e});r==null&&(r=i.doc.length);return this.regexp?H(this,i,t,r):N(this,i,t,r)}}class QueryType{constructor(e){this.spec=e}}function N(e,t,r,i){return new SearchCursor(t.doc,e.unquoted,r,i,e.caseSensitive?void 0:e=>e.toLowerCase(),e.wholeWord?j(t.doc,t.charCategorizer(t.selection.main.head)):void 0)}function j(e,t){return(r,i,n,s)=>{if(s>r||s+n.length<i){s=Math.max(0,r-2);n=e.sliceString(s,Math.min(e.length,i+2))}return(t(J(n,r-s))!=m.Word||t(U(n,r-s))!=m.Word)&&(t(U(n,i-s))!=m.Word||t(J(n,i-s))!=m.Word)}}class StringQuery extends QueryType{constructor(e){super(e)}nextMatch(e,t,r){let i=N(this.spec,e,r,e.doc.length).nextOverlapping();if(i.done){let r=Math.min(e.doc.length,t+this.spec.unquoted.length);i=N(this.spec,e,0,r).nextOverlapping()}return i.done||i.value.from==t&&i.value.to==r?null:i.value}prevMatchInRange(e,t,r){for(let i=r;;){let r=Math.max(t,i-1e4-this.spec.unquoted.length);let n=N(this.spec,e,r,i),s=null;while(!n.nextOverlapping().done)s=n.value;if(s)return s;if(r==t)return null;i-=1e4}}prevMatch(e,t,r){let i=this.prevMatchInRange(e,0,t);i||(i=this.prevMatchInRange(e,Math.max(0,r-this.spec.unquoted.length),e.doc.length));return!i||i.from==t&&i.to==r?null:i}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let r=N(this.spec,e,0,e.doc.length),i=[];while(!r.next().done){if(i.length>=t)return null;i.push(r.value)}return i}
3highlight(e,t,r,i){let n=N(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,e.doc.length));while(!n.next().done)i(n.value.from,n.value.to)}}function H(e,t,r,i){return new RegExpCursor(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:e.wholeWord?X(t.charCategorizer(t.selection.main.head)):void 0},r,i)}function J(e,t){return e.slice(v(e,t,false),t)}function U(e,t){return e.slice(t,v(e,t))}function X(e){return(t,r,i)=>!i[0].length||(e(J(i.input,i.index))!=m.Word||e(U(i.input,i.index))!=m.Word)&&(e(U(i.input,i.index+i[0].length))!=m.Word||e(J(i.input,i.index+i[0].length))!=m.Word)}class RegExpQuery extends QueryType{nextMatch(e,t,r){let i=H(this.spec,e,r,e.doc.length).next();i.done&&(i=H(this.spec,e,0,t).next());return i.done?null:i.value}prevMatchInRange(e,t,r){for(let i=1;;i++){let n=Math.max(t,r-i*1e4);let s=H(this.spec,e,n,r),o=null;while(!s.next().done)o=s.value;if(o&&(n==t||o.from>n+10))return o;if(n==t)return null}}prevMatch(e,t,r){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,r,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,((t,r)=>{if(r=="&")return e.match[0];if(r=="$")return"$";for(let t=r.length;t>0;t--){let i=+r.slice(0,t);if(i>0&&i<e.match.length)return e.match[i]+r.slice(t)}return t}))}matchAll(e,t){let r=H(this.spec,e,0,e.doc.length),i=[];while(!r.next().done){if(i.length>=t)return null;i.push(r.value)}return i}highlight(e,t,r,i){let n=H(this.spec,e,Math.max(0,t-250),Math.min(r+250,e.doc.length));while(!n.next().done)i(n.value.from,n.value.to)}}const Y=c.define();const Z=c.define();const _=u.define({create(e){return new SearchState(de(e).create(),null)},update(e,t){for(let r of t.effects)r.is(Y)?e=new SearchState(r.value.create(),e.panel):r.is(Z)&&(e=new SearchState(e.query,r.value?fe:null));return e},provide:e=>t.from(e,(e=>e.panel))});function ee(e){let t=e.field(_,false);return t?t.query.spec:de(e)}function te(e){var t;return((t=e.field(_,false))===null||t===void 0?void 0:t.panel)!=null}class SearchState{constructor(e,t){this.query=e;this.panel=t}}const re=n.mark({class:"cm-searchMatch"}),ie=n.mark({class:"cm-searchMatch cm-searchMatch-selected"});const ne=i.fromClass(class{constructor(e){this.view=e;this.decorations=this.highlight(e.state.field(_))}update(e){let t=e.state.field(_);(t!=e.startState.field(_)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return n.none;let{view:r}=this;let i=new x;for(let t=0,n=r.visibleRanges,s=n.length;t<s;t++){let{from:o,to:l}=n[t];while(t<s-1&&l>n[t+1].from-500)l=n[++t].to;e.highlight(r.state,o,l,((e,t)=>{let n=r.state.selection.ranges.some((r=>r.from==e&&r.to==t));i.add(e,t,n?ie:re)}))}return i.finish()}},{decorations:e=>e.decorations});function se(e){return t=>{let r=t.state.field(_,false);return r&&r.query.spec.valid?e(t,r):ge(t)}}const oe=se(((e,{query:t})=>{let{to:r}=e.state.selection.main;let i=t.nextMatch(e.state,r,r);if(!i)return false;let n=h.single(i.from,i.to);let s=e.state.facet(B);e.dispatch({selection:n,effects:[Se(e,i),s.scrollToMatch(n.main,e)],userEvent:"select.search"});pe(e);return true}));const le=se(((e,{query:t})=>{let{state:r}=e,{from:i}=r.selection.main;let n=t.prevMatch(r,i,i);if(!n)return false;let s=h.single(n.from,n.to);let o=e.state.facet(B);e.dispatch({selection:s,effects:[Se(e,n),o.scrollToMatch(s.main,e)],userEvent:"select.search"});pe(e);return true}));const ae=se(((e,{query:t})=>{let r=t.matchAll(e.state,1e3);if(!r||!r.length)return false;e.dispatch({selection:h.create(r.map((e=>h.range(e.from,e.to)))),userEvent:"select.search.matches"});return true}));const ce=({state:e,dispatch:t})=>{let r=e.selection;if(r.ranges.length>1||r.main.empty)return false;let{from:i,to:n}=r.main;let s=[],o=0;for(let t=new SearchCursor(e.doc,e.sliceDoc(i,n));!t.next().done;){if(s.length>1e3)return false;t.value.from==i&&(o=s.length);s.push(h.range(t.value.from,t.value.to))}t(e.update({selection:h.create(s,o),userEvent:"select.search.matches"}));return true};const he=se(((t,{query:r})=>{let{state:i}=t,{from:n,to:s}=i.selection.main;if(i.readOnly)return false;let o=r.nextMatch(i,n,n);if(!o)return false;let l=o;let a,c,u=[];let f=[];if(l.from==n&&l.to==s){c=i.toText(r.getReplacement(l));u.push({from:l.from,to:l.to,insert:c});l=r.nextMatch(i,l.from,l.to);f.push(e.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(n).number)+"."))}let d=t.state.changes(u);if(l){a=h.single(l.from,l.to).map(d);f.push(Se(t,l));
3f.push(i.facet(B).scrollToMatch(a.main,t))}t.dispatch({changes:d,selection:a,effects:f,userEvent:"input.replace"});return true}));const ue=se(((t,{query:r})=>{if(t.state.readOnly)return false;let i=r.matchAll(t.state,1e9).map((e=>{let{from:t,to:i}=e;return{from:t,to:i,insert:r.getReplacement(e)}}));if(!i.length)return false;let n=t.state.phrase("replaced $ matches",i.length)+".";t.dispatch({changes:i,effects:e.announce.of(n),userEvent:"input.replace.all"});return true}));function fe(e){return e.state.facet(B).createPanel(e)}function de(e,t){var r,i,n,s,o;let l=e.selection.main;let a=l.empty||l.to>l.from+100?"":e.sliceDoc(l.from,l.to);if(t&&!a)return t;let c=e.facet(B);return new SearchQuery({search:((r=t===null||t===void 0?void 0:t.literal)!==null&&r!==void 0?r:c.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=t===null||t===void 0?void 0:t.caseSensitive)!==null&&i!==void 0?i:c.caseSensitive,literal:(n=t===null||t===void 0?void 0:t.literal)!==null&&n!==void 0?n:c.literal,regexp:(s=t===null||t===void 0?void 0:t.regexp)!==null&&s!==void 0?s:c.regexp,wholeWord:(o=t===null||t===void 0?void 0:t.wholeWord)!==null&&o!==void 0?o:c.wholeWord})}function me(e){let t=r(e,fe);return t&&t.dom.querySelector("[main-field]")}function pe(e){let t=me(e);t&&t==e.root.activeElement&&t.select()}const ge=e=>{let t=e.state.field(_,false);if(t&&t.panel){let r=me(e);if(r&&r!=e.root.activeElement){let i=de(e.state,t.query.spec);i.valid&&e.dispatch({effects:Y.of(i)});r.focus();r.select()}}else e.dispatch({effects:[Z.of(true),t?Y.of(de(e.state,t.query.spec)):c.appendConfig.of(ke)]});return true};const ve=e=>{let t=e.state.field(_,false);if(!t||!t.panel)return false;let i=r(e,fe);i&&i.dom.contains(e.root.activeElement)&&e.focus();e.dispatch({effects:Z.of(false)});return true};const xe=[{key:"Mod-f",run:ge,scope:"editor search-panel"},{key:"F3",run:oe,shift:le,scope:"editor search-panel",preventDefault:true},{key:"Mod-g",run:oe,shift:le,scope:"editor search-panel",preventDefault:true},{key:"Escape",run:ve,scope:"editor search-panel"},{key:"Mod-Shift-l",run:ce},{key:"Mod-Alt-g",run:D},{key:"Mod-d",run:K,preventDefault:true}];class SearchPanel{constructor(e){this.view=e;let t=this.query=e.state.field(_).query.spec;this.commit=this.commit.bind(this);this.searchField=y("input",{value:t.search,placeholder:ye(e,"Find"),"aria-label":ye(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit});this.replaceField=y("input",{value:t.replace,placeholder:ye(e,"Replace"),"aria-label":ye(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit});this.caseField=y("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit});this.reField=y("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit});this.wordField=y("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function r(e,t,r){return y("button",{class:"cm-button",name:e,onclick:t,type:"button"},r)}this.dom=y("div",{onkeydown:e=>this.keydown(e),class:"cm-search"},[this.searchField,r("next",(()=>oe(e)),[ye(e,"next")]),r("prev",(()=>le(e)),[ye(e,"previous")]),r("select",(()=>ae(e)),[ye(e,"all")]),y("label",null,[this.caseField,ye(e,"match case")]),y("label",null,[this.reField,ye(e,"regexp")]),y("label",null,[this.wordField,ye(e,"by word")]),...e.state.readOnly?[]:[y("br"),this.replaceField,r("replace",(()=>he(e)),[ye(e,"replace")]),r("replaceAll",(()=>ue(e)),[ye(e,"replace all")])],y("button",{name:"close",onclick:()=>ve(e),"aria-label":ye(e,"close"),type:"button"},["Ã"])])}commit(){let e=new SearchQuery({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});if(!e.eq(this.query)){this.query=e;this.view.dispatch({effects:Y.of(e)})}}keydown(e){if(s(this.view,e,"search-panel"))e.preventDefault();else if(e.keyCode==13&&e.target==this.searchField){e.preventDefault();(e.shiftKey?le:oe)(this.view)}else if(e.keyCode==13&&e.target==this.replaceField){e.preventDefault();he(this.view)}}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(Y)&&!e.value.eq(this.query)&&this.setQuery(e.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 ye(e,t){return e.state.phrase(t)}const be=30;const we=/[\s\.,:;?!]/;function Se(t,{from:r,to:i}){let n=t.state.doc.lineAt(r),s=t.state.doc.lineAt(i).to;let o=Math.max(n.from,r-be),l=Math.min(s,i+be);let a=t.state.sliceDoc(o,l);if(o!=n.from)for(let e=0;e<be;e++)if(!we.test(a[e+1])&&we.test(a[e])){a=a.slice(e);break}if(l!=s)for(let e=a.length-1;e>a.length-be;e--)if(!we.test(a[e-1])&&we.test(a[e])){a=a.slice(0,e);break}return e.announce.of(`${t.state.phrase("current match")}. ${a} ${t.state.phrase("on line")} ${n.number}.`)}const Me=e.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"}});const ke=[_,p.low(ne),Me];export{RegExpCursor,SearchCursor,SearchQuery,ve as closeSearchPanel,oe as findNext,le as findPrevious,ee as getSearchQuery,D as gotoLine,E as highlightSelectionMatches,ge as openSearchPanel,ue as replaceAll,he as replaceNext,G as search,xe as searchKeymap,te as searchPanelOpen,ae as selectMatches,K as selectNextOccurrence,ce as selectSelectionMatches,Y as setSearchQuery}; 4
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.