Skip to content

Commit 3b726b8

Browse files
Merge pull request #68 from newtextdoc1111/dev
Merge Dev
2 parents 7d8190e + 4066f58 commit 3b726b8

10 files changed

Lines changed: 82 additions & 16 deletions

File tree

.github/workflows/test.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@ jobs:
2828
runs-on: ubuntu-latest
2929

3030
steps:
31-
- uses: actions/checkout@v1
32-
- uses: actions-hub/stylelint@master
33-
env:
34-
PATTERN : 'web/css/*.css'
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Set up Node.js
35+
uses: actions/setup-node@v6
36+
with:
37+
node-version: '22'
38+
cache: 'npm'
39+
40+
- name: Install dependencies
41+
run: npm ci
42+
43+
- name: Run stylelint
44+
run: npx stylelint "web/css/*.css"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ For example, by preparing the following CSV, you can quickly insert correspondin
169169
- **Max suggestions**: Maximum number of autocomplete suggestions to display.
170170
- **Auto-Insert Comma**: Automatically insert a comma after tags when inserting from autocomplete.
171171
- **Replace '_' with 'Space'**: Replaces underscores with spaces when inserting tags. This setting also affects related tag display.
172+
- **String to add before artist tags**: Text to prepend when inserting an artist tag. For Anima models, specify `@`.
172173
- **Enable Loras and Embeddings**: Display Lora and Embedding in the suggestions.
173174
- **Use Fast Search**: Switch autocomplete suggestions search to fast processing (see [About Fast Search for Autocomplete](#about-fast-search-for-autocomplete) for details).
174175

docs/README_jp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ worst_quality,5,9999999,
167167
- **Max Suggestions**: オートコンプリート候補の最大表示件数
168168
- **Auto-Insert Comma**: タグの挿入時、末尾にカンマを追加する
169169
- **Replace '_' with 'Space'**: タグ挿入時にアンダースコアをスペースに置き換えます。この設定は関連タグ表示にも影響します
170+
- **String to add before artist tags**: アーティストタグを挿入する際に付加する文字列。 Anima モデルの場合は「@」を指定します
170171
- **Enable Loras and Embeddings**: LoraとEmbeddingを候補に表示する
171172
- **Use Fast Search**: オートコンプリート候補の検索を高速な処理に切り替える(詳細は [オートコンプリートの高速検索について](#オートコンプリートの高速検索について) を確認してください)
172173

locales/en/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
"AutocompletePlus_Autocompletion_EnableModels": {
3232
"name": "Enable Loras and Embeddings"
3333
},
34+
"AutocompletePlus_Autocompletion_PrefixArtist": {
35+
"name": "String to add before artist tags",
36+
"tooltip": "Text to prepend when inserting an artist tag via autocomplete.\ne.g. '@' -> '@artist_name'."
37+
},
3438
"AutocompletePlus_Autocompletion_ReplaceUnderscoreWithSpace": {
3539
"name": "Replace '_' with 'Space'",
3640
"tooltip": "This setting also affects related tags display."

locales/ja/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
"AutocompletePlus_Autocompletion_EnableModels": {
3232
"name": "LoraとEmbeddingを候補に表示する"
3333
},
34+
"AutocompletePlus_Autocompletion_PrefixArtist": {
35+
"name": "アーティストタグの前に追加する文字列",
36+
"tooltip": "オートコンプリートからアーティストタグを挿入する際に付加する文字列。\n例: '@' -> '@artist_name'"
37+
},
3438
"AutocompletePlus_Autocompletion_ReplaceUnderscoreWithSpace": {
3539
"name": "'_' を 'スペース' に置き換える",
3640
"tooltip": "この設定は関連タグ表示にも影響します"

locales/zh-TW/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
"AutocompletePlus_Autocompletion_EnableModels": {
3232
"name": "顯示Lora和Embedding"
3333
},
34+
"AutocompletePlus_Autocompletion_PrefixArtist": {
35+
"name": "在藝術家標籤前添加的字串",
36+
"tooltip": "透過自動完成插入藝術家標籤時,在標籤前添加的文字。\n例: '@' -> '@artist_name'"
37+
},
3438
"AutocompletePlus_Autocompletion_ReplaceUnderscoreWithSpace": {
3539
"name": "將'_'替換為'空格'",
3640
"tooltip": "此設定也會影響相關標籤顯示"

locales/zh/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
"AutocompletePlus_Autocompletion_EnableModels": {
3232
"name": "显示Lora和Embedding"
3333
},
34+
"AutocompletePlus_Autocompletion_PrefixArtist": {
35+
"name": "在艺术家标签前添加的字符串",
36+
"tooltip": "通过自动完成插入艺术家标签时,在标签前添加的文本。\n例: '@' -> '@artist_name'"
37+
},
3438
"AutocompletePlus_Autocompletion_ReplaceUnderscoreWithSpace": {
3539
"name": "将'_'替换为'空格'",
3640
"tooltip": "此设置也会影响相关标签显示"

web/js/autocomplete.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,13 @@ function insertTagToTextArea(inputElement, tagDataToInsert) {
351351
const needsSpaceBefore = text[replaceStart - 1] === ',';
352352
const prefix = needsSpaceBefore ? ' ' : '';
353353

354+
const prefixArtist = tagDataToInsert.categoryText == 'artist' ? settingValues.prefixArtist : '';
355+
354356
// Standard separator (comma + space, or empty if autoInsertComma is disabled)
355357
const needsSuffixAfter = !",:".includes(text[replaceEnd]); // TODO: If ":" is part of the emoticon, a suffix is ​​required (e.g. ":o")
356358
const suffix = (needsSuffixAfter && settingValues.autoInsertComma) ? ', ' : '';
357359

358-
const textToInsertWithAffixes = prefix + normalizedTag + suffix;
360+
const textToInsertWithAffixes = prefix + prefixArtist + normalizedTag + suffix;
359361

360362
// --- Use execCommand for Undo support ---
361363
// 1. Select the text range to be replaced
@@ -939,6 +941,25 @@ export class AutocompleteEventHandler {
939941
constructor() {
940942
this.autocompleteUI = new AutocompleteUI();
941943
this.keyDownWithModifier = new Map(); // Keep track of keydown events with modifiers
944+
this._debounceTimer = null; // Timer ID for debounced search
945+
}
946+
947+
/**
948+
* Calls autocompleteUI.updateDisplay() with debounce for sequential search, or immediately for fast search.
949+
* @param {HTMLTextAreaElement} target
950+
*/
951+
_triggerUpdateDisplay(target) {
952+
if (settingValues.useFastSearch || settingValues.searchDebounceTime <= 0) {
953+
// FastSearch or debounce disabled: immediate update
954+
this.autocompleteUI.updateDisplay(target);
955+
} else {
956+
// Sequential search: debounced update
957+
clearTimeout(this._debounceTimer);
958+
this._debounceTimer = setTimeout(() => {
959+
this.autocompleteUI.updateDisplay(target);
960+
this._debounceTimer = null;
961+
}, settingValues.searchDebounceTime);
962+
}
942963
}
943964

944965
/**
@@ -952,6 +973,7 @@ export class AutocompleteEventHandler {
952973

953974
const partialTag = getCurrentPartialTag(event.target);
954975
if (partialTag.length <= 0) {
976+
clearTimeout(this._debounceTimer); // Cancel pending debounced search
955977
this.autocompleteUI.hide();
956978
}
957979
}
@@ -1062,7 +1084,7 @@ export class AutocompleteEventHandler {
10621084
// and default action is not prevented, update the display.
10631085
// This will typically be for character inputs, Delete, Backspace or IME composition.
10641086
if (!event.defaultPrevented) {
1065-
this.autocompleteUI.updateDisplay(event.target);
1087+
this._triggerUpdateDisplay(event.target);
10661088
}
10671089
}
10681090

web/js/main.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@ function initializeEventHandlers() {
5050
ComfyWidgets.STRING = function (node, inputName, inputData, appInstance) { // Use appInstance to avoid conflict with global app
5151
const result = originalStringWidget.apply(this, arguments);
5252

53-
// Check if the widget has an inputEl and if it's a TEXTAREA
53+
// Check if the widget has an element and if it's a TEXTAREA
5454
// This is to ensure we are targeting multiline text inputs, related to '.comfy-multiline-input'
55-
if (result && result.widget
56-
&& result.widget.inputEl && result.widget.inputEl.tagName === 'TEXTAREA' && !result.widget.inputEl.readOnly) {
57-
const widgetConfig = inputData && inputData[1] ? inputData[1] : {};
58-
// Future: Add checks for Autocomplete Plus specific configurations if needed
59-
// e.g., if (widgetConfig["AutocompletePlus.enabled"] === false) return result;
60-
61-
const nodeInfo = new NodeInfo(node.comfyClass || node.constructor.name, inputName);
62-
attachListeners(result.widget.inputEl, nodeInfo);
55+
if (result && result.widget) {
56+
// fallback for older Comfyui frontend versions
57+
const inputEl = result.widget.element ?? result.widget.inputEl;
58+
if (inputEl && inputEl.tagName === 'TEXTAREA' && !inputEl.readOnly) {
59+
const widgetConfig = inputData && inputData[1] ? inputData[1] : {};
60+
// Future: Add checks for Autocomplete Plus specific configurations if needed
61+
// e.g., if (widgetConfig["AutocompletePlus.enabled"] === false) return result;
62+
63+
const nodeInfo = new NodeInfo(node.comfyClass || node.constructor.name, inputName);
64+
attachListeners(inputEl, nodeInfo);
65+
}
6366
}
6467
return result;
6568
};
@@ -377,6 +380,17 @@ app.registerExtension({
377380
settingValues.enableModels = newVal;
378381
}
379382
},
383+
{
384+
id: id + ".Autocompletion.PrefixArtist",
385+
name: "String to add before artist tags",
386+
tooltip: "Text to prepend when inserting an artist tag via autocomplete.\ne.g. '@' -> '@artist_name'.",
387+
type: "text",
388+
defaultValue: '',
389+
category: [name, "Autocompletion", "String to add before artist tags"],
390+
onChange: (newVal, oldVal) => {
391+
settingValues.prefixArtist = newVal;
392+
}
393+
},
380394
{
381395
id: id + ".Autocompletion.ReplaceUnderscoreWithSpace",
382396
name: "Replace '_' with 'Space'",
@@ -535,4 +549,4 @@ app.registerExtension({
535549
},
536550
},
537551
]
538-
});
552+
});

web/js/settings.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export const settingValues = {
1010
enableModels: true, // Enable Lora and Embedding suggestions
1111
useFastSearch: false,
1212
replaceUnderscoreWithSpace: true, // Replace underscores with spaces in tag insertion
13+
prefixArtist: '', // Prefix to be attached before artist tags
1314
autoInsertComma: true,
15+
searchDebounceTime: 100, // Sequential search debounce time in milliseconds
1416

1517
// Related tags feature settings
1618
enableRelatedTags: true,

0 commit comments

Comments
 (0)