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))

@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Refactors file and folder renaming to share post-rename state updates.

  • Adds required-input configuration to the rename prompt.
  • Consolidates Termux and standard filesystem rename handling under one error boundary.
  • Reuses the common recent-file, editor, folder-tree, toast, and reload updates.

Confidence Score: 4/5

The PR does not yet appear safe to merge because empty rename submissions still bypass the intended required-field enforcement and silently cancel.

Although greptile replied that the issue was invalid because the regex disabled submission, FILE_NAME_REGEX accepts the empty string, so the enabled form submission resolves an empty value and the rename handler silently exits.

Files Needing Attention: src/pages/fileBrowser/fileBrowser.js; src/dialogs/prompt.js; src/lib/config.js

Important Files Changed

Filename Overview
src/pages/fileBrowser/fileBrowser.js Consolidates rename execution and subsequent UI/state synchronization while adding required-input configuration.

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

Comment thread src/pages/fileBrowser/fileBrowser.js

@bajrangCoder bajrangCoder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@AuDevTist1C
AuDevTist1C force-pushed the refactor/file-browser-rename-logic branch from 8380be3 to cf04325 Compare August 5, 2026 02:48
@AuDevTist1C
AuDevTist1C force-pushed the refactor/file-browser-rename-logic branch from 30873f3 to 6ce70f4 Compare August 14, 2026 08:49
@AuDevTist1C
AuDevTist1C force-pushed the refactor/file-browser-rename-logic branch 2 times, most recently from d6f13d3 to 3cf8973 Compare August 14, 2026 15:32
…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)
@AuDevTist1C
AuDevTist1C force-pushed the refactor/file-browser-rename-logic branch from 3cf8973 to fc1cf4a Compare August 14, 2026 16:15
@bajrangCoder

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants