Compare commits

...

2 Commits

Author SHA1 Message Date
codegen-sh[bot] 4434d3ed6b Fix TypeScript and linting errors in Document.tsx
- Import Slice from prosemirror-model to fix type error
- Use new Slice(doc.content, 0, 0) instead of doc.content for replace method
- Remove unused sel variable declaration
- Prefix unused _selection parameter with underscore

Fixes failing 'types' and 'lint' checks in CI
2025-10-31 00:46:33 +00:00
codegen-sh[bot] 9121d5e972 Fix template application adding empty linebreaks
When applying a template to a document, the replaceSelectionWith method
was incorrectly trying to insert a document node into the existing
document, which caused the template content to be added after existing
content (like empty paragraphs) rather than replacing it entirely.

This fix changes the approach to replace the entire document content
with the template content using tr.replace(), ensuring that templates
are applied cleanly without extra linebreaks.

Fixes #10508
2025-10-31 00:34:26 +00:00
+10 -4
View File
@@ -3,7 +3,7 @@ import debounce from "lodash/debounce";
import isEqual from "lodash/isEqual";
import { action, observable } from "mobx";
import { observer } from "mobx-react";
import { Node } from "prosemirror-model";
import { Node, Slice } from "prosemirror-model";
import { AllSelection, TextSelection } from "prosemirror-state";
import * as React from "react";
import { WithTranslation, withTranslation } from "react-i18next";
@@ -150,7 +150,7 @@ class DocumentScene extends React.Component<Props> {
*/
replaceSelection = (
template: Document | Revision,
selection?: TextSelection | AllSelection
_selection?: TextSelection | AllSelection
) => {
const editorRef = this.editor.current;
@@ -159,7 +159,6 @@ class DocumentScene extends React.Component<Props> {
}
const { view, schema } = editorRef;
const sel = selection ?? TextSelection.near(view.state.doc.resolve(0));
const doc = Node.fromJSON(
schema,
ProsemirrorHelper.replaceTemplateVariables(
@@ -169,7 +168,14 @@ class DocumentScene extends React.Component<Props> {
);
if (doc) {
view.dispatch(view.state.tr.setSelection(sel).replaceSelectionWith(doc));
// Replace the entire document content with the template content
// instead of trying to insert the document node itself
const tr = view.state.tr.replace(
0,
view.state.doc.content.size,
new Slice(doc.content, 0, 0)
);
view.dispatch(tr);
}
this.isEditorDirty = true;