Skip to content
Snippets Groups Projects
Commit c71d4fee authored by chris's avatar chris
Browse files

shoetcuts in progress

parent 9e5babe5
No related branches found
No related tags found
1 merge request!387Short cuts
...@@ -61,11 +61,18 @@ export default class Application { ...@@ -61,11 +61,18 @@ export default class Application {
return this.schema.getSchema(); return this.schema.getSchema();
} }
getShortCuts() {
this.shortCuts = this.container.get('ShortCuts');
console.log(this.shortCuts);
this.PmPlugins.add('shortcuts', this.shortCuts.createShortCuts());
}
resetApp() { resetApp() {
this.container = {}; this.container = {};
this.config = {}; this.config = {};
this.PmPlugins = {}; this.PmPlugins = {};
this.schema = {}; this.schema = {};
this.shortCuts = {};
} }
static create(config) { static create(config) {
......
...@@ -56,6 +56,7 @@ const WaxView = forwardRef((props, ref) => { ...@@ -56,6 +56,7 @@ const WaxView = forwardRef((props, ref) => {
if (!mounted) { if (!mounted) {
context.app.bootServices(); context.app.bootServices();
context.app.getShortCuts();
} }
const setEditorRef = useCallback( const setEditorRef = useCallback(
......
// import { wrapInList } from 'prosemirror-schema-list'; import { wrapInList } from 'prosemirror-schema-list';
import { bulletListNode } from 'wax-prosemirror-schema'; import { bulletListNode } from 'wax-prosemirror-schema';
import Service from '../../Service'; import Service from '../../Service';
import BulletList from './BulletList'; import BulletList from './BulletList';
...@@ -7,9 +7,9 @@ class BulletListService extends Service { ...@@ -7,9 +7,9 @@ class BulletListService extends Service {
name = 'BulletListService'; name = 'BulletListService';
boot() { boot() {
const shortCuts = this.container.get('ShortCuts'); const shortCuts = this.container.get('ShortCuts');
// shortCuts.addShortCut({ shortCuts.addShortCut({
// "Shift-Ctrl-8": wrapInList(this.schema.nodes.bulletlist) 'Shift-Ctrl-8': wrapInList(this.schema.nodes.bulletlist),
// }); });
} }
register() { register() {
......
import Service from "../../Service"; import { liftListItem, sinkListItem } from 'prosemirror-schema-list';
import { liftListItem, sinkListItem } from "prosemirror-schema-list"; import Service from '../../Service';
import Lift from "./Lift"; import Lift from './Lift';
class LiftService extends Service { class LiftService extends Service {
boot() { boot() {
const shortCuts = this.container.get("ShortCuts"); const shortCuts = this.container.get('ShortCuts');
// shortCuts.addShortCut({ shortCuts.addShortCut({
// "Mod-[": liftListItem(this.schema.nodes.list_item), 'Mod-[': liftListItem(this.schema.nodes.list_item),
// "Mod-]": sinkListItem(this.schema.nodes.list_item) 'Mod-]': sinkListItem(this.schema.nodes.list_item),
// }); });
} }
register() { register() {
this.container.bind("Lift").to(Lift); this.container.bind('Lift').to(Lift);
} }
} }
......
import Service from '../../Service';
import { wrapInList } from 'prosemirror-schema-list'; import { wrapInList } from 'prosemirror-schema-list';
import { orderedListNode } from 'wax-prosemirror-schema'; import { orderedListNode } from 'wax-prosemirror-schema';
import Service from '../../Service';
import OrderedList from './OrderedList'; import OrderedList from './OrderedList';
class OrderedListService extends Service { class OrderedListService extends Service {
name = 'OrderedListService'; name = 'OrderedListService';
boot() { boot() {
const shortCuts = this.container.get('ShortCuts'); const shortCuts = this.container.get('ShortCuts');
// shortCuts.addShortCut({ shortCuts.addShortCut({
// "Shift-Ctrl-9": wrapInList(this.schema.nodes.orderedlist) 'Shift-Ctrl-9': wrapInList(this.schema.nodes.orderedlist),
// }); });
} }
register() { register() {
......
/* eslint-disable no-underscore-dangle */
import { isPlainObject } from 'lodash'; import { isPlainObject } from 'lodash';
import ParseRule from './ParseRule'; import ParseRule from './ParseRule';
import Middleware from '../lib/Middleware'; import Middleware from '../lib/Middleware';
...@@ -55,7 +56,7 @@ export default class Node { ...@@ -55,7 +56,7 @@ export default class Node {
} }
toJSON() { toJSON() {
const importer = this.importer; const { importer } = this;
return { return {
atom: this.atom, atom: this.atom,
......
...@@ -113,12 +113,12 @@ const redoShortCut = (state, dispatch, view) => ...@@ -113,12 +113,12 @@ const redoShortCut = (state, dispatch, view) =>
redo(state, tr => dispatch(tr.setMeta('inputType', 'Redo')), view); redo(state, tr => dispatch(tr.setMeta('inputType', 'Redo')), view);
@injectable() @injectable()
class ShortCuts { export default class ShortCuts {
constructor(plugins, schema) { constructor() {
this.insertBreak = this.insertBreak.bind(this); this.insertBreak = this.insertBreak.bind(this);
this.insertRule = this.insertRule.bind(this); this.insertRule = this.insertRule.bind(this);
this.PmPlugins = plugins; // this.PmPlugins = plugins;
this.schema = schema; // this.schema = schema;
this.keys = this.getKeys(); this.keys = this.getKeys();
} }
...@@ -135,13 +135,12 @@ class ShortCuts { ...@@ -135,13 +135,12 @@ class ShortCuts {
} }
createShortCuts() { createShortCuts() {
const shortCuts = keymap(this.createKeyBindings()); this.shortCuts = keymap(this.createKeyBindings());
this.PmPlugins.add('shortcuts', shortCuts); return this.shortCuts;
} }
addShortCut(shortcut) { addShortCut(shortcut) {
Object.assign(this.keys, shortcut); Object.assign(this.keys, shortcut);
this.createShortCuts();
} }
createKeyBindings() { createKeyBindings() {
...@@ -166,13 +165,11 @@ class ShortCuts { ...@@ -166,13 +165,11 @@ class ShortCuts {
'Shift-Enter': chainCommands(exitCode, this.insertBreak), 'Shift-Enter': chainCommands(exitCode, this.insertBreak),
'Ctrl-Enter': chainCommands(exitCode, this.insertBreak), 'Ctrl-Enter': chainCommands(exitCode, this.insertBreak),
'Mod-_': this.insertRule, 'Mod-_': this.insertRule,
'Mod-[': liftListItem(this.schema.nodes.list_item), // 'Mod-[': liftListItem(this.schema.nodes.list_item),
'Mod-]': sinkListItem(this.schema.nodes.list_item), // 'Mod-]': sinkListItem(this.schema.nodes.list_item),
Enter: pressEnter, Enter: pressEnter,
'Shift-Ctrl-8': wrapInList(this.schema.nodes.bulletlist), // 'Shift-Ctrl-8': wrapInList(this.schema.nodes.bulletlist),
'Shift-Ctrl-9': wrapInList(this.schema.nodes.orderedlist), // 'Shift-Ctrl-9': wrapInList(this.schema.nodes.orderedlist),
}; };
} }
} }
export default ShortCuts;
...@@ -4,30 +4,15 @@ import ShortCuts from './ShortCuts'; ...@@ -4,30 +4,15 @@ import ShortCuts from './ShortCuts';
export default class ShortCutsService extends Service { export default class ShortCutsService extends Service {
name = 'ShortCutsService'; name = 'ShortCutsService';
boot() {
const shortCuts = this.container.get('ShortCuts');
shortCuts.createShortCuts();
}
// TODO start ShortCuts as Schema is initiated // TODO start ShortCuts as Schema is initiated
register() { register() {
const { PmPlugins } = this.app; this.container.bind('ShortCuts').to(ShortCuts).inSingletonScope();
this.container
.bind('ShortCuts')
.toDynamicValue(() => {
if (this.app.schema) {
const {
schema: { schema },
} = this.app;
return new ShortCuts(PmPlugins, schema);
}
return new ShortCuts( this.container.bind('CreateShortCut').toFactory(context => {
PmPlugins, return shortCut => {
this.container.get('Schema').getSchema(), const shortCutsInstance = context.container.get('ShortCuts');
); shortCutsInstance.addShortCut(shortCut);
}) };
.inSingletonScope(); });
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment