From b22c358b8593aa9bd534808b5d5effdcf0fd0869 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Wed, 1 Apr 2020 12:29:07 +0300
Subject: [PATCH] Set activeViewId into context

---
 wax-prosemirror-core/src/WaxView.js                |  7 ++++++-
 wax-prosemirror-core/src/ioc-react.js              | 11 +++++++++--
 wax-prosemirror-services/src/NoteService/Editor.js | 14 +++++++++++---
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js
index 6f53084f5..12bdaccab 100644
--- a/wax-prosemirror-core/src/WaxView.js
+++ b/wax-prosemirror-core/src/WaxView.js
@@ -52,7 +52,12 @@ export default props => {
 
     const state = view.state.apply(tr);
     view.updateState(state);
-    context.updateView({ main: view });
+
+    context.updateView({
+      main: view,
+      activeViewId: context.activeViewId,
+      activeView: view
+    });
 
     props.onChange(state.doc.content);
   };
diff --git a/wax-prosemirror-core/src/ioc-react.js b/wax-prosemirror-core/src/ioc-react.js
index 52c1fcb37..36f768cc2 100644
--- a/wax-prosemirror-core/src/ioc-react.js
+++ b/wax-prosemirror-core/src/ioc-react.js
@@ -3,6 +3,7 @@ import React, { useContext, useState } from "react";
 export const WaxContext = React.createContext({
   view: {},
   activeView: {},
+  activeViewId: null,
   app: null,
   updateView: null,
   updateActiveView: null
@@ -13,15 +14,21 @@ export default props => {
     app: props.app,
     view: props.view || {},
     activeView: props.activeView || {},
+    activeViewId: props.activeViewId || {},
     updateView: view => {
       setContext({
         ...context,
         view: Object.assign(context.view, view),
-        activeView: view.main || view
+        activeView: view.main || view,
+        activeViewId: view.activeViewId
       });
     },
     updateActiveView: view => {
-      setContext({ ...context, activeView: view });
+      setContext({
+        ...context,
+        activeView: view.activeView,
+        activeViewId: view.activeViewId
+      });
     }
   });
 
diff --git a/wax-prosemirror-services/src/NoteService/Editor.js b/wax-prosemirror-services/src/NoteService/Editor.js
index 4c663bbbe..54885fd02 100644
--- a/wax-prosemirror-services/src/NoteService/Editor.js
+++ b/wax-prosemirror-services/src/NoteService/Editor.js
@@ -48,9 +48,13 @@ export default ({ node, view }) => {
                 outerTr.step(steps[j].map(offsetMap));
             }
 
-            //Set everytime the active view into context
-            context.updateActiveView(context.view[noteId]);
             if (outerTr.docChanged) view.dispatch(outerTr);
+
+            //Set everytime the active view into context
+            context.updateActiveView({
+              activeView: context.view[noteId],
+              activeViewId: noteId
+            });
           }
         },
         handleDOMEvents: {
@@ -68,8 +72,12 @@ export default ({ node, view }) => {
     context.updateView({ [noteId]: noteView });
     if (context.view[noteId]) {
       context.view[noteId].focus();
+
       //Set everytime the active view into context
-      context.updateActiveView(context.view[noteId]);
+      context.updateActiveView({
+        activeView: context.view[noteId],
+        activeViewId: noteId
+      });
     }
   }, []);
 
-- 
GitLab