refactor(tui): simplify config context
This commit is contained in:
parent
3c60470269
commit
f8f8cc9546
27 changed files with 135 additions and 142 deletions
|
|
@ -3,7 +3,7 @@ import { useTheme } from "../context/theme"
|
|||
import { useDialog, type DialogContext } from "./dialog"
|
||||
import { Show, createEffect, createSignal, onMount, type JSX } from "solid-js"
|
||||
import { Spinner } from "../component/spinner"
|
||||
import { useTuiConfig } from "../config"
|
||||
import { useConfig } from "../config"
|
||||
import { useBindings, useCommandShortcut } from "../keymap"
|
||||
|
||||
export type DialogPromptProps = {
|
||||
|
|
@ -20,7 +20,7 @@ export type DialogPromptProps = {
|
|||
export function DialogPrompt(props: DialogPromptProps) {
|
||||
const dialog = useDialog()
|
||||
const { theme } = useTheme()
|
||||
const tuiConfig = useTuiConfig()
|
||||
const config = useConfig().data
|
||||
const submitShortcut = useCommandShortcut("dialog.prompt.submit")
|
||||
const [textareaTarget, setTextareaTarget] = createSignal<TextareaRenderable>()
|
||||
let textarea: TextareaRenderable
|
||||
|
|
@ -43,7 +43,7 @@ export function DialogPrompt(props: DialogPromptProps) {
|
|||
run: confirm,
|
||||
},
|
||||
],
|
||||
bindings: tuiConfig.keybinds.gather("dialog.prompt", ["dialog.prompt.submit"]),
|
||||
bindings: config.keybinds.gather("dialog.prompt", ["dialog.prompt.submit"]),
|
||||
}))
|
||||
|
||||
onMount(() => {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import { isDeepEqual } from "remeda"
|
|||
import { useDialog, type DialogContext } from "./dialog"
|
||||
import { Locale } from "../util/locale"
|
||||
import { getScrollAcceleration } from "../util/scroll"
|
||||
import { useTuiConfig } from "../config"
|
||||
import { useConfig } from "../config"
|
||||
import { formatKeyBindings, useBindings, useKeymapSelector } from "../keymap"
|
||||
|
||||
export interface DialogSelectProps<T> {
|
||||
|
|
@ -86,8 +86,8 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
|
|||
|
||||
const dialog = useDialog()
|
||||
const { theme } = useTheme()
|
||||
const tuiConfig = useTuiConfig()
|
||||
const scrollAcceleration = createMemo(() => getScrollAcceleration(tuiConfig))
|
||||
const config = useConfig().data
|
||||
const scrollAcceleration = createMemo(() => getScrollAcceleration(config))
|
||||
|
||||
const [store, setStore] = createStore({
|
||||
selected: 0,
|
||||
|
|
@ -130,7 +130,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
|
|||
const labels = new Map<string, string>()
|
||||
|
||||
for (const action of shownActions()) {
|
||||
const label = formatKeyBindings(actionBindings().get(action.command), tuiConfig)
|
||||
const label = formatKeyBindings(actionBindings().get(action.command), config)
|
||||
if (label) labels.set(action.command, label)
|
||||
}
|
||||
|
||||
|
|
@ -450,7 +450,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
|
|||
})),
|
||||
],
|
||||
bindings: [
|
||||
...tuiConfig.keybinds.gather("dialog.select", [
|
||||
...config.keybinds.gather("dialog.select", [
|
||||
"dialog.select.prev",
|
||||
"dialog.select.next",
|
||||
"dialog.select.page_up",
|
||||
|
|
@ -459,7 +459,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
|
|||
"dialog.select.end",
|
||||
"dialog.select.submit",
|
||||
]),
|
||||
...visible.flatMap((item) => tuiConfig.keybinds.get(item.command)),
|
||||
...visible.flatMap((item) => config.keybinds.get(item.command)),
|
||||
...(visible.length
|
||||
? [
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue