Skip to content

refactor(file-browser): consolidate rename logic and prevent empty file names - #2560

Open
AuDevTist1C wants to merge 1 commit into
Acode-Foundation:mainfrom
AuDevTist1C:refactor/file-browser-rename-logic
Open

refactor(file-browser): consolidate rename logic and prevent empty file names#2560
AuDevTist1C wants to merge 1 commit into
Acode-Foundation:mainfrom
AuDevTist1C:refactor/file-browser-rename-logic

Conversation

@AuDevTist1C

Copy link
Copy Markdown
Contributor

This PR refactors the file/folder rename control flow in fileBrowser.js to reduce code duplication and adds explicit non-empty input enforcement to the rename prompt.


Changes

1. Enforce Non-Empty Rename Input

  • Added required: true to the rename prompt options.
  • While regex pattern matching was already handled via match: config.FILE_NAME_REGEX, adding required: true prevents submitting empty string values ("").

2. Refactor and Deduplicate renameFile Flow

  • Consolidated the logic in renameFile(newname) to follow the DRY (Don't Repeat Yourself) principle.
  • Before: The Termux branch (isTermuxUrl(url)) contained duplicate state updates (recents.removeFile, recents.addFile, editorManager.getFile, openFolder.renameItem, toast, and reload()) and exited early.
  • After: Both Termux and standard filesystem paths resolve newUrl within an if / else block. Successful executions fall through to a single set of state updates and UI refreshes.

3. Unified Error Handling

  • Wrapped standard filesystem operations (fs.renameTo(newname)) inside the master try...catch block to handle errors consistently alongside the Termux branch.

(PR name and description are AI generated (Gemini 3.6 Flash))

…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-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR consolidates the local and Termux rename flows while adding required-field validation to the rename prompt.

  • Shares post-rename updates and error handling across filesystem paths.
  • Constructs the Termux destination URL once before copying and deleting the original file.
  • Adds required: true to the file-browser rename prompt.

Confidence Score: 4/5

The 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

Filename Overview
src/pages/fileBrowser/fileBrowser.js The rename-flow consolidation preserves existing backend behavior, but the added required validation is bypassed when the prompt is submitted with Enter.

Reviews (1): Last reviewed commit: "refactor(file-browser): deduplicate rena..." | Re-trigger Greptile

Comment thread src/pages/fileBrowser/fileBrowser.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant