Merge pull request #808 from h3poteto/iss-791

closes #791 Fix cursor position when user types arrow keys on image description
This commit is contained in:
AkiraFukushima 2018-12-25 01:24:37 +09:00 committed by GitHub
commit 7f097067e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -28,6 +28,8 @@
class="image-description"
:placeholder="$t('modals.new_toot.description')"
v-model="mediaDescriptions[media.id]"
v-shortkey="{left: ['arrowleft'], right: ['arrowright']}"
@shortkey="handleDescriptionKey"
role="textbox"
contenteditable="true"
aria-multiline="true">
@ -301,6 +303,19 @@ export default {
})
.catch(_ => {})
}
},
handleDescriptionKey (event) {
const current = event.target.selectionStart
switch (event.srcKey) {
case 'left':
event.target.setSelectionRange(current - 1, current - 1)
break
case 'right':
event.target.setSelectionRange(current + 1, current + 1)
break
default:
return true
}
}
}
}