From 785fafcaf9aa51457ddf7b38f9638f44700ad3ba Mon Sep 17 00:00:00 2001 From: fen Date: Thu, 10 Sep 2026 17:05:08 -0500 Subject: [PATCH] #233: file attachment title takes the file name, fallback date.ext --- internal/web/static/new.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/internal/web/static/new.js b/internal/web/static/new.js index 816f089..3e4cf2c 100644 --- a/internal/web/static/new.js +++ b/internal/web/static/new.js @@ -307,21 +307,19 @@ function setAttachedFile(file) { attachedFile = file; renderFileChip(); setHidden('file-text-note', false); - // #171/#184: title auto-fill — images take the file name; text files - // use the language-placeholder convention (e.g. Python.py, fallback - // Text.txt). Only when the title is still blank; never overwrite a - // typed title. + // #233: title auto-fill — the file's own name always wins when the + // title is still blank; fallback is date.fileextension (e.g. + // 2026-09-10.txt) when the name is missing or unusable. Never + // overwrite a typed title. if (!$('title').value.trim()) { - if (IMAGE_RE.test(file.type)) { - $('title').value = file.name; + const raw = (file.name || '').trim(); + if (raw) { + $('title').value = raw; } else { - const lang = LANG_BY_EXT[extOf(file.name)]; - if (lang) { - const fn = defaultFilename(lang); - if (fn) $('title').value = fn; - } else if (TEXT_EXTS.has(extOf(file.name))) { - $('title').value = defaultFilename('text') || 'Text.txt'; - } + const d = new Date(); + const iso = d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); + const ext = extOf(raw || file.name); + $('title').value = ext ? iso + '.' + ext : iso; } } showFileInEditor(file); -- 2.54.0