From 25c0db502eff850659824ebdbf09a28d1285dc47 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sat, 28 Oct 2023 22:14:12 -0700 Subject: [PATCH] Fixed auto-focus in prompt and env dropdown --- .../components/EnvironmentActionsDropdown.tsx | 26 ++++++++----------- src-web/components/Sidebar.tsx | 9 +++---- src-web/components/core/Editor/Editor.tsx | 9 ++++++- src-web/components/core/Input.tsx | 3 +-- src-web/hooks/Prompt.tsx | 1 + 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src-web/components/EnvironmentActionsDropdown.tsx b/src-web/components/EnvironmentActionsDropdown.tsx index e9a4104d..bffcf21b 100644 --- a/src-web/components/EnvironmentActionsDropdown.tsx +++ b/src-web/components/EnvironmentActionsDropdown.tsx @@ -36,21 +36,17 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo [activeEnvironment?.id], ), { type: 'separator', label: 'Environments' }, - ...((environments.length > 0 - ? [ - { - key: 'edit', - label: 'Manage Environments', - leftSlot: , - onSelect: async () => { - dialog.show({ - title: 'Environments', - render: () => , - }); - }, - }, - ] - : []) as DropdownItem[]), + { + key: 'edit', + label: 'Manage Environments', + leftSlot: , + onSelect: async () => { + dialog.show({ + title: 'Environments', + render: () => , + }); + }, + }, ], [activeEnvironment, dialog, environments, routes], ); diff --git a/src-web/components/Sidebar.tsx b/src-web/components/Sidebar.tsx index 1e93ba0f..90ba428a 100644 --- a/src-web/components/Sidebar.tsx +++ b/src-web/components/Sidebar.tsx @@ -23,7 +23,6 @@ import { useActiveEnvironmentId } from '../hooks/useActiveEnvironmentId'; import { WorkspaceActionsDropdown } from './WorkspaceActionsDropdown'; import { IconButton } from './core/IconButton'; import { useCreateRequest } from '../hooks/useCreateRequest'; -import { w } from '@tauri-apps/api/clipboard-79413165'; interface Props { className?: string; @@ -156,7 +155,7 @@ export const Sidebar = memo(function Sidebar({ className }: Props) { ); return ( -
+
(function Editor( heightMode, contentType, autoFocus, + autoSelect, placeholder, useTemplating, defaultValue, @@ -170,7 +172,12 @@ const _Editor = forwardRef(function Editor( view = new EditorView({ state, parent: container }); cm.current = { view, languageCompartment }; syncGutterBg({ parent: container, className }); - if (autoFocus) view.focus(); + if (autoFocus) { + view.focus(); + } + if (autoSelect) { + view.dispatch({ selection: { anchor: 0, head: view.state.doc.length } }); + } } catch (e) { console.log('Failed to initialize Codemirror', e); } diff --git a/src-web/components/core/Input.tsx b/src-web/components/core/Input.tsx index 5cd51732..fb393c8b 100644 --- a/src-web/components/core/Input.tsx +++ b/src-web/components/core/Input.tsx @@ -8,7 +8,7 @@ import { IconButton } from './IconButton'; import { HStack, VStack } from './Stacks'; export type InputProps = Omit, 'onChange' | 'onFocus'> & - Pick & { + Pick & { name: string; type?: 'text' | 'password'; label: string; @@ -24,7 +24,6 @@ export type InputProps = Omit, 'onChange' | 'on size?: 'sm' | 'md' | 'auto'; className?: string; placeholder?: string; - autoFocus?: boolean; validate?: (v: string) => boolean; require?: boolean; }; diff --git a/src-web/hooks/Prompt.tsx b/src-web/hooks/Prompt.tsx index 6989ceb9..e0759546 100644 --- a/src-web/hooks/Prompt.tsx +++ b/src-web/hooks/Prompt.tsx @@ -30,6 +30,7 @@ export function Prompt({ onHide, label, name, defaultValue, onResult }: PromptPr