texlite 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DESIGN.md +83 -4
- package/README.md +0 -3
- package/README.zh-CN.md +0 -3
- package/dist/client/assets/{AdminUsers-BMwfVHyu.js → AdminUsers-Cau9nlv9.js} +1 -1
- package/dist/client/assets/{CitationLibraryDialog-D_GkXecF.js → CitationLibraryDialog-Cf_bbSq3.js} +1 -1
- package/dist/client/assets/{Dashboard-DhKiB4Lp.js → Dashboard-JQ8pJe2d.js} +2 -2
- package/dist/client/assets/{GitDialog-DHwqaGWR.js → GitDialog-BcqqWKr-.js} +1 -1
- package/dist/client/assets/{GitHubAccountDialog-yUPMZj-e.js → GitHubAccountDialog-Cqcezf6G.js} +1 -1
- package/dist/client/assets/{HistoryDialog-CZK-cFfU.js → HistoryDialog-IurkSJuU.js} +1 -1
- package/dist/client/assets/LatexEditor-msdbtTyG.js +141 -0
- package/dist/client/assets/{PdfPreview-BqohZpfh.js → PdfPreview-BTmvQDCV.js} +1 -1
- package/dist/client/assets/{ProjectIconPickerDialog-63_apW1i.js → ProjectIconPickerDialog-Cbm-0YQW.js} +1 -1
- package/dist/client/assets/{ProjectNavigationDialogs-D8I4OJQB.js → ProjectNavigationDialogs-CozcEa2v.js} +1 -1
- package/dist/client/assets/{ProjectSettings-ChIKBc0N.js → ProjectSettings-BlthcpdA.js} +1 -1
- package/dist/client/assets/ProjectWorkspace-DUPLJCQ3.js +32 -0
- package/dist/client/assets/{SelectionHistoryDialog-DiYNdIe5.js → SelectionHistoryDialog-DiRKiMEt.js} +1 -1
- package/dist/client/assets/{SystemMetricsDialog-B9cIXfPM.js → SystemMetricsDialog-DJJZueSr.js} +1 -1
- package/dist/client/assets/{TagManagementDialog-DqGTPckP.js → TagManagementDialog-3c-WAWQd.js} +1 -1
- package/dist/client/assets/{WordCountDialog-B0pBzLsg.js → WordCountDialog-BqlX2s36.js} +1 -1
- package/dist/client/assets/check-EZ2H-iDj.js +1 -0
- package/dist/client/assets/{chktex-Cp2H8q1t.js → chktex-CZIYuMLb.js} +1 -1
- package/dist/client/assets/{external-link-DtHz2OWn.js → external-link-DGfNJFKy.js} +1 -1
- package/dist/client/assets/{github-B3ClW0wI.js → github-DJezB5ef.js} +1 -1
- package/dist/client/assets/{hard-drive-A2DTDrXg.js → hard-drive-B9h-a7KY.js} +1 -1
- package/dist/client/assets/{index-DprUq41V.js → index-BgeOKYIx.js} +4 -4
- package/dist/client/assets/index-CMBalIBd.css +1 -0
- package/dist/client/assets/{index-Bgr9VmTh.js → index-DmBKxZf9.js} +1 -1
- package/dist/client/assets/{minimize-2-CjavrBs6.js → minimize-2-Crq_SyYM.js} +1 -1
- package/dist/client/assets/{minus-417bfmnF.js → minus-Dn3USloe.js} +1 -1
- package/dist/client/assets/{plus-CCRSrXDi.js → plus-BwKRQJHI.js} +1 -1
- package/dist/client/assets/react-CltQJflK.js +49 -0
- package/dist/client/assets/{refresh-cw-0bKWvgVy.js → refresh-cw-C5yVKb1r.js} +1 -1
- package/dist/client/assets/{search-DhHW3xg7.js → search-CDyQWr9H.js} +1 -1
- package/dist/client/assets/{sigma-ggAZwYZs.js → sigma-9fiQHdlo.js} +1 -1
- package/dist/client/assets/{spellCheck-JOkkBKD7.js → spellCheck-BCpcq-VN.js} +1 -1
- package/dist/client/assets/{tags-jYRdvWMN.js → tags-C_3BvsxV.js} +1 -1
- package/dist/client/assets/{type-CZnTyitQ.js → type-CnT0mBxu.js} +1 -1
- package/dist/client/assets/{user-plus-DFkFh0mU.js → user-plus-pxz36w4w.js} +1 -1
- package/dist/client/assets/{x-CUwbFgRb.js → x-DN0Ol4Ya.js} +1 -1
- package/dist/client/index.html +3 -3
- package/dist/server/anchors.js +57 -96
- package/dist/server/collaboration.js +34 -1
- package/dist/server/db.js +9 -1
- package/dist/server/routes/comments.js +4 -4
- package/dist/server/routes/projectShared.js +11 -2
- package/dist/shared/sourceCommentAnchors.js +128 -0
- package/package.json +1 -1
- package/dist/client/assets/LatexEditor-BuLjoc1X.js +0 -141
- package/dist/client/assets/ProjectWorkspace-D8vBa8aq.js +0 -32
- package/dist/client/assets/check-6jrUH-ay.js +0 -1
- package/dist/client/assets/index-DNQd-LXW.css +0 -1
- package/dist/client/assets/react-BVUjbTTn.js +0 -49
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e}from"./index-
|
|
1
|
+
import{c as e}from"./index-BgeOKYIx.js";const t=e("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);export{t as R};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c}from"./index-
|
|
1
|
+
import{c}from"./index-BgeOKYIx.js";const r=c("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);export{r as S};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as a}from"./index-
|
|
1
|
+
import{c as a}from"./index-BgeOKYIx.js";const e=a("Sigma",[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]);export{e as S};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as w,A as L}from"./index-
|
|
1
|
+
import{g as w,A as L}from"./index-BgeOKYIx.js";import{s as y,c as S}from"./ProjectWorkspace-DUPLJCQ3.js";import"./react-CltQJflK.js";import"./check-EZ2H-iDj.js";import"./x-DN0Ol4Ya.js";import"./search-CDyQWr9H.js";import"./user-plus-pxz36w4w.js";import"./refresh-cw-C5yVKb1r.js";const k=5,f=new Map,C=12,x=S();let E=0;class p extends Error{constructor(){super("A newer writing check replaced this request."),this.name="HarperLintSupersededError"}}function I(e){return e instanceof p}function $(e){const t=[0];let r=0;for(const n of e)r+=n.length,t.push(r);return t}function d(e){return[...new Set(e.map(t=>t.trim()).filter(Boolean))].sort((t,r)=>t.localeCompare(r)).join("\0")}async function v(e,t,r,n){try{return(await w(`/api/projects/${e}/spellcheck`,{method:"POST",body:JSON.stringify({path:t,source:r,clientId:x,sequence:n})})).lints}catch(o){throw o instanceof L&&o.code==="SPELLCHECK_SUPERSEDED"?new p:o}}function A(e,t,r){if(!t.problem)return null;const n={from:t.start,to:t.end},o={from:r[t.start]??-1,to:r[t.end]??-1},i=c=>c.from>=0&&c.to>c.from&&c.to<=e.length,a=c=>i(c)&&e.slice(c.from,c.to)===t.problem;return a(o)?o:a(n)?n:null}function H(e,t,r){const n=A(e,t,r);if(!n)return null;const{from:o,to:i}=n,a=e.slice(o,i);if(!a.trim()||!/[A-Za-z]/.test(a)||t.kind==="Formatting")return null;const c=t.kind==="Spelling"||t.kind==="Typo"?"spelling":"grammar",u=t.suggestions.filter((m,s,l)=>s<k&&l.indexOf(m)===s);return{from:o,to:i,word:a,kind:c,message:t.message,suggestions:u}}function h(e,t){let r=2166136261;for(let n=0;n<t.length;n+=1)r^=t.charCodeAt(n),r=Math.imul(r,16777619);return`${e}\0${t.length}:${r>>>0}`}function g(e,t,r){const n=h(e,t),o=f.get(n);return!o||o.path!==e||o.source!==t||o.dictionary!==r?null:(f.delete(n),f.set(n,o),o.issues)}function R(e,t,r,n){const o=h(e,t);for(f.set(o,{path:e,source:t,dictionary:r,issues:n});f.size>C;){const i=f.keys().next().value;if(i===void 0)break;f.delete(i)}}async function b(e,t,r,n="main.tex"){const o=d(t),i=g(n,e,o);if(i)return i;const a=$(e),c=new Set(t.map(s=>s.trim().toLocaleLowerCase("en-US")).filter(Boolean)),u=new Set,m=r.map(s=>H(e,s,a)).filter(s=>!!s).filter(s=>s.kind!=="spelling"||!c.has(s.word.trim().toLocaleLowerCase("en-US"))).filter(s=>{const l=`${s.from}:${s.to}:${s.kind}`;return u.has(l)?!1:(u.add(l),!0)}).sort((s,l)=>s.from-l.from||s.to-l.to);return R(n,e,o,m),m}async function P(e,t,r,n){const o=d(n),i=g(t,r,o);if(i)return i;const a=await v(e,t,r,++E);return b(r,n,a,t)}function N(e,t,r,n=[]){return y(t)?P(e,t,r,n):Promise.resolve([])}export{p as HarperLintSupersededError,I as isHarperLintSupersededError,N as lintLatex,b as mapLatexLints};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as a}from"./index-
|
|
1
|
+
import{c as a}from"./index-BgeOKYIx.js";const e=a("Tags",[["path",{d:"m15 5 6.3 6.3a2.4 2.4 0 0 1 0 3.4L17 19",key:"1cbfv1"}],["path",{d:"M9.586 5.586A2 2 0 0 0 8.172 5H3a1 1 0 0 0-1 1v5.172a2 2 0 0 0 .586 1.414L8.29 18.29a2.426 2.426 0 0 0 3.42 0l3.58-3.58a2.426 2.426 0 0 0 0-3.42z",key:"135mg7"}],["circle",{cx:"6.5",cy:"9.5",r:".5",fill:"currentColor",key:"5pm5xn"}]]);export{e as T};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e}from"./index-
|
|
1
|
+
import{c as e}from"./index-BgeOKYIx.js";const n=e("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);export{n as T};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e}from"./index-
|
|
1
|
+
import{c as e}from"./index-BgeOKYIx.js";const c=e("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);export{c as U};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as a}from"./index-
|
|
1
|
+
import{c as a}from"./index-BgeOKYIx.js";const t=a("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const h=a("AtSign",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8",key:"7n84p3"}]]);const y=a("BookMarked",[["path",{d:"M10 2v8l3-3 3 3V2",key:"sqw3rj"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}]]);const k=a("BookOpen",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]]);const d=a("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);const p=a("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const c=a("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]]);const s=a("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);const r=a("FileArchive",[["path",{d:"M10 12v-1",key:"v7bkov"}],["path",{d:"M10 18v-2",key:"1cjy8d"}],["path",{d:"M10 7V6",key:"dljcrl"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v16a2 2 0 0 0 .274 1.01",key:"gkbcor"}],["circle",{cx:"10",cy:"20",r:"2",key:"1xzdoj"}]]);const l=a("FileCode2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m5 12-3 3 3 3",key:"oke12k"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]]);const o=a("FileSearch",[["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4.268 21a2 2 0 0 0 1.727 1H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"ms7g94"}],["path",{d:"m9 18-1.5-1.5",key:"1j6qii"}],["circle",{cx:"5",cy:"14",r:"3",key:"ufru5t"}]]);const n=a("FileSpreadsheet",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 17h2",key:"10kma7"}]]);const M=a("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);const i=a("FolderPlus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);const v=a("Folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);const x=a("GitBranch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]);const m=a("ListTree",[["path",{d:"M21 12h-8",key:"1bmf0i"}],["path",{d:"M21 6H8",key:"1pqkrb"}],["path",{d:"M21 18h-8",key:"1tm79t"}],["path",{d:"M3 6v4c0 1.1.9 2 2 2h3",key:"1ywdgy"}],["path",{d:"M3 10v6c0 1.1.9 2 2 2h3",key:"2wc746"}]]);const H=a("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]);const q=a("NotepadText",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"16",height:"18",x:"4",y:"4",rx:"2",key:"1u9h20"}],["path",{d:"M8 10h6",key:"3oa6kw"}],["path",{d:"M8 14h8",key:"1fgep2"}],["path",{d:"M8 18h5",key:"17enja"}]]);const u=a("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);const g=a("ScrollText",[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]]);const f=a("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);const w=a("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const z=a("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]]);const b=a("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);const F=a("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);export{h as A,y as B,p as C,c as D,s as E,o as F,x as G,m as L,H as M,q as N,u as P,g as S,f as T,b as U,F as X,v as a,n as b,l as c,k as d,M as e,t as f,z as g,i as h,d as i,r as j,w as k};
|
package/dist/client/index.html
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource/iosevka@5.2.5/600.css" />
|
|
14
14
|
<link rel="icon" type="image/svg+xml" href="logo.svg" />
|
|
15
15
|
<title>TexLite</title>
|
|
16
|
-
<script type="module" crossorigin src="./assets/index-
|
|
17
|
-
<link rel="modulepreload" crossorigin href="./assets/react-
|
|
18
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
16
|
+
<script type="module" crossorigin src="./assets/index-BgeOKYIx.js"></script>
|
|
17
|
+
<link rel="modulepreload" crossorigin href="./assets/react-CltQJflK.js">
|
|
18
|
+
<link rel="stylesheet" crossorigin href="./assets/index-CMBalIBd.css">
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
|
21
21
|
<div id="root"></div>
|
package/dist/server/anchors.js
CHANGED
|
@@ -1,116 +1,77 @@
|
|
|
1
1
|
import diff_match_patch from "diff-match-patch";
|
|
2
|
-
|
|
2
|
+
import { anchorSource, mapSourceAnchor, sourceAnchorAt } from "../shared/sourceCommentAnchors.js";
|
|
3
3
|
export function createSourceAnchor(source, startInput, endInput) {
|
|
4
|
-
|
|
5
|
-
const endOffset = clamp(Math.max(startInput, endInput), startOffset, source.length);
|
|
6
|
-
return anchorAt(source, startOffset, endOffset, false);
|
|
4
|
+
return sourceAnchorAt(anchorSource(source), startInput, endInput);
|
|
7
5
|
}
|
|
8
|
-
export function reanchorFileComments(db, projectId, filePath, oldSource, newSource) {
|
|
6
|
+
export function reanchorFileComments(db, projectId, filePath, oldSource, newSource, editBatches) {
|
|
9
7
|
if (oldSource === newSource)
|
|
10
8
|
return;
|
|
11
|
-
const
|
|
12
|
-
const diffs = dmp.diff_main(oldSource, newSource, true);
|
|
13
|
-
dmp.diff_cleanupSemantic(diffs);
|
|
14
|
-
const comments = db.prepare(`SELECT id, selected_text, start_offset, end_offset, context_before, context_after
|
|
9
|
+
const comments = db.prepare(`SELECT id, selected_text, start_offset, end_offset, context_before, context_after, orphaned
|
|
15
10
|
FROM comments WHERE project_id = ? AND file_path = ?`).all(projectId, filePath);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
if (!comments.length)
|
|
12
|
+
return;
|
|
13
|
+
// Validate the chain before using it. Disk/HTTP replacements have no Yjs
|
|
14
|
+
// chain, and must fall back to comparing their before/after snapshots.
|
|
15
|
+
const originalAnchors = comments.map((comment) => ({
|
|
16
|
+
startOffset: comment.start_offset, endOffset: comment.end_offset,
|
|
17
|
+
selectedText: comment.selected_text, contextBefore: comment.context_before,
|
|
18
|
+
contextAfter: comment.context_after, orphaned: Boolean(comment.orphaned)
|
|
19
|
+
}));
|
|
20
|
+
let anchors = originalAnchors;
|
|
21
|
+
let replayed = oldSource;
|
|
22
|
+
for (const batch of editBatches ?? []) {
|
|
23
|
+
let after = "";
|
|
24
|
+
let cursor = 0;
|
|
25
|
+
for (const edit of batch) {
|
|
26
|
+
after += replayed.slice(cursor, edit.from) + edit.insert;
|
|
27
|
+
cursor = edit.to;
|
|
32
28
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
after += replayed.slice(cursor);
|
|
30
|
+
anchors = anchors.map((anchor) => mapSourceAnchor(anchor, anchorSource(replayed), anchorSource(after), batch));
|
|
31
|
+
replayed = after;
|
|
32
|
+
}
|
|
33
|
+
if (!editBatches?.length || replayed !== newSource) {
|
|
34
|
+
const dmp = new diff_match_patch();
|
|
35
|
+
const diffs = dmp.diff_main(oldSource, newSource, true);
|
|
36
|
+
dmp.diff_cleanupSemantic(diffs);
|
|
37
|
+
const changes = [];
|
|
38
|
+
let offset = 0;
|
|
39
|
+
let pending = null;
|
|
40
|
+
for (const [kind, text] of diffs) {
|
|
41
|
+
if (kind === 0) {
|
|
42
|
+
if (pending)
|
|
43
|
+
changes.push(pending);
|
|
44
|
+
pending = null;
|
|
45
|
+
offset += text.length;
|
|
37
46
|
}
|
|
38
47
|
else {
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
pending ??= { from: offset, to: offset, insertLength: 0, inferred: true };
|
|
49
|
+
if (kind === -1) {
|
|
50
|
+
offset += text.length;
|
|
51
|
+
pending.to = offset;
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
pending.insertLength += text.length;
|
|
41
55
|
}
|
|
42
56
|
}
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
update.run(orphaned ? comment.selected_text : anchor.selectedText, anchor.startOffset, anchor.endOffset, anchor.contextBefore, anchor.contextAfter, Number(anchor.orphaned), new Date().toISOString(), comment.id);
|
|
57
|
+
if (pending)
|
|
58
|
+
changes.push(pending);
|
|
59
|
+
anchors = originalAnchors.map((anchor) => mapSourceAnchor(anchor, anchorSource(oldSource), anchorSource(newSource), changes));
|
|
47
60
|
}
|
|
61
|
+
const update = db.prepare(`UPDATE comments SET selected_text = ?, start_offset = ?, end_offset = ?,
|
|
62
|
+
context_before = ?, context_after = ?, orphaned = ?, updated_at = ? WHERE id = ?`);
|
|
63
|
+
db.transaction(() => {
|
|
64
|
+
for (const [index, comment] of comments.entries()) {
|
|
65
|
+
const anchor = anchors[index];
|
|
66
|
+
update.run(anchor.selectedText, anchor.startOffset, anchor.endOffset, anchor.contextBefore, anchor.contextAfter, Number(anchor.orphaned), new Date().toISOString(), comment.id);
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
48
69
|
}
|
|
49
70
|
export function offsetToLine(source, offsetInput) {
|
|
50
|
-
const offset =
|
|
71
|
+
const offset = Math.max(0, Math.min(source.length, Number.isFinite(offsetInput) ? Math.floor(offsetInput) : 0));
|
|
51
72
|
let line = 1;
|
|
52
73
|
for (let index = 0; index < offset; index += 1)
|
|
53
74
|
if (source.charCodeAt(index) === 10)
|
|
54
75
|
line += 1;
|
|
55
76
|
return line;
|
|
56
77
|
}
|
|
57
|
-
function anchorAt(source, startOffset, endOffset, orphaned) {
|
|
58
|
-
return {
|
|
59
|
-
startOffset,
|
|
60
|
-
endOffset,
|
|
61
|
-
selectedText: source.slice(startOffset, endOffset),
|
|
62
|
-
contextBefore: source.slice(Math.max(0, startOffset - CONTEXT_SIZE), startOffset),
|
|
63
|
-
contextAfter: source.slice(endOffset, Math.min(source.length, endOffset + CONTEXT_SIZE)),
|
|
64
|
-
orphaned
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function nearestContextualMatch(source, selected, expected, contextBefore, contextAfter) {
|
|
68
|
-
if (!selected)
|
|
69
|
-
return null;
|
|
70
|
-
let best = null;
|
|
71
|
-
let bestRank = Number.NEGATIVE_INFINITY;
|
|
72
|
-
let cursor = 0;
|
|
73
|
-
while (cursor <= source.length) {
|
|
74
|
-
const found = source.indexOf(selected, cursor);
|
|
75
|
-
if (found < 0)
|
|
76
|
-
break;
|
|
77
|
-
const distance = Math.abs(found - expected);
|
|
78
|
-
const before = source.slice(Math.max(0, found - contextBefore.length), found);
|
|
79
|
-
const after = source.slice(found + selected.length, found + selected.length + contextAfter.length);
|
|
80
|
-
const contextScore = commonSuffixLength(before, contextBefore) + commonPrefixLength(after, contextAfter);
|
|
81
|
-
// Do not relocate based solely on proximity. A repeated word with no
|
|
82
|
-
// matching context is ambiguous and must be surfaced as orphaned.
|
|
83
|
-
const availableContext = contextBefore.length + contextAfter.length;
|
|
84
|
-
if (availableContext === 0)
|
|
85
|
-
return null;
|
|
86
|
-
const minimumContext = Math.min(4, availableContext);
|
|
87
|
-
if (contextScore < minimumContext) {
|
|
88
|
-
cursor = found + Math.max(1, selected.length);
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
const rank = contextScore * 1000 - distance;
|
|
92
|
-
if (rank > bestRank) {
|
|
93
|
-
best = found;
|
|
94
|
-
bestRank = rank;
|
|
95
|
-
}
|
|
96
|
-
cursor = found + Math.max(1, selected.length);
|
|
97
|
-
}
|
|
98
|
-
return best;
|
|
99
|
-
}
|
|
100
|
-
function commonPrefixLength(left, right) {
|
|
101
|
-
const limit = Math.min(left.length, right.length);
|
|
102
|
-
let index = 0;
|
|
103
|
-
while (index < limit && left[index] === right[index])
|
|
104
|
-
index += 1;
|
|
105
|
-
return index;
|
|
106
|
-
}
|
|
107
|
-
function commonSuffixLength(left, right) {
|
|
108
|
-
const limit = Math.min(left.length, right.length);
|
|
109
|
-
let count = 0;
|
|
110
|
-
while (count < limit && left[left.length - 1 - count] === right[right.length - 1 - count])
|
|
111
|
-
count += 1;
|
|
112
|
-
return count;
|
|
113
|
-
}
|
|
114
|
-
function clamp(value, min, max) {
|
|
115
|
-
return Math.max(min, Math.min(max, Number.isFinite(value) ? Math.floor(value) : min));
|
|
116
|
-
}
|
|
@@ -701,6 +701,7 @@ export class CollaborationService {
|
|
|
701
701
|
observedContent: new Map(),
|
|
702
702
|
dirtyPaths: new Set(),
|
|
703
703
|
pendingEditSegments: [],
|
|
704
|
+
pendingCommentEdits: new Map(),
|
|
704
705
|
textObservers: new Map(),
|
|
705
706
|
saveTimer: null,
|
|
706
707
|
stateSaveTimer: null,
|
|
@@ -874,6 +875,7 @@ export class CollaborationService {
|
|
|
874
875
|
// edit record; keeping this mirror current prevents later edits from
|
|
875
876
|
// being mapped across such a replacement.
|
|
876
877
|
room.observedContent.set(filePath, after);
|
|
878
|
+
room.pendingCommentEdits.delete(filePath);
|
|
877
879
|
return;
|
|
878
880
|
}
|
|
879
881
|
if (!room.allowedPaths.has(filePath)) {
|
|
@@ -888,6 +890,35 @@ export class CollaborationService {
|
|
|
888
890
|
const connection = transaction.origin;
|
|
889
891
|
this.recordEditStep(room, filePath, connection, event, before, after);
|
|
890
892
|
}
|
|
893
|
+
if (before !== after) {
|
|
894
|
+
const edits = [];
|
|
895
|
+
let offset = 0;
|
|
896
|
+
let pending = null;
|
|
897
|
+
for (const delta of event.delta) {
|
|
898
|
+
if (delta.retain) {
|
|
899
|
+
if (pending)
|
|
900
|
+
edits.push(pending);
|
|
901
|
+
pending = null;
|
|
902
|
+
offset += delta.retain;
|
|
903
|
+
}
|
|
904
|
+
else if (delta.delete || typeof delta.insert === "string") {
|
|
905
|
+
pending ??= { from: offset, to: offset, insert: "", insertLength: 0 };
|
|
906
|
+
if (delta.delete) {
|
|
907
|
+
offset += delta.delete;
|
|
908
|
+
pending.to = offset;
|
|
909
|
+
}
|
|
910
|
+
if (typeof delta.insert === "string") {
|
|
911
|
+
pending.insert += delta.insert;
|
|
912
|
+
pending.insertLength += delta.insert.length;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
if (pending)
|
|
917
|
+
edits.push(pending);
|
|
918
|
+
const batches = room.pendingCommentEdits.get(filePath) ?? [];
|
|
919
|
+
batches.push(edits);
|
|
920
|
+
room.pendingCommentEdits.set(filePath, batches);
|
|
921
|
+
}
|
|
891
922
|
room.observedContent.set(filePath, after);
|
|
892
923
|
room.dirtyPaths.add(filePath);
|
|
893
924
|
};
|
|
@@ -1415,7 +1446,7 @@ export class CollaborationService {
|
|
|
1415
1446
|
room.dirtyPaths.delete(filePath);
|
|
1416
1447
|
finalizedPaths.add(filePath);
|
|
1417
1448
|
try {
|
|
1418
|
-
reanchorFileComments(this.db, room.projectId, filePath, previous, next);
|
|
1449
|
+
reanchorFileComments(this.db, room.projectId, filePath, previous, next, room.pendingCommentEdits.get(filePath));
|
|
1419
1450
|
}
|
|
1420
1451
|
catch { /* Source durability is primary; comments can still be re-anchored by a later edit. */ }
|
|
1421
1452
|
changed = true;
|
|
@@ -1426,6 +1457,8 @@ export class CollaborationService {
|
|
|
1426
1457
|
// A reverted edit or rejected oversized file did not produce a durable
|
|
1427
1458
|
// source revision, so it must not become a misleading edit-history row.
|
|
1428
1459
|
if (finalizedPaths.size > 0) {
|
|
1460
|
+
for (const filePath of finalizedPaths)
|
|
1461
|
+
room.pendingCommentEdits.delete(filePath);
|
|
1429
1462
|
room.pendingEditSegments = room.pendingEditSegments.filter((segment) => !finalizedPaths.has(segment.filePath));
|
|
1430
1463
|
}
|
|
1431
1464
|
if (changed && room.lastModifiedUserId) {
|
package/dist/server/db.js
CHANGED
|
@@ -19,7 +19,15 @@ const databaseMigrations = [
|
|
|
19
19
|
return;
|
|
20
20
|
db.exec("ALTER TABLE projects ADD COLUMN chktex_enabled INTEGER NOT NULL DEFAULT 0 CHECK (chktex_enabled IN (0, 1))");
|
|
21
21
|
} },
|
|
22
|
-
{ version: 3, name: "move_github_tokens_to_user_accounts", apply: migrateGitHubTokensToUsers }
|
|
22
|
+
{ version: 3, name: "move_github_tokens_to_user_accounts", apply: migrateGitHubTokensToUsers },
|
|
23
|
+
{ version: 4, name: "add_comment_resolution_metadata", apply: (db) => {
|
|
24
|
+
if (missingColumn(db, "comments", "resolved_by")) {
|
|
25
|
+
db.exec("ALTER TABLE comments ADD COLUMN resolved_by TEXT REFERENCES users(id) ON DELETE SET NULL");
|
|
26
|
+
}
|
|
27
|
+
if (missingColumn(db, "comments", "resolved_at")) {
|
|
28
|
+
db.exec("ALTER TABLE comments ADD COLUMN resolved_at TEXT");
|
|
29
|
+
}
|
|
30
|
+
} }
|
|
23
31
|
];
|
|
24
32
|
function migrateGitHubTokensToUsers(db) {
|
|
25
33
|
db.exec(`
|
|
@@ -207,10 +207,10 @@ export function registerCommentRoutes(app, context) {
|
|
|
207
207
|
projectId: id, commentId, authorId: user.id, content, previousContent: comment.content, createdAt: changedAt
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
|
-
if (typeof body.resolved === "boolean") {
|
|
211
|
-
db.prepare("UPDATE comments SET resolved = ?, updated_at = ? WHERE id = ?")
|
|
212
|
-
.run(body.resolved ? 1 : 0, changedAt, commentId);
|
|
213
|
-
if (body.resolved
|
|
210
|
+
if (typeof body.resolved === "boolean" && body.resolved !== Boolean(comment.resolved)) {
|
|
211
|
+
db.prepare("UPDATE comments SET resolved = ?, resolved_by = ?, resolved_at = ?, updated_at = ? WHERE id = ?")
|
|
212
|
+
.run(body.resolved ? 1 : 0, body.resolved ? user.id : null, body.resolved ? changedAt : null, changedAt, commentId);
|
|
213
|
+
if (body.resolved)
|
|
214
214
|
markCommentMentionsResolved(db, commentId, changedAt);
|
|
215
215
|
}
|
|
216
216
|
})();
|
|
@@ -198,8 +198,11 @@ function commentsForScope(db, config, projectId, filePath) {
|
|
|
198
198
|
const commentOrder = hasFileScope
|
|
199
199
|
? "c.created_at"
|
|
200
200
|
: "c.file_path COLLATE NOCASE, c.start_line, c.created_at";
|
|
201
|
-
const rows = db.prepare(`SELECT c.*, u.username AS author_username, u.display_name AS author_display_name
|
|
202
|
-
|
|
201
|
+
const rows = db.prepare(`SELECT c.*, u.username AS author_username, u.display_name AS author_display_name,
|
|
202
|
+
resolver.username AS resolved_by_username, resolver.display_name AS resolved_by_display_name FROM comments c
|
|
203
|
+
LEFT JOIN users u ON u.id = c.author_id
|
|
204
|
+
LEFT JOIN users resolver ON resolver.id = c.resolved_by
|
|
205
|
+
WHERE c.project_id = ?${fileClause} ORDER BY ${commentOrder}`)
|
|
203
206
|
.all(projectId, ...(hasFileScope ? [filePath] : []));
|
|
204
207
|
if (!rows.length)
|
|
205
208
|
return [];
|
|
@@ -239,12 +242,18 @@ function commentsForScope(db, config, projectId, filePath) {
|
|
|
239
242
|
authorUsername: comment.author_username,
|
|
240
243
|
authorDisplayName: comment.author_display_name,
|
|
241
244
|
selectedText: comment.selected_text,
|
|
245
|
+
contextBefore: comment.context_before,
|
|
246
|
+
contextAfter: comment.context_after,
|
|
242
247
|
startOffset: comment.start_offset,
|
|
243
248
|
endOffset: comment.end_offset,
|
|
244
249
|
startLine: offsetToLine(sourceByPath.get(comment.file_path) ?? "", comment.start_offset),
|
|
245
250
|
endLine: offsetToLine(sourceByPath.get(comment.file_path) ?? "", comment.end_offset),
|
|
246
251
|
content: comment.content,
|
|
247
252
|
resolved: Boolean(comment.resolved),
|
|
253
|
+
resolvedById: comment.resolved_by,
|
|
254
|
+
resolvedByUsername: comment.resolved_by_username,
|
|
255
|
+
resolvedByDisplayName: comment.resolved_by_display_name,
|
|
256
|
+
resolvedAt: comment.resolved_at,
|
|
248
257
|
orphaned: Boolean(comment.orphaned),
|
|
249
258
|
createdAt: comment.created_at,
|
|
250
259
|
updatedAt: comment.updated_at,
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
const CONTEXT_SIZE = 48;
|
|
2
|
+
export function anchorSource(source) {
|
|
3
|
+
return { length: source.length, sliceString: (from, to) => source.slice(from, to) };
|
|
4
|
+
}
|
|
5
|
+
export function sourceAnchorAt(source, start, end) {
|
|
6
|
+
const startOffset = clamp(Math.min(start, end), 0, source.length);
|
|
7
|
+
const endOffset = clamp(Math.max(start, end), startOffset, source.length);
|
|
8
|
+
return {
|
|
9
|
+
startOffset, endOffset,
|
|
10
|
+
selectedText: source.sliceString(startOffset, endOffset),
|
|
11
|
+
contextBefore: source.sliceString(Math.max(0, startOffset - CONTEXT_SIZE), startOffset),
|
|
12
|
+
contextAfter: source.sliceString(endOffset, Math.min(source.length, endOffset + CONTEXT_SIZE)),
|
|
13
|
+
orphaned: false
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function mappedOffset(position, changes, side) {
|
|
17
|
+
let delta = 0;
|
|
18
|
+
for (const change of changes) {
|
|
19
|
+
if (position < change.from)
|
|
20
|
+
break;
|
|
21
|
+
if (position > change.to || position === change.to && change.to > change.from) {
|
|
22
|
+
delta += change.insertLength - (change.to - change.from);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return change.from + delta + (side > 0 ? change.insertLength : 0);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return position + delta;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Follow partial edits, but keep the last attached quote and context when the
|
|
32
|
+
* selection is erased or no longer recognizable. They are required for undo
|
|
33
|
+
* recovery; the mapped range alone is just a positional hint while detached.
|
|
34
|
+
* A browser may bound recovery searches near the hint to avoid flattening the
|
|
35
|
+
* entire CodeMirror document on each keystroke. Saves search the whole file.
|
|
36
|
+
*/
|
|
37
|
+
export function mapSourceAnchor(anchor, oldSource, newSource, changes, recoveryWindow, insertedRanges = []) {
|
|
38
|
+
const oldStart = clamp(anchor.startOffset, 0, oldSource.length);
|
|
39
|
+
const oldEnd = clamp(anchor.endOffset, oldStart, oldSource.length);
|
|
40
|
+
const deletions = changes.filter((change) => change.from < oldEnd && change.to > oldStart);
|
|
41
|
+
// Replacements touching the selection's boundaries belong to the range.
|
|
42
|
+
// Pure insertions just outside it do not (typing before/after a quote).
|
|
43
|
+
const startSide = deletions.some((change) => change.from <= oldStart) ? -1 : 1;
|
|
44
|
+
const endSide = deletions.some((change) => change.to >= oldEnd) ? 1 : -1;
|
|
45
|
+
const start = clamp(mappedOffset(oldStart, changes, startSide), 0, newSource.length);
|
|
46
|
+
const end = clamp(mappedOffset(oldEnd, changes, endSide), start, newSource.length);
|
|
47
|
+
const oldMatches = oldSource.sliceString(oldStart, oldEnd) === anchor.selectedText;
|
|
48
|
+
if (!anchor.orphaned && oldMatches) {
|
|
49
|
+
if (!anchor.selectedText && oldStart === oldEnd)
|
|
50
|
+
return sourceAnchorAt(newSource, start, start);
|
|
51
|
+
const deletedLength = deletions.reduce((sum, change) => sum + Math.min(oldEnd, change.to) - Math.max(oldStart, change.from), 0);
|
|
52
|
+
const retainedLength = oldEnd - oldStart - deletedLength;
|
|
53
|
+
// Exact editor operations can retain even one original character.
|
|
54
|
+
// A guessed text diff needs stronger evidence for word replacements.
|
|
55
|
+
const minimumRetained = changes.some((change) => change.inferred) ? Math.min(2, oldEnd - oldStart) : 1;
|
|
56
|
+
if (end > start && retainedLength >= minimumRetained) {
|
|
57
|
+
return sourceAnchorAt(newSource, start, end);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const detached = { ...anchor, startOffset: start, endOffset: end, orphaned: true };
|
|
61
|
+
// Do not silently legitimize a previously attached but stale DB row whose
|
|
62
|
+
// quote didn't match the old document in the first place.
|
|
63
|
+
if (!anchor.orphaned && !oldMatches)
|
|
64
|
+
return detached;
|
|
65
|
+
const restored = contextualMatch(newSource, anchor, start, recoveryWindow, insertedRanges);
|
|
66
|
+
return restored === null ? detached : sourceAnchorAt(newSource, restored, restored + anchor.selectedText.length);
|
|
67
|
+
}
|
|
68
|
+
function contextualMatch(source, anchor, start, window, insertedRanges = []) {
|
|
69
|
+
const selected = anchor.selectedText;
|
|
70
|
+
if (!selected)
|
|
71
|
+
return null;
|
|
72
|
+
const from = window === undefined ? 0 : Math.max(0, start - selected.length - window);
|
|
73
|
+
const to = window === undefined ? source.length : Math.min(source.length, start + selected.length + window);
|
|
74
|
+
// Whole-document undo/paste may restore a quote far from the collapsed
|
|
75
|
+
// hint. Inspect the inserted fragment in that case, not the whole file on
|
|
76
|
+
// each subsequent small edit while the comment remains detached.
|
|
77
|
+
const ranges = window === undefined ? [{ from, to }] : [{ from, to },
|
|
78
|
+
...insertedRanges.filter((range) => range.to - range.from >= selected.length)];
|
|
79
|
+
const seen = new Set();
|
|
80
|
+
const availableContext = anchor.contextBefore.length + anchor.contextAfter.length;
|
|
81
|
+
let best = null;
|
|
82
|
+
let bestRank = Number.NEGATIVE_INFINITY;
|
|
83
|
+
let tied = false;
|
|
84
|
+
for (const range of ranges) {
|
|
85
|
+
const search = source.sliceString(range.from, range.to);
|
|
86
|
+
for (let cursor = 0; cursor <= search.length;) {
|
|
87
|
+
const index = search.indexOf(selected, cursor);
|
|
88
|
+
if (index < 0)
|
|
89
|
+
break;
|
|
90
|
+
const found = range.from + index;
|
|
91
|
+
cursor = index + Math.max(1, selected.length);
|
|
92
|
+
if (seen.has(found))
|
|
93
|
+
continue;
|
|
94
|
+
seen.add(found);
|
|
95
|
+
const before = source.sliceString(Math.max(0, found - anchor.contextBefore.length), found);
|
|
96
|
+
const after = source.sliceString(found + selected.length, Math.min(source.length, found + selected.length + anchor.contextAfter.length));
|
|
97
|
+
const contextScore = commonSuffixLength(before, anchor.contextBefore) + commonPrefixLength(after, anchor.contextAfter);
|
|
98
|
+
// A whole-file selection has no context. Only an exact whole-file undo
|
|
99
|
+
// is safe in that case; proximity or uniqueness alone is insufficient.
|
|
100
|
+
if (availableContext ? contextScore >= Math.min(4, availableContext) : found === 0 && selected.length === source.length) {
|
|
101
|
+
const rank = contextScore * 1000 - Math.abs(found - start);
|
|
102
|
+
if (rank > bestRank) {
|
|
103
|
+
best = found;
|
|
104
|
+
bestRank = rank;
|
|
105
|
+
tied = false;
|
|
106
|
+
}
|
|
107
|
+
else if (rank === bestRank)
|
|
108
|
+
tied = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return tied ? null : best;
|
|
113
|
+
}
|
|
114
|
+
function commonPrefixLength(left, right) {
|
|
115
|
+
let index = 0;
|
|
116
|
+
while (index < Math.min(left.length, right.length) && left[index] === right[index])
|
|
117
|
+
index++;
|
|
118
|
+
return index;
|
|
119
|
+
}
|
|
120
|
+
function commonSuffixLength(left, right) {
|
|
121
|
+
let count = 0;
|
|
122
|
+
while (count < Math.min(left.length, right.length) && left[left.length - count - 1] === right[right.length - count - 1])
|
|
123
|
+
count++;
|
|
124
|
+
return count;
|
|
125
|
+
}
|
|
126
|
+
function clamp(value, min, max) {
|
|
127
|
+
return Math.max(min, Math.min(max, Number.isFinite(value) ? Math.floor(value) : min));
|
|
128
|
+
}
|