Merge pull request #494 from h3poteto/iss-493

closes #493 Handle arrowleft and arrowright key in textarea
This commit is contained in:
AkiraFukushima 2018-08-15 09:39:34 +09:00 committed by GitHub
commit aa6dd42f69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -3,7 +3,7 @@
<textarea
v-model="status"
ref="status"
v-shortkey="openSuggest ? {up: ['arrowup'], down: ['arrowdown'], enter: ['enter']} : {linux: ['ctrl', 'enter'], mac: ['meta', 'enter']}"
v-shortkey="openSuggest ? {up: ['arrowup'], down: ['arrowdown'], enter: ['enter']} : {linux: ['ctrl', 'enter'], mac: ['meta', 'enter'], left: ['arrowleft'], right: ['arrowright']}"
@shortkey="handleKey"
v-on:input="startSuggest"
:placeholder="$t('modals.new_toot.status')"
@ -129,6 +129,7 @@ export default {
this.insertAccount(account)
},
handleKey (event) {
const current = event.target.selectionStart
switch (event.srcKey) {
case 'up':
this.suggestHighlight(this.highlightedIndex - 1)
@ -139,6 +140,12 @@ export default {
case 'enter':
this.selectCurrentAccount()
break
case 'left':
event.target.setSelectionRange(current - 1, current - 1)
break
case 'right':
event.target.setSelectionRange(current + 1, current + 1)
break
case 'linux':
case 'mac':
this.$emit('toot')