Markdown editor image paste sets cursor correctly

Now sets cursor to alt text rather than end of placeholder image.
Fixed #751
This commit is contained in:
Dan Brown 2018-03-18 11:32:40 +00:00
parent b42b07179f
commit d2eec4fbce
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 4 additions and 2 deletions

View File

@ -120,7 +120,7 @@ class ImageController extends Controller
{
$this->checkPermission('image-create-all');
$this->validate($request, [
'file' => 'is_image'
'file' => 'required|is_image'
]);
if (!$this->imageRepo->isValidType($type)) {

View File

@ -255,7 +255,9 @@ class MarkdownEditor {
let placeholderImage = window.baseUrl(`/loading.gif#upload${id}`);
let selectedText = cm.getSelection();
let placeHolderText = `![${selectedText}](${placeholderImage})`;
let cursor = cm.getCursor();
cm.replaceSelection(placeHolderText);
cm.setCursor({line: cursor.line, ch: cursor.ch + selectedText.length + 2});
let remoteFilename = "image-" + Date.now() + "." + ext;
let formData = new FormData();
@ -264,7 +266,7 @@ class MarkdownEditor {
window.$http.post('/images/gallery/upload', formData).then(resp => {
replaceContent(placeholderImage, resp.data.thumbs.display);
}).catch(err => {
events.emit('error', trans('errors.image_upload_error'));
window.$events.emit('error', trans('errors.image_upload_error'));
replaceContent(placeHolderText, selectedText);
console.log(err);
});