From bdc91318446300c461f88cf146b09a4a8d73750b Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 11 Oct 2023 07:31:06 +0300 Subject: [PATCH] minor refactoring... Signed-off-by: Alex A. Naanou --- experiments/outline-editor/editor.js | 41 ++++++++++++++++----------- experiments/outline-editor/index.html | 4 +-- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/experiments/outline-editor/editor.js b/experiments/outline-editor/editor.js index 3a63ce0..b841a30 100755 --- a/experiments/outline-editor/editor.js +++ b/experiments/outline-editor/editor.js @@ -175,9 +175,16 @@ var Outline = { || node }, at: function(index, nodes='visible'){ return this.get(nodes).at(index) }, - - focus: function(node='focused', offset){}, - edit: function(node='focused', offset){}, + focus: function(node='focused', offset){ + var elem = this.get(...arguments) + elem?.focus() + return elem }, + edit: function(node='focused', offset){ + var elem = this.get(...arguments) + if(elem.nodeName != 'TEXTAREA'){ + elem = elem.querySelector('textarea') } + elem?.focus() + return elem }, update: function(node='focused', data){ var node = this.get(node) @@ -349,7 +356,12 @@ var Outline = { .replace(/(?$1') .replace(/(?$1') .replace(/(?$1') + // characters... + // XXX use ligatures for these??? + .replace(/(? 0) ? this.toggleCollapse(true) - : this.get('parent')?.focus() }, + : this.focus('parent') }, ArrowRight: function(evt){ var edited = this.get('edited') if(edited){ @@ -574,17 +585,15 @@ var Outline = { if(edited.selectionStart == edited.selectionEnd && edited.selectionStart == edited.value.length){ evt.preventDefault() - edited = this.get('edited', 'next') - edited.focus() + edited = this.focus('edited', 'next') edited.selectionStart = edited.selectionEnd = 0 } return } if(this.right_key_expands){ this.toggleCollapse(false) - var child = this.get('children')[0] - child?.focus() + var child = this.focus('children')[0] if(!child){ - this.get('next')?.focus() } + this.focus('next') } } else { evt.shiftKey ? this.toggleCollapse(false) @@ -765,7 +774,7 @@ var Outline = { var refocusNode = function(){ focus_textarea ? editor.get().querySelector('textarea').focus() - : editor.get().focus() + : editor.focus() focus_textarea = undefined } // cache the focused node type before focus changes... toolbar.addEventListener('mousedown', cahceNodeType) diff --git a/experiments/outline-editor/index.html b/experiments/outline-editor/index.html index d4bb55e..b143127 100755 --- a/experiments/outline-editor/index.html +++ b/experiments/outline-editor/index.html @@ -48,8 +48,8 @@ var setup = function(){ - ~editor: semi-live update styles~ - need to reach checkboxes via keyboard - persistent empty first/last node (a button to create a new node) - - add completion percentage to blocks with todo's nested: - - `[%]`, `%%`, or something similar... + - add completion percentage to blocks with todo's nested + - _...use `[%]`, `%%`, or something similar..._ - read-only mode - should bulets be on the same level as nodes or offset?? - A) justified to bulet: