From 2ef0403d262ed6d3816c2bd327d87d6c7567c5c7 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Thu, 19 Dec 2019 23:02:57 +0200
Subject: [PATCH] feat: base shortcuts working

---
 .../src/ShortCutsService/ShortCuts.js           | 16 ++++++++++++----
 .../src/ShortCutsService/ShortCutsService.js    | 17 +++++++++++++++--
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/wax-prosemirror-plugins/src/ShortCutsService/ShortCuts.js b/wax-prosemirror-plugins/src/ShortCutsService/ShortCuts.js
index f8a27e947..fd511d861 100644
--- a/wax-prosemirror-plugins/src/ShortCutsService/ShortCuts.js
+++ b/wax-prosemirror-plugins/src/ShortCutsService/ShortCuts.js
@@ -13,13 +13,12 @@ import {
 
 @injectable()
 class ShortCuts {
-  constructor(config) {
-    this.schema = config.schema;
-    this.shortCuts = config.shortCuts;
+  constructor(plugins, schema) {
+    this.PmPlugins = plugins;
+    this.schema = schema;
 
     this.insertBreak = this.insertBreak.bind(this);
     this.insertRule = this.insertRule.bind(this);
-    return keymap(this.createKeyBindings());
   }
 
   insertBreak(state, dispatch) {
@@ -34,6 +33,15 @@ class ShortCuts {
     return true;
   }
 
+  createShortCuts() {
+    const shortCuts = keymap(this.createKeyBindings());
+    this.PmPlugins.add("shortcuts", shortCuts);
+  }
+
+  addShortCut() {
+    /* TODO add shortcut from each package*/
+  }
+
   createKeyBindings() {
     const keys = Object.assign(this.getKeys(), this.shortCuts);
     Object.keys(baseKeymap).forEach(key => {
diff --git a/wax-prosemirror-plugins/src/ShortCutsService/ShortCutsService.js b/wax-prosemirror-plugins/src/ShortCutsService/ShortCutsService.js
index fb4dd8e7f..17a42b805 100644
--- a/wax-prosemirror-plugins/src/ShortCutsService/ShortCutsService.js
+++ b/wax-prosemirror-plugins/src/ShortCutsService/ShortCutsService.js
@@ -4,7 +4,20 @@ import ShortCuts from "./ShortCuts";
 export default class ShortCutsService extends Service {
   name = "ShortCutsService";
 
-  boot() {}
+  boot() {
+    const shortCuts = this.container.get("ShortCuts");
+    shortCuts.createShortCuts();
+  }
 
-  register() {}
+  register() {
+    const PmPlugins = this.app.PmPlugins;
+    this.container
+      .bind("ShortCuts")
+      .toDynamicValue(() => {
+        const { schema: { schema } } = this.app;
+
+        return new ShortCuts(PmPlugins, schema);
+      })
+      .inSingletonScope();
+  }
 }
-- 
GitLab