Skip to content

Commit

Permalink
feat: goto dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 3, 2021
1 parent 65924dc commit 200bcff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions packages/client/internals/Goto.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<script setup lang="ts">
import { whenever } from '@vueuse/core'
import { nextTick, ref } from 'vue'
import { go } from '../logic/nav'
import { computed, nextTick, ref } from 'vue'
import { go, total } from '../logic/nav'
import { showGotoDialog } from '../state'
const input = ref<HTMLInputElement>()
const num = ref('')
const text = ref('')
const num = computed(() => +text.value)
const valid = computed(() => !isNaN(num.value) && num.value > 0 && num.value <= total.value)
function goTo() {
const n = +num.value
if (!isNaN(n))
go(n - 1)
if (valid.value)
go(num.value)
close()
}
Expand All @@ -19,7 +20,7 @@ function close() {
}
whenever(showGotoDialog, async() => {
num.value = ''
text.value = ''
await nextTick()
input.value?.focus()
})
Expand All @@ -35,11 +36,12 @@ whenever(showGotoDialog, async() => {
>
<input
ref="input"
v-model="num"
v-model="text"
type="number"
:disabled="!showGotoDialog"
class="outline-none bg-transparent"
placeholder="Goto..."
:class="{ 'text-red-400': !valid && text }"
@keydown.enter="goTo"
@keydown.escape="close"
@blur="close"
Expand Down
2 changes: 1 addition & 1 deletion packages/client/logic/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { next, nextSlide, prev, prevSlide } from './nav'
const _shortcut = and(not(isInputing), shortcutsEnabled)

export function shortcut(key: string, fn: Fn) {
return whenever(and(magicKeys[key], _shortcut), fn)
return whenever(and(magicKeys[key], _shortcut), fn, { flush: 'sync' })
}

export function registerShotcuts() {
Expand Down

0 comments on commit 200bcff

Please sign in to comment.