From ebf201d6a4b971b621fbb6da8b45ba08e79fe3f3 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 2 Nov 2023 00:06:39 +0300 Subject: [PATCH] now whitespace working correctly... Signed-off-by: Alex A. Naanou --- experiments/outline-editor/editor.js | 19 ++++++++------ experiments/outline-editor/index.html | 36 +++++++++++++-------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/experiments/outline-editor/editor.js b/experiments/outline-editor/editor.js index 7d4df1e..372c3e2 100755 --- a/experiments/outline-editor/editor.js +++ b/experiments/outline-editor/editor.js @@ -767,7 +767,6 @@ var Outline = { tab_size: 4, carot_jump_edge_then_block: false, // XXX not sure what should the default be... - // XXX this should not affect editing... trim_block_text: false, @@ -1081,7 +1080,7 @@ var Outline = { // NOTE: we are ignoring the .collapsed attr here parsed = this.__code2html__(data.text, {...data}) html.innerHTML = - parsed.text.length == 0 ? + parsed.text == '' ? parsed.text // NOTE: adding a space here is done to prevent the browser // from hiding the last newline... @@ -1094,7 +1093,7 @@ var Outline = { delete parsed.style } else { html.innerHTML = - data.text.length == 0 ? + data.text == '' ? data.text // NOTE: adding a space here is done to prevent the browser // from hiding the last newline... @@ -1362,7 +1361,7 @@ var Outline = { // only whitespace -> keep element blank... if(code.trim() == ''){ - elem.text = '' + elem.text = code return elem } // helpers... @@ -1412,8 +1411,11 @@ var Outline = { return code .replace(/(\n\s*)-/g, '$1\\-') }, __text2code__: function(text){ - return text - .replace(/(\n\s*)\\-/g, '$1-') }, + text = text + .replace(/(\n\s*)\\-/g, '$1-') + return this.trim_block_text ? + text.trim() + : text }, // serialization... data: function(elem, deep=true){ @@ -2159,7 +2161,10 @@ var Outline = { if(elem.classList.contains('code')){ var block = that.get(elem) // clean out attrs... - elem.value = that.parseBlockAttrs(elem.value).text + elem.value = + that.trim_block_text ? + that.parseBlockAttrs(elem.value).text.trim() + : that.parseBlockAttrs(elem.value).text that.update(block) // undo... if(elem.value != elem.dataset.original){ diff --git a/experiments/outline-editor/index.html b/experiments/outline-editor/index.html index 633bd28..928747d 100755 --- a/experiments/outline-editor/index.html +++ b/experiments/outline-editor/index.html @@ -48,7 +48,6 @@ var setup = function(){ - - ## Bugs: focused:: true - - BUG: `.trim_block_text` should not affect editing... - BUG: mobile browsers behave quite chaotically ignoring parts of the styling... - FF: - zooming on edited field @@ -57,23 +56,6 @@ var setup = function(){ - side margins are a bit too large (account for toolbat to the right) - - ## ToDo: - - trailing whitespace is ignored in `.view`... (BUG?) - - demos: - - - leading whitespace... - - trailing whitespace... - - - empty block is not correctly shown\: - - - - - - _it seams that HTML ignores the last newline if it is not followed by anything_ - - there are four ways to deal with this:# - - trim whitespace on refocus - - show whitespace in both modes - - REJECT remove trailing whitespace completely on refocus (a-la logseq) - - REJECT keep current behavior - - I do not believe in keeping whitespace in edit and hiding it in view (POLS) - custom element / web component - Q: can we get rid of the editor block??: - CSS breaks if we do... @@ -147,6 +129,24 @@ var setup = function(){ - empty item height is a bit off... - search? - _...not sure if search should be internal or external yet..._ + - DONE trailing whitespace is ignored in `.view`... + collapsed:: true + - demos: + - + leading whitespace... + - trailing whitespace... + + - empty block\: + - + + + - _it seams that HTML ignores the last newline if it is not followed by anything_ + - there are four ways to deal with this:# + - trim whitespace on refocus (option) + - show whitespace in both modes (option) + - REJECT remove trailing whitespace completely on refocus (a-la logseq) + - REJECT keep current behavior + - I do not believe in keeping whitespace in edit and hiding it in view (POLS) - DONE add options to save to `.sessionStorage` / `.localStorage` - DONE might be a good idea to focus the prev (empty) node if pressing `Enter` at 0 position collapsed:: true