diff --git a/experiments/outline-editor/editor.js b/experiments/outline-editor/editor.js index 1b92989..2d63c68 100755 --- a/experiments/outline-editor/editor.js +++ b/experiments/outline-editor/editor.js @@ -133,17 +133,6 @@ var getMarkdownOffset = function(markdown, text, i){ m = p } } return m - t } -// NOTE: this is the same as .innerText but will not add extra "\n" after -// each block element... -var getTexts = function(elem, res=[]){ - for(var n of elem.childNodes){ - n.nodeType == n.TEXT_NODE ? - res.push(n.textContent) - : getTexts(n, res) } - return res } -var getText = function(elem){ - return getTexts(elem).join('') } - var offsetAt = function(A, B, i){ i ??= A.length-1 var o = 0 @@ -157,39 +146,17 @@ var offsetAt = function(A, B, i){ 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 -//
-// block element -//
-// this line, and above placement of completely broken` -// t = 'text text text\n\n\nblock element\n\n\nthis line, and above placement of completely broken ' -// o = offsetMap(m, t) -// // this should reproduce common sections... -// console.log('---', o.map(function(e, i){ return m[i+e] }).join('')) -// XXX can we cheat here??? -// XXX do we need this??? -var offsetMap = function(A, B, m=[]){ - var o = 0 - var p = 0 - for(var n=0; n < A.length; n++){ - while(A[n] != B[n+o]){ - if(n+o >= B.length){ - m.length += 1 - o = p-1 - break } - o++ } - A[n] == B[n+o] - && m.push(o) - p = o } - return m } +// NOTE: this is the same as .innerText but will not add extra "\n" after +// each block element... +var getTexts = function(elem, res=[]){ + for(var n of elem.childNodes){ + n.nodeType == n.TEXT_NODE ? + res.push(n.textContent) + : getTexts(n, res) } + return res } +var getText = function(elem){ + return getTexts(elem).join('') } +