refactor(file-browser): consolidate rename logic and prevent empty file names - #2560
refactor(file-browser): consolidate rename logic and prevent empty file names#2560AuDevTist1C wants to merge 1 commit into
Conversation
…lidation - Enforce `required: true` on the file/folder rename prompt to prevent empty inputs. - Unify post-rename side effects (recents update, editor tab URI sync, tree state, success toast, reload) across standard and Termux filesystem paths. - Wrap standard filesystem rename execution inside the master try-catch block to gracefully capture errors. (AI generated commit message)
Greptile SummaryThis PR consolidates the local and Termux rename flows while adding required-field validation to the rename prompt.
Confidence Score: 4/5The PR appears safe to merge, although Enter-key submission still bypasses the intended required-field feedback. The filesystem rename refactor preserves the existing state-update paths, while the only accepted concern is a non-blocking prompt inconsistency that silently cancels an empty Enter-key submission. Files Needing Attention: src/pages/fileBrowser/fileBrowser.js Important Files Changed
Reviews (1): Last reviewed commit: "refactor(file-browser): deduplicate rena..." | Re-trigger Greptile |
bajrangCoder
left a comment
There was a problem hiding this comment.
Enter bypasses the new required validation.
FILE_NAME_REGEX accepts an empty string, so clearing the field enables submission. Pressing Enter runs prompt onsubmit, which resolves "" without checking options.required or hiding the prompt. The rename is cancelled by the caller, but the dialog remains in a resolved, non-functional state.
This PR refactors the file/folder rename control flow in
fileBrowser.jsto reduce code duplication and adds explicit non-empty input enforcement to the rename prompt.Changes
1. Enforce Non-Empty Rename Input
required: trueto the rename prompt options.match: config.FILE_NAME_REGEX, addingrequired: trueprevents submitting empty string values ("").2. Refactor and Deduplicate
renameFileFlowrenameFile(newname)to follow the DRY (Don't Repeat Yourself) principle.isTermuxUrl(url)) contained duplicate state updates (recents.removeFile,recents.addFile,editorManager.getFile,openFolder.renameItem,toast, andreload()) and exited early.newUrlwithin anif / elseblock. Successful executions fall through to a single set of state updates and UI refreshes.3. Unified Error Handling
fs.renameTo(newname)) inside the mastertry...catchblock to handle errors consistently alongside the Termux branch.(PR name and description are AI generated (Gemini 3.6 Flash))