Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add select all text as well #113

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/common/components/inline-edit/inline-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const EditableComponent: React.FC<Props> = props => {
const [editText, setEditText] = useState(text);

const inputRef = useRef<HTMLInputElement>(null);
const hasTextSelected = useRef(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this flag?


// handle click outside of the input when editing
useEffect(() => {
Expand All @@ -35,18 +36,24 @@ export const EditableComponent: React.FC<Props> = props => {
) {
setIsEditing(false);
onTextSubmit(editText);
hasTextSelected.current = false;
}
};

const handleKeyDown = (event: KeyboardEvent) => {
if (isEditing && event.key === 'Enter') {
setIsEditing(false);
onTextSubmit(editText);
hasTextSelected.current = false;
}
};

if (isEditing) {
inputRef.current?.focus();
if (!hasTextSelected.current) {
inputRef.current?.focus();
inputRef.current?.select();
hasTextSelected.current = true;
}
document.addEventListener('mousedown', handleClickOutside);
document.addEventListener('keydown', handleKeyDown);
} else {
Expand Down
Loading