Skip to content

Commit

Permalink
Desktop: Fixes #6211: Try to replace the external link with internal …
Browse files Browse the repository at this point in the history
…link when attachment file is pasted in Markdown editor (#6865)
  • Loading branch information
wh201906 authored Jan 11, 2023
1 parent 9a9fdef commit 3bee0a1
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import NoteTextViewer from '../../../NoteTextViewer';
import Editor from './Editor';
import usePluginServiceRegistration from '../../utils/usePluginServiceRegistration';
import Setting from '@joplin/lib/models/Setting';
import Note from '@joplin/lib/models/Note';
import { _ } from '@joplin/lib/locale';
import bridge from '../../../../services/bridge';
import markdownUtils from '@joplin/lib/markdownUtils';
Expand Down Expand Up @@ -292,17 +293,18 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
}
}, []);

const editorPasteText = useCallback(() => {
const editorPasteText = useCallback(async () => {
if (editorRef.current) {
editorRef.current.replaceSelection(clipboard.readText());
const modifiedMd = await Note.replaceResourceExternalToInternalLinks(clipboard.readText(), { useAbsolutePaths: true });
editorRef.current.replaceSelection(modifiedMd);
}
}, []);

const editorPaste = useCallback(() => {
const clipboardText = clipboard.readText();

if (clipboardText) {
editorPasteText();
void editorPasteText();
} else {
// To handle pasting images
void onEditorPaste();
Expand Down

0 comments on commit 3bee0a1

Please sign in to comment.