Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: attachment upload broken after v2.0.0 upgrade (#1525)

robin316417961ad0
diff --git a/ui/src/components/Editor/ToolBars/file.tsx b/ui/src/components/Editor/ToolBars/file.tsx
index d48c0e6a..3c2e54ba 100644
--- a/ui/src/components/Editor/ToolBars/file.tsx
+++ b/ui/src/components/Editor/ToolBars/file.tsx
@@ -98,8 +98,7 @@ const File = () => {
uploadImage({ file: e.target.files[0], type: 'post_attachment' })
.then((url) => {
const text = `[${fileName}](${url})`;
- editor.replaceRange('', startPos, endPos);
- editor.replaceSelection(text);
+ editor.replaceRange(text, startPos, endPos);
})
.catch(() => {
editor.replaceRange('', startPos, endPos);
diff --git a/ui/src/components/Editor/utils/codemirror/base.ts b/ui/src/components/Editor/utils/codemirror/base.ts
index 4a257f04..3b20653b 100644
--- a/ui/src/components/Editor/utils/codemirror/base.ts
+++ b/ui/src/components/Editor/utils/codemirror/base.ts
@@ -97,6 +97,14 @@ export function createBaseMethods(editor: Editor) {
});
},
+ replaceRange: (value: string, from: Position, to: Position) => {
+ const fromOffset = editor.state.doc.line(from.line).from + from.ch;
+ const toOffset = editor.state.doc.line(to.line).from + to.ch;
+ editor.dispatch({
+ changes: { from: fromOffset, to: toOffset, insert: value },
+ });
+ },
+
getValue: () => {
return editor.state.doc.toString();
},