Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ui/src/components/Editor/ToolBars/file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment thread
robinv8 marked this conversation as resolved.
})
.catch(() => {
editor.replaceRange('', startPos, endPos);
Expand Down
8 changes: 8 additions & 0 deletions ui/src/components/Editor/utils/codemirror/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand Down
Loading