Skip to content

Commit 200bcff

Browse files
committed
feat: goto dialog
1 parent 65924dc commit 200bcff

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

packages/client/internals/Goto.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<script setup lang="ts">
22
import { whenever } from '@vueuse/core'
3-
import { nextTick, ref } from 'vue'
4-
import { go } from '../logic/nav'
3+
import { computed, nextTick, ref } from 'vue'
4+
import { go, total } from '../logic/nav'
55
import { showGotoDialog } from '../state'
66
77
const input = ref<HTMLInputElement>()
8-
const num = ref('')
8+
const text = ref('')
9+
const num = computed(() => +text.value)
10+
const valid = computed(() => !isNaN(num.value) && num.value > 0 && num.value <= total.value)
911
1012
function goTo() {
11-
const n = +num.value
12-
if (!isNaN(n))
13-
go(n - 1)
13+
if (valid.value)
14+
go(num.value)
1415
close()
1516
}
1617
@@ -19,7 +20,7 @@ function close() {
1920
}
2021
2122
whenever(showGotoDialog, async() => {
22-
num.value = ''
23+
text.value = ''
2324
await nextTick()
2425
input.value?.focus()
2526
})
@@ -35,11 +36,12 @@ whenever(showGotoDialog, async() => {
3536
>
3637
<input
3738
ref="input"
38-
v-model="num"
39+
v-model="text"
3940
type="number"
4041
:disabled="!showGotoDialog"
4142
class="outline-none bg-transparent"
4243
placeholder="Goto..."
44+
:class="{ 'text-red-400': !valid && text }"
4345
@keydown.enter="goTo"
4446
@keydown.escape="close"
4547
@blur="close"

packages/client/logic/shortcuts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { next, nextSlide, prev, prevSlide } from './nav'
66
const _shortcut = and(not(isInputing), shortcutsEnabled)
77

88
export function shortcut(key: string, fn: Fn) {
9-
return whenever(and(magicKeys[key], _shortcut), fn)
9+
return whenever(and(magicKeys[key], _shortcut), fn, { flush: 'sync' })
1010
}
1111

1212
export function registerShotcuts() {

0 commit comments

Comments
 (0)