From 0d55624f0593883853f285d0644d3c28ade1ba91 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Fri, 12 Mar 2021 13:40:00 +0200
Subject: [PATCH] remove selection if focus is lost from note

---
 .../src/components/comments/ConnectedComment.js        |  3 ++-
 wax-prosemirror-services/src/NoteService/Editor.js     | 10 +++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/wax-prosemirror-components/src/components/comments/ConnectedComment.js b/wax-prosemirror-components/src/components/comments/ConnectedComment.js
index d7d2413ad..6e12ec1cb 100644
--- a/wax-prosemirror-components/src/components/comments/ConnectedComment.js
+++ b/wax-prosemirror-components/src/components/comments/ConnectedComment.js
@@ -50,7 +50,7 @@ export default ({ comment, top, commentId, recalculateTops }) => {
 
   const commentPlugin = app.PmPlugins.get('commentPlugin');
   const activeComment = commentPlugin.getState(activeView.state).comment;
-  console.log(activeComment);
+
   useEffect(() => {
     setIsActive(false);
     recalculateTops();
@@ -121,6 +121,7 @@ export default ({ comment, top, commentId, recalculateTops }) => {
     });
     // if (allCommentsWithSameId.length > 1);
     // maxPos += last(allCommentsWithSameId).node.nodeSize;
+    recalculateTops();
     dispatch(state.tr.removeMark(minPos, maxPos, commentMark));
     activeView.focus();
   };
diff --git a/wax-prosemirror-services/src/NoteService/Editor.js b/wax-prosemirror-services/src/NoteService/Editor.js
index d8b7871bd..a77c8da0c 100644
--- a/wax-prosemirror-services/src/NoteService/Editor.js
+++ b/wax-prosemirror-services/src/NoteService/Editor.js
@@ -2,7 +2,7 @@
 import React, { useEffect, useRef, useContext, useMemo } from 'react';
 import { filter } from 'lodash';
 import { EditorView } from 'prosemirror-view';
-import { EditorState } from 'prosemirror-state';
+import { EditorState, TextSelection } from 'prosemirror-state';
 import { StepMap } from 'prosemirror-transform';
 import { baseKeymap } from 'prosemirror-commands';
 import { keymap } from 'prosemirror-keymap';
@@ -37,6 +37,14 @@ export default ({ node, view }) => {
         // This is the magic part
         dispatchTransaction,
         handleDOMEvents: {
+          blur: () => {
+            context.view[noteId].dispatch(
+              context.view[noteId].state.tr.setSelection(
+                new TextSelection(context.view[noteId].state.tr.doc.resolve(0)),
+              ),
+            );
+          },
+
           mousedown: () => {
             context.updateView({}, noteId);
             clickInNote = true;
-- 
GitLab