Skip to content

Commit

Permalink
fix: make file renaming consistent with tag & note renaming (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara authored Mar 12, 2022
1 parent 7720793 commit fc2a350
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,14 @@ export const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
}, [isRenamingFile]);

const renameFile = async (file: SNFile, name: string) => {
const didRename = await handleFileAction({
await handleFileAction({
type: PopoverFileItemActionType.RenameFile,
payload: {
file,
name,
},
});
if (didRename) {
setIsRenamingFile(false);
}
setIsRenamingFile(false);
};

const handleFileNameInput = (event: Event) => {
Expand All @@ -90,11 +88,14 @@ export const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({

const handleFileNameInputKeyDown = (event: KeyboardEvent) => {
if (event.key === KeyboardKey.Enter) {
renameFile(file, fileName);
return;
fileNameInputRef.current?.blur();
}
};

const handleFileNameInputBlur = () => {
renameFile(file, fileName);
};

return (
<div className="flex items-center justify-between p-3">
<div className="flex items-center">
Expand All @@ -108,6 +109,7 @@ export const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
ref={fileNameInputRef}
onInput={handleFileNameInput}
onKeyDown={handleFileNameInputKeyDown}
onBlur={handleFileNameInputBlur}
/>
) : (
<div className="text-sm mb-1">{file.nameWithExt}</div>
Expand Down

0 comments on commit fc2a350

Please sign in to comment.