diff --git a/experiments/outline-editor/editor.js b/experiments/outline-editor/editor.js index 20a31fe..c2de6ad 100755 --- a/experiments/outline-editor/editor.js +++ b/experiments/outline-editor/editor.js @@ -191,14 +191,59 @@ var getMarkdownOffset = function(markdown, text, i){ return map[i] } //*/ -getText = function(elem, res=[]){ +/* XXX this is not needed... +var getText = function(elem, res=[]){ for(var n of elem.childNodes){ - if(n.nodeType == n.TEXT_NODE){ + n.nodeType == n.TEXT_NODE ? res.push(n.textContent) - } else { - getText(n, res) } } + : getText(n, res) } return res } +//*/ +var offsetAt = function(A, B, i){ + i ??= A.length-1 + var o = 0 + var p = 0 + for(var n=0; n <= i; n++){ + while(A[n] != B[n+o]){ + if(n+o >= B.length){ + o = p + break } + o++ } + p = o } + return o } + +// +// offsetMap( +// 'abMcdefg', +// 'abcdeXfg') +// -> [0, 0, , -1, -1, -1, 0, 0] +// +// XXX this is still wrong -- the problem is that in more complex cases +// this finds a non-optimal solution... +// m = `text text text +//