fix: Text caret not placed in new math block after creation

fix: Excessive padding on inline math node
This commit is contained in:
Tom Moor
2023-07-25 00:04:14 -04:00
parent d94caf2783
commit 15c8a4867f
2 changed files with 14 additions and 2 deletions

View File

@@ -268,6 +268,11 @@ width: 100%;
padding: ${props.editorStyle?.padding ?? "initial"};
margin: ${props.editorStyle?.margin ?? "initial"};
.ProseMirror {
padding: 0;
margin: 0;
}
& > .ProseMirror-yjs-cursor {
display: none;
}

View File

@@ -4,7 +4,7 @@ import {
} from "@benrbray/prosemirror-math";
import { PluginSimple } from "markdown-it";
import { NodeSpec, NodeType, Node as ProsemirrorNode } from "prosemirror-model";
import { Command } from "prosemirror-state";
import { Command, TextSelection } from "prosemirror-state";
import { MarkdownSerializerState } from "../lib/markdown/serializer";
import mathRule, { REGEX_BLOCK_MATH_DOLLARS } from "../rules/math";
import Node from "./Node";
@@ -24,7 +24,14 @@ export default class MathBlock extends Node {
commands({ type }: { type: NodeType }) {
return (): Command => (state, dispatch) => {
dispatch?.(state.tr.replaceSelectionWith(type.create()).scrollIntoView());
const tr = state.tr.replaceSelectionWith(type.create());
dispatch?.(
tr
.setSelection(
TextSelection.near(tr.doc.resolve(state.selection.from - 1))
)
.scrollIntoView()
);
return true;
};
}