Skip to content

Commit a218924

Browse files
committed
Merge remote-tracking branch 'origin/dev' into test
2 parents b1da65f + 3164179 commit a218924

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎ui/src/components/Editor/ToolBars/file.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ const File = () => {
9898
uploadImage({ file: e.target.files[0], type: 'post_attachment' })
9999
.then((url) => {
100100
const text = `[${fileName}](${url})`;
101-
editor.replaceRange('', startPos, endPos);
102-
editor.replaceSelection(text);
101+
editor.replaceRange(text, startPos, endPos);
103102
})
104103
.catch(() => {
105104
editor.replaceRange('', startPos, endPos);

‎ui/src/components/Editor/utils/codemirror/base.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ export function createBaseMethods(editor: Editor) {
9797
});
9898
},
9999

100+
replaceRange: (value: string, from: Position, to: Position) => {
101+
const fromOffset = editor.state.doc.line(from.line).from + from.ch;
102+
const toOffset = editor.state.doc.line(to.line).from + to.ch;
103+
editor.dispatch({
104+
changes: { from: fromOffset, to: toOffset, insert: value },
105+
});
106+
},
107+
100108
getValue: () => {
101109
return editor.state.doc.toString();
102110
},

0 commit comments

Comments
 (0)