Skip to content

Commit

Permalink
Markdown editor image paste sets cursor correctly
Browse files Browse the repository at this point in the history
Now sets cursor to alt text rather than end of placeholder image.
Fixed #751
  • Loading branch information
ssddanbrown committed Mar 18, 2018
1 parent b42b071 commit d2eec4f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function uploadByType($type, Request $request)
{
$this->checkPermission('image-create-all');
$this->validate($request, [
'file' => 'is_image'
'file' => 'required|is_image'
]);

if (!$this->imageRepo->isValidType($type)) {
Expand Down
4 changes: 3 additions & 1 deletion resources/assets/js/components/markdown-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
});
Expand Down

0 comments on commit d2eec4f

Please sign in to comment.