From 491a053c2e5ec8da619187e7e5618197dce2224b Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Fri, 20 Dec 2019 15:28:03 +0200
Subject: [PATCH] feat(shortcuts): add certain shortcuts

---
 .../src/InlineAnnotations/CodeService/CodeService.js   |  6 +++++-
 .../EmphasisService/EmphasisService.js                 |  6 ++++++
 .../InlineAnnotations/StrongService/StrongService.js   |  6 ++++++
 .../UnderlineService/UnderlineService.js               |  6 ++++++
 wax-prosemirror-services/src/SchemaService/Schema.js   |  1 -
 .../src/ShortCutsService/ShortCuts.js                  | 10 ++++++----
 6 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/wax-prosemirror-services/src/InlineAnnotations/CodeService/CodeService.js b/wax-prosemirror-services/src/InlineAnnotations/CodeService/CodeService.js
index 543d5f6a4..aa9e80f1e 100644
--- a/wax-prosemirror-services/src/InlineAnnotations/CodeService/CodeService.js
+++ b/wax-prosemirror-services/src/InlineAnnotations/CodeService/CodeService.js
@@ -1,9 +1,13 @@
+import { toggleMark } from "prosemirror-commands";
 import Service from "wax-prosemirror-core/src/services/Service";
 import { codeMark } from "wax-prosemirror-schema";
 import Code from "./Code";
 
 class CodeService extends Service {
-  boot() {}
+  boot() {
+    const shortCuts = this.container.get("ShortCuts");
+    shortCuts.addShortCut({ "Mod-`": toggleMark(this.schema.marks.code) });
+  }
 
   register() {
     this.container
diff --git a/wax-prosemirror-services/src/InlineAnnotations/EmphasisService/EmphasisService.js b/wax-prosemirror-services/src/InlineAnnotations/EmphasisService/EmphasisService.js
index 190a397ab..7114a88a1 100644
--- a/wax-prosemirror-services/src/InlineAnnotations/EmphasisService/EmphasisService.js
+++ b/wax-prosemirror-services/src/InlineAnnotations/EmphasisService/EmphasisService.js
@@ -1,8 +1,14 @@
+import { toggleMark } from "prosemirror-commands";
 import Service from "wax-prosemirror-core/src/services/Service";
 import { emphasisMark } from "wax-prosemirror-schema";
 import Emphasis from "./Emphasis";
 
 class EmphasisService extends Service {
+  boot() {
+    const shortCuts = this.container.get("ShortCuts");
+    shortCuts.addShortCut({ "Mod-i": toggleMark(this.schema.marks.em) });
+  }
+
   register() {
     this.container.bind("Emphasis").to(Emphasis);
 
diff --git a/wax-prosemirror-services/src/InlineAnnotations/StrongService/StrongService.js b/wax-prosemirror-services/src/InlineAnnotations/StrongService/StrongService.js
index cd954b8fb..79832f9fc 100644
--- a/wax-prosemirror-services/src/InlineAnnotations/StrongService/StrongService.js
+++ b/wax-prosemirror-services/src/InlineAnnotations/StrongService/StrongService.js
@@ -1,8 +1,14 @@
+import { toggleMark } from "prosemirror-commands";
 import Service from "wax-prosemirror-core/src/services/Service";
 import { strongMark } from "wax-prosemirror-schema";
 import Strong from "./Strong";
 
 class StrongService extends Service {
+  boot() {
+    const shortCuts = this.container.get("ShortCuts");
+    shortCuts.addShortCut({ "Mod-b": toggleMark(this.schema.marks.strong) });
+  }
+
   register() {
     this.container.bind("Strong").to(Strong);
 
diff --git a/wax-prosemirror-services/src/InlineAnnotations/UnderlineService/UnderlineService.js b/wax-prosemirror-services/src/InlineAnnotations/UnderlineService/UnderlineService.js
index 5e9fd797f..c72013b98 100644
--- a/wax-prosemirror-services/src/InlineAnnotations/UnderlineService/UnderlineService.js
+++ b/wax-prosemirror-services/src/InlineAnnotations/UnderlineService/UnderlineService.js
@@ -1,8 +1,14 @@
+import { toggleMark } from "prosemirror-commands";
 import Service from "wax-prosemirror-core/src/services/Service";
 import { underlineMark } from "wax-prosemirror-schema";
 import Underline from "./Underline";
 
 class UnderlineService extends Service {
+  boot() {
+    const shortCuts = this.container.get("ShortCuts");
+    shortCuts.addShortCut({ "Mod-u": toggleMark(this.schema.marks.underline) });
+  }
+
   register() {
     this.container.bind("Underline").to(Underline);
 
diff --git a/wax-prosemirror-services/src/SchemaService/Schema.js b/wax-prosemirror-services/src/SchemaService/Schema.js
index 8360e36e6..0cb402b48 100644
--- a/wax-prosemirror-services/src/SchemaService/Schema.js
+++ b/wax-prosemirror-services/src/SchemaService/Schema.js
@@ -98,7 +98,6 @@ export default class Schema {
       nodes[index] = this._nodes[index].toJSON();
     }
 
-    console.log(this._marks);
     for (let index in this._marks) {
       marks[index] = this._marks[index].toJSON();
     }
diff --git a/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js b/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js
index fd511d861..0e4628ac0 100644
--- a/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js
+++ b/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js
@@ -13,10 +13,11 @@ import {
 
 @injectable()
 class ShortCuts {
+  keys = {};
   constructor(plugins, schema) {
     this.PmPlugins = plugins;
     this.schema = schema;
-
+    this.keys = this.getKeys();
     this.insertBreak = this.insertBreak.bind(this);
     this.insertRule = this.insertRule.bind(this);
   }
@@ -38,12 +39,13 @@ class ShortCuts {
     this.PmPlugins.add("shortcuts", shortCuts);
   }
 
-  addShortCut() {
-    /* TODO add shortcut from each package*/
+  addShortCut(shortcut) {
+    this.keys = Object.assign(this.keys, shortcut);
+    this.createShortCuts();
   }
 
   createKeyBindings() {
-    const keys = Object.assign(this.getKeys(), this.shortCuts);
+    const keys = this.keys;
     Object.keys(baseKeymap).forEach(key => {
       if (keys[key]) {
         keys[key] = chainCommands(keys[key], baseKeymap[key]);
-- 
GitLab