Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
feat: Add handling for shift+enter, tab keys within code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
tommoor committed Feb 13, 2021
1 parent 5f2e38d commit 746b04d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/nodes/CodeFence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import powershell from "refractor/lang/powershell";
import ruby from "refractor/lang/ruby";
import sql from "refractor/lang/sql";
import typescript from "refractor/lang/typescript";

import { setBlockType } from "prosemirror-commands";
import { textblockTypeInputRule } from "prosemirror-inputrules";
import copy from "copy-to-clipboard";
import Prism, { LANGUAGES } from "../plugins/Prism";
import isInCode from "../queries/isInCode";
import Node from "./Node";
import { ToastType } from "../types";

Expand Down Expand Up @@ -107,9 +107,23 @@ export default class CodeFence extends Node {
return () => setBlockType(type);
}

keys({ type }) {
keys({ type, schema }) {
return {
"Shift-Ctrl-\\": setBlockType(type),
"Shift-Enter": (state, dispatch) => {
if (!isInCode(state)) return false;

const { tr, selection } = state;
dispatch(tr.insertText("\n", selection.from, selection.to));
return true;
},
Tab: (state, dispatch) => {
if (!isInCode(state)) return false;

const { tr, selection } = state;
dispatch(tr.insertText(" ", selection.from, selection.to));
return true;
},
};
}

Expand Down

0 comments on commit 746b04d

Please sign in to comment.