Files
openchamber/packages/ui/src/components/views/git/CommitInput.tsx
T
Bohdan Triapitsyn f2ec9b1003 feat(ui): add session history navigation, permission keys, and review shortcuts
mod+alt+arrows step through this window's session-open history (or between
neighbouring tabs when session tabs are on), mod+k r renames the current
session inline, and mod+k a toggles permission auto-accept. Pending
permission cards respond to alt+enter / alt+shift+enter / alt+backspace with
the keys printed on the buttons. The commit message box commits on
mod+enter, alt+arrows step the diff review between changed files, and the
command palette gains search-only commands for rare actions so the initial
list stays short.
2026-08-26 15:46:44 +03:00

85 lines
2.7 KiB
TypeScript

import React from 'react';
import { cn } from '@/lib/utils';
import { useUIStore } from '@/stores/useUIStore';
import { useI18n } from '@/lib/i18n';
interface CommitInputProps {
value: string;
onChange: (value: string) => void;
onSubmit?: () => void;
placeholder?: string;
disabled?: boolean;
hasTouchInput?: boolean;
isMobile?: boolean;
}
const MIN_HEIGHT = 38; // Single line height
const MAX_HEIGHT = 200;
export const CommitInput: React.FC<CommitInputProps> = ({
value,
onChange,
onSubmit,
placeholder,
disabled = false,
hasTouchInput = false,
isMobile = false,
}) => {
const { t } = useI18n();
const textareaRef = React.useRef<HTMLTextAreaElement>(null);
const inputSpellcheckEnabled = useUIStore((state) => state.inputSpellcheckEnabled);
// Auto-resize based on content (layout phase to avoid mount flicker)
React.useLayoutEffect(() => {
const textarea = textareaRef.current;
if (!textarea) return;
const hadFocus = document.activeElement === textarea;
const resize = () => {
// Reset to baseline to measure content height from a stable line.
textarea.style.height = `${MIN_HEIGHT}px`;
const contentHeight = textarea.scrollHeight;
const newHeight = Math.min(Math.max(contentHeight, MIN_HEIGHT), MAX_HEIGHT);
textarea.style.height = `${newHeight}px`;
textarea.style.overflowY = contentHeight > MAX_HEIGHT ? 'auto' : 'hidden';
if (contentHeight > MAX_HEIGHT && !hadFocus) {
textarea.scrollTop = textarea.scrollHeight;
}
};
resize();
const frameId = window.requestAnimationFrame(resize);
return () => {
window.cancelAnimationFrame(frameId);
};
}, [value]);
return (
<textarea
ref={textareaRef}
value={value}
onChange={(e) => onChange(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey) {
e.preventDefault();
onSubmit?.();
}
}}
placeholder={placeholder ?? t('gitView.commit.messagePlaceholder')}
rows={1}
disabled={disabled}
autoCorrect={hasTouchInput ? 'on' : 'off'}
autoCapitalize={hasTouchInput ? 'sentences' : 'off'}
spellCheck={isMobile || inputSpellcheckEnabled}
className={cn(
'w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground',
'resize-none outline-none transition-[border-color,box-shadow] duration-150',
'focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]',
disabled && 'opacity-50'
)}
style={{ minHeight: MIN_HEIGHT, maxHeight: MAX_HEIGHT }}
/>
);
};