Fixing editing

This commit is contained in:
Luis Fernando Molina committed 2020-12-31 15:06:52 +01:00
1 parent 108eb7894f
commit 4e9b1eb700
3 files changed
+97 -92

No files matched your search

@@ -1,7 +1,7 @@
{
"type": "Vaina",
"definition": {
"text": "Write here the definition of this Concept. Updated. Again.",
"text": "Write here the definition of this Concept. Updated. Again. Modified.",
"translations": [
{
"language": "ES",
@@ -15,12 +15,12 @@
"style": "Definition"
}
],
"updated": 1609084340848
"updated": 1609423527735
},
"paragraphs": [
{
"style": "Important",
"text": "Left click and Edit to enter edit mode and change this text. ENTER to write new paragraphs. ESC to exit edit mode. Task",
"text": "Left click and Edit to enter edit mode and change this text. ENTER to write new paragraphs. ESC to exit edit mode. Task Modified.",
"translations": [
{
"language": "RU",
@@ -33,7 +33,7 @@
"style": "Important"
}
],
"updated": 1609142715653
"updated": 1609423537716
},
{
"style": "List",
@@ -179,93 +179,7 @@ function newSuperalgosDocSpace() {
function exitEditMode() {
if (EDITOR_ON_FOCUS === true) {
let editing
if (UI.projects.superalgos.spaces.docsSpace.contextMenu.selectedParagraph.id.indexOf('definition') >= 0) {
editing = "Definition"
} else {
editing = "Paragraph"
}
switch (editing) {
case "Paragraph": {
/*
In this case we are at a regular paragraph.
*/
let docSchemaParagraph = UI.projects.superalgos.spaces.docsSpace.paragraphMap.get(UI.projects.superalgos.spaces.docsSpace.contextMenu.selectedParagraph.id)
/*
We will detect if the user has created new paragraphs while editing.
For that we will inspect the value of the text area looking for a char
code representing carriedge return.
*/
let paragraphs = []
let paragraph = ''
let splittedSelectedParagraph = UI.projects.superalgos.spaces.docsSpace.contextMenu.selectedParagraph.id.split('-')
let selectededitableParagraphIndex = Number(splittedSelectedParagraph[2])
let selectedParagraphStyle = splittedSelectedParagraph[3]
let style = selectedParagraphStyle.charAt(0).toUpperCase() + selectedParagraphStyle.slice(1);
for (let i = 0; i < UI.projects.superalgos.spaces.docsSpace.textArea.value.length; i++) {
if (UI.projects.superalgos.spaces.docsSpace.textArea.value.charCodeAt(i) === 10 && style !== 'Javascript' && style !== 'Json' && style !== 'Table') {
if (paragraph !== '') {
paragraphs.push(paragraph)
}
paragraph = ''
} else {
paragraph = paragraph + UI.projects.superalgos.spaces.docsSpace.textArea.value[i]
}
}
paragraphs.push(paragraph)
if (paragraphs.length === 1) {
/* There is no need to add new paragraphs, we just update the one we have. */
if (paragraphs[0] !== '') {
UI.projects.superalgos.utilities.docs.setTextBasedOnLanguage(docSchemaParagraph, paragraphs[0])
} else {
/*
Deleting paragarphs is only possible in the default language.
*/
if (UI.projects.superalgos.spaces.docsSpace.language === UI.projects.superalgos.globals.docs.DEFAULT_LANGUAGE) {
docsSchemaDocument.paragraphs.splice(selectededitableParagraphIndex, 1)
if (docsSchemaDocument.paragraphs.length === 0) {
let newParagraph = {
style: 'Text',
text: 'Please contribute to the docs by editing this content.'
}
docsSchemaDocument.paragraphs.push(newParagraph)
}
}
}
} else {
/*
Adding paragarphs is only possible in the default language.
*/
if (UI.projects.superalgos.spaces.docsSpace.language === UI.projects.superalgos.globals.docs.DEFAULT_LANGUAGE) {
/*
We will update the one paragraph we have and we will add the rest.
*/
UI.projects.superalgos.utilities.docs.setTextBasedOnLanguage(docSchemaParagraph, paragraphs[0])
for (let i = 1; i < paragraphs.length; i++) {
let newParagraph = {
style: style,
text: paragraphs[i]
}
docsSchemaDocument.paragraphs.splice(selectededitableParagraphIndex + i, 0, newParagraph)
}
}
}
break
}
case "Definition": {
/*
This means that the definition was being edited.
*/
if (UI.projects.superalgos.spaces.docsSpace.textArea.value !== '') {
UI.projects.superalgos.utilities.docs.setTextBasedOnLanguage(docsSchemaDocument.definition, UI.projects.superalgos.spaces.docsSpace.textArea.value)
}
break
}
}
thisObject.documentPage.exitEditMode()
EDITOR_ON_FOCUS = false
UI.projects.superalgos.spaces.docsSpace.documentPage.render()
}
@@ -1,6 +1,7 @@
function newSuperalgosDocsDocumentPage() {
let thisObject = {
render: render,
exitEditMode: exitEditMode,
render: render,
initialize: initialize,
finalize: finalize
}
@@ -1575,4 +1576,94 @@ function newSuperalgosDocsDocumentPage() {
collapsibleElementsArray[i].removeEventListener("click", function () { })
}
}
function exitEditMode() {
let editing
if (UI.projects.superalgos.spaces.docsSpace.contextMenu.selectedParagraph.id.indexOf('definition') >= 0) {
editing = "Definition"
} else {
editing = "Paragraph"
}
switch (editing) {
case "Paragraph": {
/*
In this case we are at a regular paragraph.
*/
let docSchemaParagraph = UI.projects.superalgos.spaces.docsSpace.paragraphMap.get(UI.projects.superalgos.spaces.docsSpace.contextMenu.selectedParagraph.id)
/*
We will detect if the user has created new paragraphs while editing.
For that we will inspect the value of the text area looking for a char
code representing carriedge return.
*/
let paragraphs = []
let paragraph = ''
let splittedSelectedParagraph = UI.projects.superalgos.spaces.docsSpace.contextMenu.selectedParagraph.id.split('-')
let selectededitableParagraphIndex = Number(splittedSelectedParagraph[2])
let selectedParagraphStyle = splittedSelectedParagraph[3]
let style = selectedParagraphStyle.charAt(0).toUpperCase() + selectedParagraphStyle.slice(1);
for (let i = 0; i < UI.projects.superalgos.spaces.docsSpace.textArea.value.length; i++) {
if (UI.projects.superalgos.spaces.docsSpace.textArea.value.charCodeAt(i) === 10 && style !== 'Javascript' && style !== 'Json' && style !== 'Table') {
if (paragraph !== '') {
paragraphs.push(paragraph)
}
paragraph = ''
} else {
paragraph = paragraph + UI.projects.superalgos.spaces.docsSpace.textArea.value[i]
}
}
paragraphs.push(paragraph)
if (paragraphs.length === 1) {
/* There is no need to add new paragraphs, we just update the one we have. */
if (paragraphs[0] !== '') {
UI.projects.superalgos.utilities.docs.setTextBasedOnLanguage(docSchemaParagraph, paragraphs[0])
} else {
/*
Deleting paragarphs is only possible in the default language.
*/
if (UI.projects.superalgos.spaces.docsSpace.language === UI.projects.superalgos.globals.docs.DEFAULT_LANGUAGE) {
docsSchemaDocument.paragraphs.splice(selectededitableParagraphIndex, 1)
if (docsSchemaDocument.paragraphs.length === 0) {
let newParagraph = {
style: 'Text',
text: 'Please contribute to the docs by editing this content.'
}
docsSchemaDocument.paragraphs.push(newParagraph)
}
}
}
} else {
/*
Adding paragarphs is only possible in the default language.
*/
if (UI.projects.superalgos.spaces.docsSpace.language === UI.projects.superalgos.globals.docs.DEFAULT_LANGUAGE) {
/*
We will update the one paragraph we have and we will add the rest.
*/
UI.projects.superalgos.utilities.docs.setTextBasedOnLanguage(docSchemaParagraph, paragraphs[0])
for (let i = 1; i < paragraphs.length; i++) {
let newParagraph = {
style: style,
text: paragraphs[i]
}
docsSchemaDocument.paragraphs.splice(selectededitableParagraphIndex + i, 0, newParagraph)
}
}
}
break
}
case "Definition": {
/*
This means that the definition was being edited.
*/
if (UI.projects.superalgos.spaces.docsSpace.textArea.value !== '') {
UI.projects.superalgos.utilities.docs.setTextBasedOnLanguage(docsSchemaDocument.definition, UI.projects.superalgos.spaces.docsSpace.textArea.value)
}
break
}
}
}
}