refs #791 Fix cursor position when user type arrow keys on image description

This commit is contained in:
AkiraFukushima 2018-12-25 00:39:57 +09:00
parent abc4bf5818
commit bd16a491fa
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
}
}
}
}