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