fix(ui): auto-focus tag input and flush uncommitted text on save (#934)

- ModelModal (ModelTags.js): auto-focus input on entering tag edit mode
- ModelModal (ModelTags.js): flush uncommitted input text as tag on Save
- Bulk Add Tags (BulkManager.js): same two fixes
- RecipeModal already handled both cases correctly
This commit is contained in:
Will Miao
2026-05-20 23:06:40 +08:00
parent 78303b2a5e
commit 818fa34a48
2 changed files with 24 additions and 2 deletions

View File

@@ -274,7 +274,17 @@ async function saveTags() {
const filePath = editBtn.dataset.filePath;
const tagElements = document.querySelectorAll('.metadata-item');
const tags = Array.from(tagElements).map(tag => tag.dataset.tag);
let tags = Array.from(tagElements).map(tag => tag.dataset.tag);
// Flush uncommitted input as a tag so it's not silently lost on save
const tagInput = document.querySelector('.metadata-input');
if (tagInput) {
const pendingTag = tagInput.value.trim().toLowerCase();
if (pendingTag && !tags.includes(pendingTag)) {
tags.push(pendingTag);
}
tagInput.value = '';
}
// Get original tags to compare
const originalTagElements = document.querySelectorAll('.tooltip-tag');
@@ -465,6 +475,7 @@ function setupTagInput() {
const tagInput = document.querySelector('.metadata-input');
if (tagInput) {
tagInput.focus();
tagInput.addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
e.preventDefault();

View File

@@ -785,6 +785,7 @@ export class BulkManager {
// Setup tag input behavior
const tagInput = document.querySelector('.bulk-metadata-input');
if (tagInput) {
tagInput.focus();
tagInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
@@ -1008,7 +1009,17 @@ export class BulkManager {
async saveBulkTags(mode = 'append') {
const tagElements = document.querySelectorAll('#bulkTagsItems .metadata-item');
const tags = Array.from(tagElements).map(tag => tag.dataset.tag);
let tags = Array.from(tagElements).map(tag => tag.dataset.tag);
// Flush uncommitted input as a tag so it's not silently lost on save
const tagInput = document.querySelector('.bulk-metadata-input');
if (tagInput) {
const pendingTag = tagInput.value.trim().toLowerCase();
if (pendingTag && !tags.includes(pendingTag)) {
tags.push(pendingTag);
}
tagInput.value = '';
}
if (tags.length === 0) {
showToast('toast.models.noTagsToAdd', {}, 'warning');