From b0dc4a39cc63752a0536bd6ba0902385e95b05cd Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 12 Dec 2023 02:23:33 +0300 Subject: [PATCH] bugfix... Signed-off-by: Alex A. Naanou --- experiments/outline-editor/editor.js | 9 ++++++++- experiments/outline-editor/index.html | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/experiments/outline-editor/editor.js b/experiments/outline-editor/editor.js index e5b468b..acadc47 100755 --- a/experiments/outline-editor/editor.js +++ b/experiments/outline-editor/editor.js @@ -44,10 +44,12 @@ var getCharOffset = function(elem, x, y, data){ ?? 0 // text node... if(e instanceof Text){ + /* XXX not needed wit getText(..) // count "virtual" newlines between text and block elements... if(data.prev_elem == 'block'){ data.c += 1 } data.prev_elem = 'text' + //*/ var rect, cursor_line, line_start, offset for(var i=0; i < e.length; i++){ @@ -101,6 +103,7 @@ var getCharOffset = function(elem, x, y, data){ && ' \t\n'.includes(data.last)){ return data.c - 1 } + /* XXX not needed wit getText(..) // count "virtual" newlines between text and block elements... var type = getComputedStyle(e).display var block = [ @@ -119,15 +122,18 @@ var getCharOffset = function(elem, x, y, data){ data.prev_elem = block ? 'block' : 'elem' + //*/ // handle the node... data = getCharOffset(e, x, y, data) + /* XXX not needed wit getText(..) // compensate for table stuff... if(type == 'table-row'){ data.c -= 1 } if(type == 'table-cell'){ data.c += 1 } + //*/ if(typeof(data) != 'object'){ return data } } } @@ -2492,7 +2498,8 @@ var Outline = { var view = that.get(elem).querySelector('.view') var initial = elem.selectionStart var c = getCharOffset(view, evt.clientX, evt.clientY) - var m = getMarkdownOffset(elem.value, view.innerText, c) + //var m = getMarkdownOffset(elem.value, view.innerText, c) + var m = getMarkdownOffset(elem.value, getText(view).join(''), c) // selecting an element with text offset by markup... if(m != 0){ evt.preventDefault() diff --git a/experiments/outline-editor/index.html b/experiments/outline-editor/index.html index c2b7905..798e034 100755 --- a/experiments/outline-editor/index.html +++ b/experiments/outline-editor/index.html @@ -51,6 +51,8 @@ var setup = function(){ - BUG: caret positioning broken - Strategies to test:: - ASAP use `getText(..)` to build the input text instead of `.innerText` + - DONE adds 1 char offset per block element + - this greatly simplifies things... - normalize `.innerText` to remove duplicate `"\n"`'s _(will break placement on empty lines... ???)_ - try and build offset maps on parse