From 7bff70ed5673fb4789c991367cc81b507858c168 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Wed, 14 Oct 2020 21:19:37 +0300
Subject: [PATCH] delete of math nodes

---
 editors/editoria/src/layout/EditoriaLayout.js |  3 ++
 .../comments/CommentBubbleComponent.js        | 22 +++++++++++---
 .../components/notes/NoteEditorContainer.js   |  9 ------
 .../src/ShortCutsService/ShortCuts.js         | 29 +++++++++++++++++--
 4 files changed, 48 insertions(+), 15 deletions(-)

diff --git a/editors/editoria/src/layout/EditoriaLayout.js b/editors/editoria/src/layout/EditoriaLayout.js
index ce371bacb..417566f11 100644
--- a/editors/editoria/src/layout/EditoriaLayout.js
+++ b/editors/editoria/src/layout/EditoriaLayout.js
@@ -119,6 +119,9 @@ const NotesAreaContainer = styled.div`
   position: absolute;
   /* PM styles  for note content*/
   ${EditorElements};
+  .ProseMirror {
+    display: inline;
+  }
 `;
 
 const NotesContainer = styled.div`
diff --git a/wax-prosemirror-components/src/components/comments/CommentBubbleComponent.js b/wax-prosemirror-components/src/components/comments/CommentBubbleComponent.js
index 8443731c4..9e9f9818b 100644
--- a/wax-prosemirror-components/src/components/comments/CommentBubbleComponent.js
+++ b/wax-prosemirror-components/src/components/comments/CommentBubbleComponent.js
@@ -30,17 +30,31 @@ const CommentBubbleComponent = ({
     activeView.focus();
   };
 
-  const isSelectionComment = () => {
+  const isCommentAllowed = () => {
     const commentMark = activeView.state.schema.marks.comment;
     const mark = DocumentHelpers.findMark(state, commentMark, true);
 
+    let allowed = true;
+    state.doc.nodesBetween(
+      state.selection.$from.pos,
+      state.selection.$to.pos,
+      (node, from) => {
+        if (
+          node.type.name === 'math_display' ||
+          node.type.name === 'math_inline'
+        ) {
+          allowed = false;
+        }
+      },
+    );
+
     // TODO Overlapping comments . for now don't allow
-    if (mark.length >= 1) return true;
-    return false;
+    if (mark.length >= 1) allowed = false;
+    return allowed;
   };
 
   return (
-    !isSelectionComment() &&
+    isCommentAllowed() &&
     showComment(activeViewId) && (
       <CommentBubble
         onClick={event => {
diff --git a/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js b/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js
index 81ea93833..8e08ea86c 100644
--- a/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js
+++ b/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js
@@ -25,15 +25,6 @@ const NoteStyled = styled.div`
   height: 100%;
   border-bottom: 1px solid black;
 
-  span.comment {
-    border-bottom: none !important;
-    &: after {
-      content: '';
-      border-bottom: 2px solid gold;
-      display: block;
-    }
-  }
-
   &:focus {
     outline: none;
   }
diff --git a/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js b/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js
index 2370331b4..3d5ceac0c 100644
--- a/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js
+++ b/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js
@@ -1,5 +1,4 @@
 import { injectable } from 'inversify';
-import { minBy, maxBy } from 'lodash';
 import { keymap } from 'prosemirror-keymap';
 import { undo, redo } from 'prosemirror-history';
 
@@ -9,6 +8,7 @@ import {
   liftListItem,
   sinkListItem,
 } from 'prosemirror-schema-list';
+import { NodeSelection, TextSelection } from 'prosemirror-state';
 
 import {
   baseKeymap,
@@ -26,12 +26,37 @@ const backSpace = chainCommands(
   selectNodeBackward,
 );
 
-const backSpaceShortCut = (state, dispatch, view) =>
+const backSpaceShortCut = (state, dispatch, view) => {
+  const { $from, $to } = state.selection;
+  const { nodeBefore } = $from;
+  if (!nodeBefore) {
+    return false;
+  }
+
+  if (nodeBefore.type.name === 'math_inline') {
+    const index = $from.index($from.depth);
+    const $beforePos = state.doc.resolve($from.posAtIndex(index - 1));
+
+    dispatch(state.tr.setSelection(new NodeSelection($beforePos)));
+
+    return true;
+  }
+
+  state.doc.nodesBetween($from.pos, $to.pos, (node, from) => {
+    if (node.type.name === 'math_display') {
+      const $start = state.tr.doc.resolve(state.tr.selection.$anchor.start());
+      const $end = state.tr.doc.resolve(state.tr.selection.$anchor.end());
+
+      dispatch(state.tr.setSelection(new TextSelection($start, $end)));
+    }
+  });
+
   backSpace(
     state,
     tr => dispatch(tr.setMeta('inputType', 'backwardsDelete')),
     view,
   );
+};
 
 const undoShortCut = (state, dispatch, view) =>
   undo(state, tr => dispatch(tr.setMeta('inputType', 'Undo')), view);
-- 
GitLab