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

set meta for backspace

parent c398a4d6
No related branches found
No related tags found
1 merge request!107Tracked transaction
...@@ -15,9 +15,25 @@ import { ...@@ -15,9 +15,25 @@ import {
setBlockType, setBlockType,
chainCommands, chainCommands,
exitCode, exitCode,
selectParentNode selectParentNode,
joinBackward,
selectNodeBackward,
deleteSelection
} from "prosemirror-commands"; } from "prosemirror-commands";
const backSpace = chainCommands(
deleteSelection,
joinBackward,
selectNodeBackward
);
const addInputRulebackSpace = (state, dispatch, view) =>
backSpace(
state,
tr => dispatch(tr.setMeta("inputType", "deleteContentBackward")),
view
);
@injectable() @injectable()
class ShortCuts { class ShortCuts {
constructor(plugins, schema) { constructor(plugins, schema) {
...@@ -65,7 +81,7 @@ class ShortCuts { ...@@ -65,7 +81,7 @@ class ShortCuts {
return { return {
"Mod-z": undo, "Mod-z": undo,
"Shift-Mod-z": redo, "Shift-Mod-z": redo,
Backspace: undoInputRule, Backspace: addInputRulebackSpace,
"Mod-y": redo, "Mod-y": redo,
Escape: selectParentNode, Escape: selectParentNode,
"Mod-Enter": chainCommands(exitCode, this.insertBreak), "Mod-Enter": chainCommands(exitCode, this.insertBreak),
......
...@@ -64,26 +64,31 @@ const trackedTransaction = (tr, state, user) => { ...@@ -64,26 +64,31 @@ const trackedTransaction = (tr, state, user) => {
newTr.setMeta(tr.getMeta("uiEvent")); newTr.setMeta(tr.getMeta("uiEvent"));
} }
// if (tr.selectionSet) { if (tr.selectionSet) {
if ( if (
tr.selection instanceof TextSelection && tr.selection instanceof TextSelection &&
(tr.selection.from < state.selection.from || (tr.selection.from < state.selection.from ||
tr.getMeta("inputType") === "deleteContentBackward") tr.getMeta("inputType") === "deleteContentBackward")
) { ) {
const caretPos = map.map(tr.selection.from, -1); const caretPos = map.map(tr.selection.from, -1);
newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos))); newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos)));
} else { } else {
const caretPos = map.map(tr.selection.from, -1); newTr.setSelection(tr.selection.map(newTr.doc, map));
newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos))); }
// newTr.setSelection(tr.selection.map(newTr.doc, map));
} }
// }
if (tr.storedMarksSet) { if (tr.storedMarksSet) {
newTr.setStoredMarks(tr.storedMarks); newTr.setStoredMarks(tr.storedMarks);
} }
if (tr.scrolledIntoView) { if (tr.scrolledIntoView) {
newTr.scrollIntoView(); newTr.scrollIntoView();
} }
if (
tr.selection instanceof TextSelection &&
tr.selection.from < state.selection.from
) {
const caretPos = map.map(tr.selection.from, -1);
newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos)));
}
return newTr; return newTr;
}; };
......
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