import*as TextUtils from"../text_utils/text_utils.js";export function toPos(t){return{start:new CodeMirror.Pos(t.startLine,t.startColumn),end:new CodeMirror.Pos(t.endLine,t.endColumn)}}export function toRange(t,e){return new TextUtils.TextRange.TextRange(t.line,t.ch,e.line,e.ch)}export function changeObjectToEditOperation(t){const e=toRange(t.from,t.to),n=e.clone(),r=t.text.length;return 0===r?(n.endLine=n.startLine,n.endColumn=n.startColumn):1===r?(n.endLine=n.startLine,n.endColumn=n.startColumn+t.text[0].length):(n.endLine=n.startLine+r-1,n.endColumn=t.text[r-1].length),{oldRange:e,newRange:n}}export function pullLines(t,e){const n=[];return t.eachLine(0,e,(function(t){n.push(t.text)})),n}let tokenizerFactoryInstance;export class TokenizerFactory extends TextUtils.TextUtils.TokenizerFactory{static instance(t={forceNew:null}){const{forceNew:e}=t;return tokenizerFactoryInstance&&!e||(tokenizerFactoryInstance=new TokenizerFactory),tokenizerFactoryInstance}getMode(t){return CodeMirror.getMode({indentUnit:2},t)}createTokenizer(t,e){const n=e||CodeMirror.getMode({indentUnit:2},t),r=CodeMirror.startState(n);return function(t,e){const o=new CodeMirror.StringStream(t);for(;!o.eol();){const t=n.token(o,r),i=o.current();e(i,t,o.start,o.start+i.length),o.start=o.pos}}}}