Merge pull request '#233: file attachment title takes the file name' (#236) from fix-233 into dev
CI / test (push) Successful in 50s
CI / docker (push) Successful in 44s

This commit was merged in pull request #236.
This commit is contained in:
fen
2026-09-10 23:39:44 +00:00
+11 -13
View File
@@ -307,21 +307,19 @@ function setAttachedFile(file) {
attachedFile = file; attachedFile = file;
renderFileChip(); renderFileChip();
setHidden('file-text-note', false); setHidden('file-text-note', false);
// #171/#184: title auto-fill — images take the file name; text files // #233: title auto-fill — the file's own name always wins when the
// use the language-placeholder convention (e.g. Python.py, fallback // title is still blank; fallback is date.fileextension (e.g.
// Text.txt). Only when the title is still blank; never overwrite a // 2026-09-10.txt) when the name is missing or unusable. Never
// typed title. // overwrite a typed title.
if (!$('title').value.trim()) { if (!$('title').value.trim()) {
if (IMAGE_RE.test(file.type)) { const raw = (file.name || '').trim();
$('title').value = file.name; if (raw) {
$('title').value = raw;
} else { } else {
const lang = LANG_BY_EXT[extOf(file.name)]; const d = new Date();
if (lang) { const iso = d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0');
const fn = defaultFilename(lang); const ext = extOf(raw || file.name);
if (fn) $('title').value = fn; $('title').value = ext ? iso + '.' + ext : iso;
} else if (TEXT_EXTS.has(extOf(file.name))) {
$('title').value = defaultFilename('text') || 'Text.txt';
}
} }
} }
showFileInEditor(file); showFileInEditor(file);