Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use 'image' as name for pasted images #13339

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 3 additions & 5 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,10 @@ function initImagePaste(target) {
const field = this;
field.addEventListener('paste', (event) => {
retrieveImageFromClipboardAsBlob(event, (img) => {
const name = img.name.substr(0, img.name.lastIndexOf('.'));
insertAtCursor(field, `![${name}]()`);
insertAtCursor(field, `![image]()`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
insertAtCursor(field, `![image]()`);
insertAtCursor(field, `![Uploading image ...]()`);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is helping any, I prefer the text to not change after upload.

uploadFile(img, (res) => {
const data = JSON.parse(res);
replaceAndKeepCursor(field, `![${name}]()`, `![${name}](${AppSubUrl}/attachments/${data.uuid})`);
replaceAndKeepCursor(field, `![image]()`, `![image](${AppSubUrl}/attachments/${data.uuid})`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
replaceAndKeepCursor(field, `![image]()`, `![image](${AppSubUrl}/attachments/${data.uuid})`);
replaceAndKeepCursor(field, `![Uploading image ...]()`, `![image](${AppSubUrl}/attachments/${data.uuid})`);

const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
$('.files').append(input);
});
Expand All @@ -368,11 +367,10 @@ function initImagePaste(target) {
function initSimpleMDEImagePaste(simplemde, files) {
simplemde.codemirror.on('paste', (_, event) => {
retrieveImageFromClipboardAsBlob(event, (img) => {
const name = img.name.substr(0, img.name.lastIndexOf('.'));
uploadFile(img, (res) => {
const data = JSON.parse(res);
const pos = simplemde.codemirror.getCursor();
simplemde.codemirror.replaceRange(`![${name}](${AppSubUrl}/attachments/${data.uuid})`, pos);
simplemde.codemirror.replaceRange(`![image](${AppSubUrl}/attachments/${data.uuid})`, pos);
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
files.append(input);
});
Expand Down