diff --git a/packages/cwrc-leafwriter/src/css/build/editor.css b/packages/cwrc-leafwriter/src/css/build/editor.css index fb614f04aa58a7f63c99d7656154b0427b9d6a97..97d28381f156e36da6e8fa4d6537daae331f2e55 100644 --- a/packages/cwrc-leafwriter/src/css/build/editor.css +++ b/packages/cwrc-leafwriter/src/css/build/editor.css @@ -373,6 +373,21 @@ span[data-mce-bogus] { text-indent: unset !important; } +*[_tag='lb'] { + display : inline !important; +} + +*[_tag='lb']:not(.showTags):before { + content: "\A" !important; + white-space: pre !important; +} + +.showTags [_tag='lb']:before { + content: "\A <lb />" !important; + box-shadow: none !important; + padding-left: 0 !important; +} + @media (prefers-color-scheme: dark) { *[_tag='pb'] { color: black !important; diff --git a/packages/cwrc-leafwriter/src/css/editor.less b/packages/cwrc-leafwriter/src/css/editor.less index 4057346ec615a9d1e2b939503c5f6f8ce618609e..79b1b41014b7a51a4e432a6724265afe457b06aa 100644 --- a/packages/cwrc-leafwriter/src/css/editor.less +++ b/packages/cwrc-leafwriter/src/css/editor.less @@ -281,6 +281,21 @@ span[data-mce-bogus] { text-indent: unset !important; } +*[_tag='lb'] { + display : inline !important; +} + +*[_tag='lb']:not(.showTags):before { + content: "\A" !important; + white-space: pre !important; +} + +.showTags [_tag='lb']:before { + content: "\A <lb />" !important; + box-shadow: none !important; + padding-left: 0 !important; +} + @media (prefers-color-scheme: dark) { *[_tag='pb'] { color: black !important; diff --git a/packages/cwrc-leafwriter/src/js/tinymce/tinymceWrapper.ts b/packages/cwrc-leafwriter/src/js/tinymce/tinymceWrapper.ts index 19ee8ae9f95c7f56c87cc7ff4e2f23d976a808b3..ea4aa8734620e0351bf9eb7cdaf7b5a8ac8d9df2 100644 --- a/packages/cwrc-leafwriter/src/js/tinymce/tinymceWrapper.ts +++ b/packages/cwrc-leafwriter/src/js/tinymce/tinymceWrapper.ts @@ -377,24 +377,51 @@ export const tinymceWrapperInit = function ({ rng.collapse(true); writer.editor?.selection.setRng(rng); } else { - if (currentNode.getAttribute('_entity') !== 'true') { - // exception for entities since the entity parent tag can actually encapsulate several tags - const currentTag = currentNode.getAttribute('_tag'); - /* writer.dialogManager.show('message', { - title: 'No Text Allowed', - msg: `Text is not allowed in the current tag: ${currentTag}.`, - type: 'error', - });*/ - writer.overmindActions.ui.notifyViaSnackbar({ - message: `Text is not allowed in the current tag: ${currentTag}.`, - options: { variant: 'error', key: currentTag }, - }); - } - - // remove text that is not allowed - $(writer.editor?.currentNode).contents().filter(function() { + const curTag = currentNode.getAttribute('_tag') + if (curTag == "lb") + { + // console.log("We ended in lb!") + // get text, that has already been entered + let entered_Text = $(writer.editor?.currentNode).contents().filter(function() { return this.nodeType === 3; - }).remove(); + }) + // console.log(entered_Text.text()) + // Copy to position after lb-element + $(writer.editor?.currentNode).after(entered_Text.text()) + // get element where to position cursor next + var newCurosorElement; + $(writer.editor?.currentNode).after(function() { + newCurosorElement = this.nextSibling // This is the next (text) sibling of lb + return false + }) + // console.log(newCurosorElement) + + // remove text on old position + $(writer.editor?.currentNode).contents().filter(function() { + return this.nodeType === 3; + }).remove(); + // Move cursor to new position + writer.editor.selection.setCursorLocation(newCurosorElement,entered_Text.text().length) // Position cursor in text sibling of lb at end of inserted text + } else { + if (currentNode.getAttribute('_entity') !== 'true') { + // exception for entities since the entity parent tag can actually encapsulate several tags + const currentTag = currentNode.getAttribute('_tag'); + /* writer.dialogManager.show('message', { + title: 'No Text Allowed', + msg: `Text is not allowed in the current tag: ${currentTag}.`, + type: 'error', + });*/ + writer.overmindActions.ui.notifyViaSnackbar({ + message: `Text is not allowed in the current tag: ${currentTag}.`, + options: { variant: 'error', key: currentTag }, + }); + } + + // remove text that is not allowed + $(writer.editor?.currentNode).contents().filter(function() { + return this.nodeType === 3; + }).remove(); + } } } }