From 363be1f238b92f597d03d5c6ff74802c54c84ff5 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 21 Oct 2023 15:53:09 +0300 Subject: [PATCH] refactoring... Signed-off-by: Alex A. Naanou --- experiments/outline-editor/editor.js | 86 +++++++++++++++++----------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/experiments/outline-editor/editor.js b/experiments/outline-editor/editor.js index b8a2495..0bae508 100755 --- a/experiments/outline-editor/editor.js +++ b/experiments/outline-editor/editor.js @@ -538,22 +538,22 @@ var styling = { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// // XXX use ligatures for these??? var symbols = { __proto__: plugin, // XXX use a single regex with handler func to do these... symbols: { - '>>': '»', - '<<': '«', - '->': '→', - '<-': '←', - '=>': '⇒', - '<=': '⇐', - '(i)': '🛈', - '(c)': '©', - '/!\\': '⚠', + // XXX think these are better handled by ligatures... + //'>>': '»', + //'<<': '«', + //'->': '→', + //'<-': '←', + //'=>': '⇒', + //'<=': '⇐', + '(i)': '🛈', + '(c)': '©', + '/!\\': '⚠', }, get symbols_pattern(){ return (this.symbols != null @@ -573,17 +573,6 @@ var symbols = { return that.symbols[m] }) : text return text - /* XXX - .replace(/(?>/gm, '»') - .replace(/(?/gm, '→') - .replace(/(?/gm, '⇒') - .replace(/(?)/gm, '←') - .replace(/(?)/gm, '⇐') - .replace(/(?) if(node === true || node === false){ @@ -857,12 +873,14 @@ var Outline = { .slice(siblings.indexOf(cur)+1) parent.after(cur) children.length > 0 - && cur.lastChild.append(...children) } + && cur.lastChild.append(...children) + this.__change__() } // indent... } else { var parent = siblings[siblings.indexOf(cur) - 1] if(parent){ - parent.lastChild.append(cur) } } + parent.lastChild.append(cur) + this.__change__()} } return cur }, deindent: function(node='focused', indent=false){ return this.indent(node, indent) }, @@ -886,15 +904,21 @@ var Outline = { siblings[i+1].after(node) focused && this.focus() } + this.__change__() return this }, show: function(node='focused', offset){ var node = this.get(...arguments) var outline = this.outline var parent = node + var changes = false do{ parent = parent.parentElement + changes = changes + || parent.getAttribute('collapsed') == '' parent.removeAttribute('collapsed') } while(parent !== outline) + changes + && this.__change__() return node }, toggleCollapse: function(node='focused', state='next'){ var that = this @@ -920,6 +944,7 @@ var Outline = { node.removeAttribute('collapsed') for(var elem of [...node.querySelectorAll('textarea')]){ elem.updateSize() } } + this.__change__() return node }, remove: function(node='focused', offset){ var elem = this.get(...arguments) @@ -932,10 +957,11 @@ var Outline = { : this.get(elem, 'next') } elem?.remove() next?.focus() + this.__change__() return this }, - clear: function(){ this.outline.innerText = '' + this.__change__() return this }, // block serialization... @@ -1486,17 +1512,9 @@ var Outline = { that.runPlugins('__focusout__', evt, that, elem) }) // update .code... - var update_code_timeout outline.addEventListener('change', function(evt){ - if(update_code_timeout){ - return } - update_code_timeout = setTimeout( - function(){ - update_code_timeout = undefined - that.sync() - that.runPlugins('__change__', evt, that) }, - that.code_update_interval || 5000) }) + this.__change__() }) // toolbar... var toolbar = this.toolbar