From 12ceea9e54aef21d587b32cd8d3652be83f944db Mon Sep 17 00:00:00 2001 From: Dionisio Date: Fri, 13 Feb 2026 15:40:58 +0100 Subject: [PATCH] fix: select only filename (without extension) when renaming files When renaming a file (e.g. image.png), the input now selects only 'image' instead of 'image.png', preventing accidental extension changes. Folders still select the full name. Uses setSelectionRange(0, lastDot) to position cursor selection up to the last dot. Closes suggestion from issue #83 feedback. --- static/js/modal.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/static/js/modal.js b/static/js/modal.js index 5c22d0b4..99b638a2 100644 --- a/static/js/modal.js +++ b/static/js/modal.js @@ -19,6 +19,9 @@ const Modal = { onConfirm: null, onCancel: null, + // Rename mode: select only name without extension + _selectNameOnly: false, + /** * Initialize modal system */ @@ -141,6 +144,9 @@ const Modal = { promptRename(currentName, isFolder = false) { const t = window.i18n ? window.i18n.t.bind(window.i18n) : (k) => k; + // For files, we want to select only the name part (without extension) + this._selectNameOnly = !isFolder; + return this.prompt({ title: t('dialogs.rename_title') || 'Renombrar', label: t('dialogs.new_name') || 'Nuevo nombre', @@ -168,7 +174,20 @@ const Modal = { // Focus input after animation setTimeout(() => { this.input.focus(); - this.input.select(); + + if (this._selectNameOnly) { + // Select only the filename, excluding the extension + const value = this.input.value; + const lastDot = value.lastIndexOf('.'); + if (lastDot > 0) { + this.input.setSelectionRange(0, lastDot); + } else { + this.input.select(); + } + this._selectNameOnly = false; + } else { + this.input.select(); + } }, 100); },