-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
Some browsers seem to put file system paths into blob.name which look rather odd and should not be part of the posted content. Always set name to static "image" like GH does.
I generally wonder if it's ever desirable to accept the browser-provided filename. Generally I think not because it's bound to always be something autogenerated because clipboard conceptionally stores a byte stream without a filename, thought there might be exceptions. |
Here's something to check out browser behaviour. On macOS, I see get |
Couldn't we look for the last index of '/' and trim between it and the last indexof '.'? (defaulting to 'image' if that is nothing) |
Looking at #13333 (comment) again, it appears the strange path appears before the pasted content. So I think there might be two @a1012112796 please tell the exact os/browser used there and if it happens on CTRL-V too as opposed to right click. Also, what tool is used to copy the content and could it be that that tool puts two items on the system clipboard? |
@silverwind Thanks for your work, But sadly it maybe not usefull. test with a simple text editor, you can see it only add one link to system clipboard, not other thing. test with ubunt v20.04, chrome |
@a1012112796 can you try pasting on https://jsfiddle.net/silverwind/acezbfkd/? It should only show the image item like this: |
Hmm, I see. |
uploadFile(img, (res) => { | ||
const data = JSON.parse(res); | ||
replaceAndKeepCursor(field, `![${name}]()`, `![${name}](${AppSubUrl}/attachments/${data.uuid})`); | ||
replaceAndKeepCursor(field, `![image]()`, `![image](${AppSubUrl}/attachments/${data.uuid})`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaceAndKeepCursor(field, `![image]()`, `![image](${AppSubUrl}/attachments/${data.uuid})`); | |
replaceAndKeepCursor(field, `![Uploading image ...]()`, `![image](${AppSubUrl}/attachments/${data.uuid})`); |
@@ -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]()`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
insertAtCursor(field, `![image]()`); | |
insertAtCursor(field, `![Uploading image ...]()`); |
There was a problem hiding this comment.
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.
suggest show error message on the editor bottom when uploading image failed like |
The issue is your paste actions pastes two things, a path and a image while generally the expectation is that only a image is there. I think we can workaround by ignoring textual items when a image is present. I'm not sure how GitHub handles this as the minified JS is quite hard to read but I assume you don't have the issue on GitHub, right? Maybe there is a helper JS library around to handle image paste for us. |
Closing as this approach is wrong, may check it out later in a Ubuntu VM. |
Some browsers seem to put file system paths into blob.name which look rather odd and should not be part of the posted content. Always set name to static "image" like GH does.
Ref: #13333 (comment)
@a1012112796 please confirm this works for you, also test multiple pastes.