Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f84125262 | ||
|
|
906ba108cc | ||
|
|
6d54bbc7ca | ||
|
|
bda6f4fa9d | ||
|
|
2237b0cb52 | ||
|
|
6e23ad89b6 | ||
|
|
389a79cac9 | ||
|
|
1c4e081f9a | ||
|
|
9c57062011 | ||
|
|
38975c11ab | ||
|
|
8459e3dac9 | ||
|
|
e7eab66d8f | ||
|
|
26772ac8dd | ||
|
|
f68c0c7dc2 | ||
|
|
79fb35ff8c | ||
|
|
4f776d676a | ||
|
|
9f8078c408 | ||
|
|
ab2e83ec38 | ||
|
|
2715f1f165 | ||
|
|
56f506110d | ||
|
|
6785a2b6a5 | ||
|
|
e8b0e44cf4 | ||
|
|
4b64fae70d | ||
|
|
e622148b27 | ||
|
|
7a279d71c3 | ||
|
|
ee8b265173 | ||
|
|
80d254c6b4 | ||
|
|
8f6d451fef | ||
|
|
f2920add1d | ||
|
|
dbb5f66a1f | ||
|
|
cacee5ddad | ||
|
|
7f23b02812 | ||
|
|
edbea2bb43 | ||
|
|
70f916b825 | ||
|
|
42f5e73515 | ||
|
|
52e5d2fd5f | ||
|
|
397c90275f | ||
|
|
2c8877060c | ||
|
|
1203e2f0ef | ||
|
|
f2ff83088d | ||
|
|
d6f53ebb0f | ||
|
|
2552e8d746 | ||
|
|
96ba7d8055 |
@@ -13,6 +13,7 @@
|
||||
- **:zap:No setup required**: Automatically downloads CSV data optimized for Danbooru tags.
|
||||
- **:mag:Autocomplete**: Displays tag suggestions in real-time based on your input as you type.
|
||||
- **:file_cabinet:Related Tags Display**: Shows a list of tags highly related to the selected tag.
|
||||
- **:triangular_ruler:Auto Formatter**: Automatically formats prompt text when the textarea loses focus, cleaning up extra spaces and commas.
|
||||
- **:earth_asia:Multilingual Support**: Supports input completion in Japanese, Chinese, and Korean.
|
||||
- **:computer_mouse:Intuitive Operation**:
|
||||
- Supports both mouse and keyboard operations.
|
||||
@@ -55,6 +56,20 @@ When you select any tag in a text input area, a list of highly related tags is d
|
||||
- Tags that have already been entered are displayed grayed out. If you try to insert a grayed-out tag, the already entered tag will instead be selected.
|
||||
- You can display related tags for the cursor position by pressing `Ctrl+Shift+Space`.
|
||||
|
||||
## Auto Formatter
|
||||
|
||||
When a text input area loses focus (e.g., by clicking outside or pressing Tab), the prompt text is automatically formatted. This feature improves readability when editing large amounts of text.
|
||||
|
||||
Detailed behavior is as follows:
|
||||
- Automatically adds a comma and space after each tag for proper separation
|
||||
- Removes extra commas and spaces between tags
|
||||
- You can manually trigger formatting using the keyboard shortcut `Alt+Shift+F` (keybinding can be customized in ComfyUI settings)
|
||||
- You can enable/disable this feature in the settings
|
||||
|
||||
> [!NOTE]
|
||||
> Auto-formatting is disabled for certain nodes to prevent errors.
|
||||
> Example: [Power Puter (rgthree)](https://github.com/rgthree/rgthree-comfy/wiki/Node:-Power-Puter) `code` field, [LoraLoaderBlockWeight (Inspire)](https://github.com/ltdrdata/ComfyUI-Inspire-Pack) `block_vector` field
|
||||
|
||||
## CSV Data
|
||||
|
||||
Two basic CSV data files are required for operation. These are managed on [HuggingFace](https://huggingface.co/datasets/newtextdoc1111/danbooru-tag-csv) and are automatically downloaded when ComfyUI is first launched after installation, so no setup is required.
|
||||
@@ -150,6 +165,7 @@ For example, by preparing the following CSV, you can quickly insert correspondin
|
||||
|
||||
- **Enable Autocomplete**: Enable/disable the autocomplete feature.
|
||||
- **Max suggestions**: Maximum number of autocomplete suggestions to display.
|
||||
- **Auto-Insert Comma**: Automatically insert a comma after tags when inserting from autocomplete.
|
||||
- **Replace '_' with 'Space'**: Replaces underscores with spaces when inserting tags. This setting also affects related tag display.
|
||||
- **Enable Loras and Embeddings**: Display Lora and Embedding in the suggestions.
|
||||
- **Use Fast Search**: Switch autocomplete suggestions search to fast processing (see [About Fast Search for Autocomplete](#about-fast-search-for-autocomplete) for details).
|
||||
@@ -159,12 +175,19 @@ For example, by preparing the following CSV, you can quickly insert correspondin
|
||||
- **Enable Related Tags**: Enable/disable the related tags feature.
|
||||
- **Max related tags**: Maximum number of related tags to display.
|
||||
- **Default Display Position**: Default display position when ComfyUI starts.
|
||||
- **Related Tags Trigger Mode**: Which action will trigger displaying related tags (click only, Ctrl+click)
|
||||
- **Related Tags Trigger Mode**: Which action will trigger displaying related tags for the entered tag (click only, Ctrl+click)
|
||||
|
||||
### Display
|
||||
|
||||
- **Hide Alias**: Hide/show the Alias column in autocomplete and related tags (default is show)
|
||||
|
||||
### Auto Formatter
|
||||
|
||||
- **Enable Auto Format**: Enable/disable the automatically format prompt text when the textarea loses focus.
|
||||
- **Auto Format Trigger**: Choose when formatting is applied.
|
||||
- **Auto**: Format automatically when leaving text field
|
||||
- **Manual**: Format only via keyboard shortcut (default: `Alt+Shift+F`)
|
||||
|
||||
## Advanced Settings
|
||||
|
||||
### Disabling CSV Update Check on Startup
|
||||
|
||||
+24
-1
@@ -11,6 +11,7 @@
|
||||
- **:zap:セットアップ不要**: Danbooruタグに最適化された CSV データを自動でダウンロード
|
||||
- **:mag:オートコンプリート**: テキスト入力中に、入力内容に基づいてタグ候補をリアルタイムで表示
|
||||
- **:file_cabinet:関連タグ表示機能**: 選択したタグと関連性の高いタグを一覧表示
|
||||
- **:triangular_ruler:自動フォーマット**: テキストエリアがフォーカスを失った際に、プロンプトテキストを自動的にフォーマットし、余分なスペースやカンマを整理
|
||||
- **:earth_asia:多言語対応**: 日本語、中国語、韓国語での入力補完をサポート
|
||||
- **:computer_mouse:直感的な操作**:
|
||||
- マウスとキーボードどちらの操作にも対応
|
||||
@@ -53,6 +54,20 @@
|
||||
- 入力済みのタグはグレーアウトで表示されます。グレーアウトしたタグを挿入しようとした場合、代わりに入力済みのタグを選択状態にします
|
||||
- `Ctrl+Shift+Space` キーでカーソル位置の関連タグを表示できます
|
||||
|
||||
## 自動フォーマット
|
||||
|
||||
テキスト入力エリアがフォーカスを失った際(例:外側をクリック、Tabキーを押す)、プロンプトテキストを自動的にフォーマットする機能です。大量のテキストを編集する際に可読性を向上させる事が出来ます。
|
||||
|
||||
詳細な動作は以下になります:
|
||||
- 各タグの後に自動的にカンマとスペースを追加し、適切に区切ります
|
||||
- タグ間の余分なカンマとスペースを削除します
|
||||
- キーボードショートカット `Alt+Shift+F` を使って手動でフォーマットすることも出来ます(キーバインドはComfyUIの設定から変更可能です)
|
||||
- 設定から機能の有効化/無効化を切り替えられます
|
||||
|
||||
> [!NOTE]
|
||||
> 一部のノードはエラーに繋がるため、自動フォーマットは実行されません。
|
||||
> 例: [Power Puter (rgthree)](https://github.com/rgthree/rgthree-comfy/wiki/Node:-Power-Puter) の `code` フィールド、 [LoraLoaderBlockWeight (Inspire)](https://github.com/ltdrdata/ComfyUI-Inspire-Pack) の `block_vector` フィールド
|
||||
|
||||
## CSV データ
|
||||
|
||||
動作には基本となる CSV データが2つ必要です。これらは [HuggingFace](https://huggingface.co/datasets/newtextdoc1111/danbooru-tag-csv) で管理されており、 ComfyUI にインストール後の初回起動時に自動でダウンロードされるのでセットアップは不要です。
|
||||
@@ -148,6 +163,7 @@ worst_quality,5,9999999,
|
||||
|
||||
- **Enable Autocomplete**: オートコンプリート機能の有効化/無効化
|
||||
- **Max Suggestions**: オートコンプリート候補の最大表示件数
|
||||
- **Auto-Insert Comma**: タグの挿入時、末尾にカンマを追加する
|
||||
- **Replace '_' with 'Space'**: タグ挿入時にアンダースコアをスペースに置き換えます。この設定は関連タグ表示にも影響します
|
||||
- **Enable Loras and Embeddings**: LoraとEmbeddingを候補に表示する
|
||||
- **Use Fast Search**: オートコンプリート候補の検索を高速な処理に切り替える(詳細は [オートコンプリートの高速検索について](#オートコンプリートの高速検索について) を確認してください)
|
||||
@@ -157,12 +173,19 @@ worst_quality,5,9999999,
|
||||
- **Enable Related Tags**: 関連タグ機能の有効化/無効化
|
||||
- **Max related tags**: 関連タグの最大表示件数
|
||||
- **Default Display Position**: ComfyUI起動時のデフォルト表示位置
|
||||
- **Related Tags Trigger Mode** : 関連タグを表示する際、どの操作をトリガーとするか(クリックのみ、Ctrl+クリック)
|
||||
- **Related Tags Trigger Mode** : 入力済みのタグの関連タグを表示する際、どの操作をトリガーとするか(クリックのみ、Ctrl+クリック)
|
||||
|
||||
### 表示
|
||||
|
||||
- **Hide Alias**: オートコンプリートと関連タグで表示されるエイリアス列の非表示/表示を切り替え(デフォルトは表示です)
|
||||
|
||||
### 自動フォーマット
|
||||
|
||||
- **Enable Auto Format**: テキストエリアがフォーカスを失った際にプロンプトテキストを自動的にフォーマットする機能の有効化/無効化
|
||||
- **Auto Format Trigger**: フォーマットを適用するタイミングを選択します
|
||||
- **自動**: テキスト欄からフォーカスが外れた際に自動でフォーマットします
|
||||
- **手動**: キーボードショートカットでのみフォーマットします(デフォルト: `Alt+Shift+F`)
|
||||
|
||||
## 上級者向け設定
|
||||
|
||||
### 起動時のCSV更新チェックを無効化する
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"settingsCategories": {
|
||||
"Autocomplete Plus": "Autocomplete Plus",
|
||||
"Tag Source": "Tag Source",
|
||||
"Autocompletion": "Autocompletion",
|
||||
"Related Tags": "Related Tags",
|
||||
"Display": "Display",
|
||||
"AutoFormatter": "AutoFormatter"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"AutocompletePlus_TagSource_IconPosition": {
|
||||
"name": "Tag Source Icon Position",
|
||||
"options": {
|
||||
"left": "Left",
|
||||
"right": "Right",
|
||||
"hidden": "Hidden"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_TagSource_PrimaryTagSource": {
|
||||
"name": "Primary source for 'all' Source",
|
||||
"tooltip": "When 'Autocomplete Tag Source' is 'all', this determines which source's tags appear first in suggestions.",
|
||||
"options": {
|
||||
"danbooru": "Danbooru",
|
||||
"e621": "e621"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_TagSource": {
|
||||
"name": "Autocomplete Tag Source",
|
||||
"tooltip": "Select the tag source for autocomplete suggestions. 'all' includes tags from all loaded sources.",
|
||||
"options": {
|
||||
"danbooru": "Danbooru",
|
||||
"e621": "e621",
|
||||
"all": "all"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_UseFastSearch": {
|
||||
"name": "Use Fast Search",
|
||||
"tooltip": "Tag search processing during text input operates faster, improving responsiveness."
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_EnableModels": {
|
||||
"name": "Enable Loras and Embeddings"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_ReplaceUnderscoreWithSpace": {
|
||||
"name": "Replace '_' with 'Space'",
|
||||
"tooltip": "This setting also affects related tags display."
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_AutoInsertComma": {
|
||||
"name": "Auto-Insert Comma",
|
||||
"tooltip": "Automatically insert a comma after tags when inserting from autocomplete."
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_MaxSuggestions": {
|
||||
"name": "Max suggestions"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_Enable": {
|
||||
"name": "Enable Autocomplete"
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_RelatedTagsTriggerMode": {
|
||||
"name": "Related Tags Trigger Mode",
|
||||
"tooltip": "Which action will trigger displaying related tags for the entered tag (click only, Ctrl+click).",
|
||||
"options": {
|
||||
"click": "Click",
|
||||
"ctrl+Click": "Ctrl+Click"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_DisplayPosition": {
|
||||
"name": "Default Display Position",
|
||||
"tooltip": "Display position (relative to Textarea).",
|
||||
"options": {
|
||||
"horizontal": "Horizontal",
|
||||
"vertical": "Vertical"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_MaxRelatedTags": {
|
||||
"name": "Max related tags"
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_Enable": {
|
||||
"name": "Enable Related Tags"
|
||||
},
|
||||
"AutocompletePlus_Display_HideAlias": {
|
||||
"name": "Hide Alias",
|
||||
"tooltip": "Hide alias column in the autocomplete and related tags display."
|
||||
},
|
||||
"AutocompletePlus_AutoFormatter_Trigger": {
|
||||
"name": "Auto Format Trigger",
|
||||
"tooltip": "Auto: Format automatically when leaving text field.\nManual: Format only via keyboard shortcut. default keybind: (Alt+Shift+F)",
|
||||
"options": {
|
||||
"auto": "Auto",
|
||||
"manual": "Manual"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_AutoFormatter_EnableAutoFormat": {
|
||||
"name": "Enable Auto Format"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"settingsCategories": {
|
||||
"Autocomplete Plus": "Autocomplete Plus",
|
||||
"Tag Source": "タグソース",
|
||||
"Autocompletion": "オートコンプリート",
|
||||
"Related Tags": "関連タグ",
|
||||
"Display": "表示",
|
||||
"AutoFormatter": "自動フォーマット"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"AutocompletePlus_TagSource_IconPosition": {
|
||||
"name": "タグソースのアイコン位置",
|
||||
"options": {
|
||||
"left": "左",
|
||||
"right": "右",
|
||||
"hidden": "非表示"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_TagSource_PrimaryTagSource": {
|
||||
"name": "優先して表示するタグソース",
|
||||
"tooltip": "オートコンプリートのタグソースが「全て」のとき、ここで指定したタグソースが優先して表示されます",
|
||||
"options": {
|
||||
"danbooru": "Danbooru",
|
||||
"e621": "e621"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_TagSource": {
|
||||
"name": "オートコンプリートのタグソース",
|
||||
"tooltip": "オートコンプリート候補に表示するタグソース。\n「全て」を選択するとロード済みの全てのタグソースを表示します",
|
||||
"options": {
|
||||
"danbooru": "Danbooru",
|
||||
"e621": "e621",
|
||||
"all": "全て"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_UseFastSearch": {
|
||||
"name": "高速検索の有効化",
|
||||
"tooltip": "候補の検索を高速な処理に切り替えます。\n入力時の遅延が改善される場合があります"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_EnableModels": {
|
||||
"name": "LoraとEmbeddingを候補に表示する"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_ReplaceUnderscoreWithSpace": {
|
||||
"name": "'_' を 'スペース' に置き換える",
|
||||
"tooltip": "この設定は関連タグ表示にも影響します"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_AutoInsertComma": {
|
||||
"name": "カンマを自動で追加する",
|
||||
"tooltip": "オートコンプリート確定時、タグの末尾に自動でカンマを追加する"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_MaxSuggestions": {
|
||||
"name": "候補の最大表示件数"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_Enable": {
|
||||
"name": "オートコンプリート機能の有効化"
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_RelatedTagsTriggerMode": {
|
||||
"name": "関連タグを表示する操作",
|
||||
"tooltip": "入力済みのタグの関連タグを表示する際、どの操作をトリガーとするか(クリックのみ、Ctrl+クリック)",
|
||||
"options": {
|
||||
"click": "クリック",
|
||||
"ctrl+Click": "Ctrl+クリック"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_DisplayPosition": {
|
||||
"name": "デフォルト表示位置",
|
||||
"tooltip": "入力中のテキストエリアを基準に、どの位置に表示するか",
|
||||
"options": {
|
||||
"horizontal": "水平",
|
||||
"vertical": "垂直"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_MaxRelatedTags": {
|
||||
"name": "関連タグの最大表示件数"
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_Enable": {
|
||||
"name": "関連タグ機能の有効化"
|
||||
},
|
||||
"AutocompletePlus_Display_HideAlias": {
|
||||
"name": "エイリアスを非表示",
|
||||
"tooltip": "オートコンプリートと関連タグで表示されるエイリアス列を非表示にします"
|
||||
},
|
||||
"AutocompletePlus_AutoFormatter_Trigger": {
|
||||
"name": "自動フォーマットのトリガー",
|
||||
"tooltip": "自動: テキスト欄からフォーカスが外れた際に自動でフォーマットします\n手動: キーボードショートカットでのみフォーマットします。デフォルトのキーバインド: (Alt+Shift+F)",
|
||||
"options": {
|
||||
"auto": "自動",
|
||||
"manual": "手動"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_AutoFormatter_EnableAutoFormat": {
|
||||
"name": "自動フォーマット機能の有効化"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"settingsCategories": {
|
||||
"Autocomplete Plus": "Autocomplete Plus",
|
||||
"Tag Source": "標籤來源",
|
||||
"Autocompletion": "自動完成",
|
||||
"Related Tags": "相關標籤",
|
||||
"Display": "顯示",
|
||||
"AutoFormatter": "自動格式化"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"AutocompletePlus_TagSource_IconPosition": {
|
||||
"name": "標籤來源圖示位置",
|
||||
"options": {
|
||||
"left": "左",
|
||||
"right": "右",
|
||||
"hidden": "隱藏"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_TagSource_PrimaryTagSource": {
|
||||
"name": "「全部」選擇時的主要來源",
|
||||
"tooltip": "當自動完成標籤來源為「全部」時,此設定決定哪個來源的標籤優先顯示在建議中。",
|
||||
"options": {
|
||||
"danbooru": "Danbooru",
|
||||
"e621": "e621"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_TagSource": {
|
||||
"name": "自動完成標籤來源",
|
||||
"tooltip": "選擇自動完成建議的標籤來源。選擇「全部」將包含所有已載入來源的標籤。",
|
||||
"options": {
|
||||
"danbooru": "Danbooru",
|
||||
"e621": "e621",
|
||||
"all": "全部"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_UseFastSearch": {
|
||||
"name": "啟用快速搜尋",
|
||||
"tooltip": "標籤搜尋處理更快,提高文字輸入時的回應速度"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_EnableModels": {
|
||||
"name": "顯示Lora和Embedding"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_ReplaceUnderscoreWithSpace": {
|
||||
"name": "將'_'替換為'空格'",
|
||||
"tooltip": "此設定也會影響相關標籤顯示"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_AutoInsertComma": {
|
||||
"name": "自動插入逗號",
|
||||
"tooltip": "從自動完成插入標籤時自動在標籤後添加逗號"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_MaxSuggestions": {
|
||||
"name": "最大提示數"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_Enable": {
|
||||
"name": "啟用自動完成"
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_RelatedTagsTriggerMode": {
|
||||
"name": "顯示相關標籤的操作",
|
||||
"tooltip": "指定觸發顯示已輸入標籤的相關標籤的操作(僅點擊、Ctrl+點擊)",
|
||||
"options": {
|
||||
"click": "點擊",
|
||||
"ctrl+Click": "Ctrl+點擊"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_DisplayPosition": {
|
||||
"name": "預設顯示位置",
|
||||
"tooltip": "相對於文字區域的顯示位置",
|
||||
"options": {
|
||||
"horizontal": "水平",
|
||||
"vertical": "垂直"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_MaxRelatedTags": {
|
||||
"name": "最大相關標籤數"
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_Enable": {
|
||||
"name": "啟用相關標籤"
|
||||
},
|
||||
"AutocompletePlus_Display_HideAlias": {
|
||||
"name": "隱藏別名",
|
||||
"tooltip": "隱藏自動完成和相關標籤顯示中的別名欄"
|
||||
},
|
||||
"AutocompletePlus_AutoFormatter_Trigger": {
|
||||
"name": "自動格式化觸發方式",
|
||||
"tooltip": "自動: 離開文字方塊時自動格式化\n手動: 僅透過鍵盤快速鍵格式化。預設快速鍵: (Alt+Shift+F)",
|
||||
"options": {
|
||||
"auto": "自動",
|
||||
"manual": "手動"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_AutoFormatter_EnableAutoFormat": {
|
||||
"name": "啟用自動格式化"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"settingsCategories": {
|
||||
"Autocomplete Plus": "Autocomplete Plus",
|
||||
"Tag Source": "标签来源",
|
||||
"Autocompletion": "自动完成",
|
||||
"Related Tags": "相关标签",
|
||||
"Display": "显示",
|
||||
"AutoFormatter": "自动格式化"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"AutocompletePlus_TagSource_IconPosition": {
|
||||
"name": "标签来源图标位置",
|
||||
"options": {
|
||||
"left": "左",
|
||||
"right": "右",
|
||||
"hidden": "隐藏"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_TagSource_PrimaryTagSource": {
|
||||
"name": "'全部'选择时的主要来源",
|
||||
"tooltip": "当自动完成标签来源为\"全部\"时,此设置决定哪个来源的标签优先显示在建议中。",
|
||||
"options": {
|
||||
"danbooru": "Danbooru",
|
||||
"e621": "e621"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_TagSource": {
|
||||
"name": "自动完成标签来源",
|
||||
"tooltip": "选择自动完成建议的标签来源。选择\"全部\"将包含所有已加载来源的标签。",
|
||||
"options": {
|
||||
"danbooru": "Danbooru",
|
||||
"e621": "e621",
|
||||
"all": "全部"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_UseFastSearch": {
|
||||
"name": "启用快速搜索",
|
||||
"tooltip": "标签搜索处理更快,提高文本输入时的响应速度"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_EnableModels": {
|
||||
"name": "显示Lora和Embedding"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_ReplaceUnderscoreWithSpace": {
|
||||
"name": "将'_'替换为'空格'",
|
||||
"tooltip": "此设置也会影响相关标签显示"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_AutoInsertComma": {
|
||||
"name": "自动插入逗号",
|
||||
"tooltip": "从自动完成插入标签时自动在标签后添加逗号"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_MaxSuggestions": {
|
||||
"name": "最大提示数"
|
||||
},
|
||||
"AutocompletePlus_Autocompletion_Enable": {
|
||||
"name": "启用自动完成"
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_RelatedTagsTriggerMode": {
|
||||
"name": "显示相关标签的操作",
|
||||
"tooltip": "指定触发显示已输入标签的相关标签的操作(仅点击、Ctrl+点击)",
|
||||
"options": {
|
||||
"click": "点击",
|
||||
"ctrl+Click": "Ctrl+点击"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_DisplayPosition": {
|
||||
"name": "默认显示位置",
|
||||
"tooltip": "相对于文本区域的显示位置",
|
||||
"options": {
|
||||
"horizontal": "水平",
|
||||
"vertical": "垂直"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_MaxRelatedTags": {
|
||||
"name": "最大相关标签数"
|
||||
},
|
||||
"AutocompletePlus_RelatedTags_Enable": {
|
||||
"name": "启用相关标签"
|
||||
},
|
||||
"AutocompletePlus_Display_HideAlias": {
|
||||
"name": "隐藏别名",
|
||||
"tooltip": "隐藏自动完成和相关标签显示中的别名列"
|
||||
},
|
||||
"AutocompletePlus_AutoFormatter_Trigger": {
|
||||
"name": "自动格式化触发方式",
|
||||
"tooltip": "自动: 离开文本框时自动格式化\n手动: 仅通过键盘快捷键格式化。默认快捷键: (Alt+Shift+F)",
|
||||
"options": {
|
||||
"auto": "自动",
|
||||
"manual": "手动"
|
||||
}
|
||||
},
|
||||
"AutocompletePlus_AutoFormatter_EnableAutoFormat": {
|
||||
"name": "启用自动格式化"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "comfyui-autocomplete-plus"
|
||||
description = "Autocomplete and Related Tag display for ComfyUI"
|
||||
version = "1.6.1"
|
||||
version = "1.8.0"
|
||||
license = {file = "LICENSE"}
|
||||
dependencies = ["",]
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import {
|
||||
formatPromptText,
|
||||
__test__
|
||||
} from "../../web/js/auto-formatter.js";
|
||||
|
||||
const {
|
||||
shouldAutoFormat
|
||||
} = __test__;
|
||||
|
||||
describe('AutoFormatter Functions', () => {
|
||||
|
||||
describe('shouldAutoFormat', () => {
|
||||
const mockNodeInfo = (nodeType, inputName) => ({
|
||||
nodeType,
|
||||
inputName
|
||||
});
|
||||
|
||||
test('should return false for empty text', () => {
|
||||
expect(shouldAutoFormat('', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
|
||||
expect(shouldAutoFormat(' ', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
|
||||
});
|
||||
|
||||
test('should return false for blocklisted nodes', () => {
|
||||
expect(shouldAutoFormat('some text,', mockNodeInfo('Power Puter (rgthree)', 'code'))).toBe(false);
|
||||
expect(shouldAutoFormat('some text,', mockNodeInfo('LoraLoaderBlockWeight //Inspire', 'block_vector'))).toBe(false);
|
||||
});
|
||||
|
||||
test('should return false for numeric data or single-letter placeholders', () => {
|
||||
expect(shouldAutoFormat('0,0,0,1,1,1', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
|
||||
expect(shouldAutoFormat('0.5, -1.2, 0.8', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
|
||||
expect(shouldAutoFormat('A,B,R', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
|
||||
expect(shouldAutoFormat('X, 1.5, Y', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
|
||||
});
|
||||
|
||||
test('should return true for text with "word + comma" pattern', () => {
|
||||
expect(shouldAutoFormat('1girl, blue hair,', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(true);
|
||||
expect(shouldAutoFormat('tag1, tag2', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false if "word + comma" pattern is not found', () => {
|
||||
expect(shouldAutoFormat('hello world', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
|
||||
expect(shouldAutoFormat('tag1 tag2', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatPromptText', () => {
|
||||
test('should format text by adding comma and space after tags', () => {
|
||||
const input = 'tag1,tag2,tag3';
|
||||
const expected = 'tag1, tag2, tag3, ';
|
||||
expect(formatPromptText(input)).toBe(expected);
|
||||
});
|
||||
|
||||
test('should remove extra spaces around tags', () => {
|
||||
const input = ' tag1 , tag2 ';
|
||||
const expected = 'tag1, tag2, ';
|
||||
expect(formatPromptText(input)).toBe(expected);
|
||||
});
|
||||
|
||||
test('should preserve special syntax like weights', () => {
|
||||
const input = '(tag1:1.2), [tag2]';
|
||||
// Note: The current implementation splits by comma.
|
||||
// If the input is "(tag1:1.2), [tag2]", it splits into "(tag1:1.2)" and "[tag2]".
|
||||
// Then joins with ", ".
|
||||
const expected = '(tag1:1.2), [tag2], ';
|
||||
expect(formatPromptText(input)).toBe(expected);
|
||||
});
|
||||
|
||||
test('should handle multiple lines', () => {
|
||||
const input = 'tag1, tag2\ntag3, tag4';
|
||||
const expected = 'tag1, tag2, \ntag3, tag4, ';
|
||||
expect(formatPromptText(input)).toBe(expected);
|
||||
});
|
||||
|
||||
test('should keep empty lines unchanged', () => {
|
||||
const input = 'tag1, tag2\n\ntag3, tag4';
|
||||
const expected = 'tag1, tag2, \n\ntag3, tag4, ';
|
||||
expect(formatPromptText(input)).toBe(expected);
|
||||
});
|
||||
|
||||
test('should handle empty input', () => {
|
||||
expect(formatPromptText('')).toBe('');
|
||||
expect(formatPromptText(null)).toBe(null);
|
||||
expect(formatPromptText(undefined)).toBe(undefined);
|
||||
});
|
||||
|
||||
test('should handle input with only spaces', () => {
|
||||
expect(formatPromptText(' ')).toBe(' ');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -353,7 +353,18 @@ describe('Autocomplete Functions', () => {
|
||||
insertTagToTextArea(textarea, tagData);
|
||||
}).not.toThrow();
|
||||
|
||||
expect(textarea.value).toBe('<lora:my_model>, ');
|
||||
expect(textarea.value).toBe('<lora:my_model:1.0>, ');
|
||||
});
|
||||
|
||||
test('should complete embedding tag without adding weight', () => {
|
||||
const textarea = createMockTextarea('embedding:', 10);
|
||||
const tagData = { tag: 'embedding:my_embedding', source: 'embeddings' };
|
||||
|
||||
expect(() => {
|
||||
insertTagToTextArea(textarea, tagData);
|
||||
}).not.toThrow();
|
||||
|
||||
expect(textarea.value).toBe('embedding:my_embedding, ');
|
||||
});
|
||||
|
||||
test('should handle wildcard tag insertion', () => {
|
||||
|
||||
+100
-1
@@ -4,7 +4,8 @@ import {
|
||||
normalizeTagToSearch,
|
||||
normalizeTagToInsert,
|
||||
getCurrentTagRange,
|
||||
findAllTagPositions
|
||||
findAllTagPositions,
|
||||
addWeightToLora
|
||||
} from '../../web/js/utils.js';
|
||||
|
||||
// filepath: web/js/utils.test.js
|
||||
@@ -440,3 +441,101 @@ describe('findAllTagPositions', () => {
|
||||
expect(positions[5].tag).toBe('last');
|
||||
});
|
||||
});
|
||||
|
||||
describe('addWeightToModel', () => {
|
||||
test('should return null or empty string for invalid inputs', () => {
|
||||
expect(addWeightToLora(null)).toBeNull();
|
||||
expect(addWeightToLora(undefined)).toBeUndefined();
|
||||
expect(addWeightToLora('')).toBe('');
|
||||
});
|
||||
|
||||
// LoRA format tests
|
||||
test('should add default weight to LoRA without weight', () => {
|
||||
expect(addWeightToLora('<lora:my_style01>')).toBe('<lora:my_style01:1.0>');
|
||||
expect(addWeightToLora('<lora:anime_style>')).toBe('<lora:anime_style:1.0>');
|
||||
expect(addWeightToLora('<lora:character_lora>')).toBe('<lora:character_lora:1.0>');
|
||||
});
|
||||
|
||||
test('should preserve existing weight in LoRA', () => {
|
||||
expect(addWeightToLora('<lora:my_style01:0.8>')).toBe('<lora:my_style01:0.8>');
|
||||
expect(addWeightToLora('<lora:anime_style:1.2>')).toBe('<lora:anime_style:1.2>');
|
||||
expect(addWeightToLora('<lora:character_lora:0.5>')).toBe('<lora:character_lora:0.5>');
|
||||
});
|
||||
|
||||
test('should handle LoRA with path separators', () => {
|
||||
expect(addWeightToLora('<lora:folder/my_style01>')).toBe('<lora:folder/my_style01:1.0>');
|
||||
expect(addWeightToLora('<lora:folder/subfolder/style>')).toBe('<lora:folder/subfolder/style:1.0>');
|
||||
expect(addWeightToLora('<lora:folder/my_style01:0.7>')).toBe('<lora:folder/my_style01:0.7>');
|
||||
});
|
||||
|
||||
test('should handle LoRA with symbols', () => {
|
||||
expect(addWeightToLora('<lora:folder/myLora style>')).toBe('<lora:folder/myLora style:1.0>');
|
||||
expect(addWeightToLora('<lora:folder/myLora-style>')).toBe('<lora:folder/myLora-style:1.0>');
|
||||
expect(addWeightToLora('<lora:folder/myLora[style]>')).toBe('<lora:folder/myLora[style]:1.0>');
|
||||
expect(addWeightToLora('<lora:folder/myLora v1.0>')).toBe('<lora:folder/myLora v1.0:1.0>');
|
||||
expect(addWeightToLora('<lora:folder/myLora v1.0:0.75>')).toBe('<lora:folder/myLora v1.0:0.75>');
|
||||
});
|
||||
|
||||
test('should handle case-insensitive LoRA tags', () => {
|
||||
expect(addWeightToLora('<LORA:my_style01>')).toBe('<LORA:my_style01:1.0>');
|
||||
expect(addWeightToLora('<LoRa:anime_style>')).toBe('<LoRa:anime_style:1.0>');
|
||||
expect(addWeightToLora('<Lora:character_lora:0.9>')).toBe('<Lora:character_lora:0.9>');
|
||||
});
|
||||
|
||||
// Custom default weight tests
|
||||
test('should use custom default weight for LoRA', () => {
|
||||
expect(addWeightToLora('<lora:my_style01>', 0.5)).toBe('<lora:my_style01:0.5>');
|
||||
expect(addWeightToLora('<lora:anime_style>', 1.5)).toBe('<lora:anime_style:1.5>');
|
||||
expect(addWeightToLora('<lora:character_lora>', 2.0)).toBe('<lora:character_lora:2.0>');
|
||||
});
|
||||
|
||||
test('should not override existing weight even with custom default', () => {
|
||||
expect(addWeightToLora('<lora:my_style01:0.8>', 2.0)).toBe('<lora:my_style01:0.8>');
|
||||
});
|
||||
|
||||
// Non-model format tests
|
||||
test('should return non-model tags as-is', () => {
|
||||
expect(addWeightToLora('blue_hair')).toBe('blue_hair');
|
||||
expect(addWeightToLora('1girl')).toBe('1girl');
|
||||
expect(addWeightToLora('standing:1.2')).toBe('standing:1.2');
|
||||
expect(addWeightToLora('<other:tag>')).toBe('<other:tag>');
|
||||
expect(addWeightToLora('random:text:format')).toBe('random:text:format');
|
||||
});
|
||||
|
||||
// Edge cases
|
||||
test('should handle malformed LoRA tags', () => {
|
||||
expect(addWeightToLora('<lora:>')).toBe('<lora:>');
|
||||
expect(addWeightToLora('<lora>')).toBe('<lora>');
|
||||
expect(addWeightToLora('lora:my_style01')).toBe('lora:my_style01');
|
||||
});
|
||||
|
||||
test('should handle decimal weights correctly', () => {
|
||||
expect(addWeightToLora('<lora:style:0.123>')).toBe('<lora:style:0.123>');
|
||||
expect(addWeightToLora('<lora:style:1.999>')).toBe('<lora:style:1.999>');
|
||||
});
|
||||
|
||||
test('should handle special characters in model names', () => {
|
||||
expect(addWeightToLora('<lora:my-style_01>')).toBe('<lora:my-style_01:1.0>');
|
||||
expect(addWeightToLora('<lora:style.v2>')).toBe('<lora:style.v2:1.0>');
|
||||
});
|
||||
|
||||
// Embedding format tests - should not be modified
|
||||
test('should not modify embedding tags without weight', () => {
|
||||
expect(addWeightToLora('embedding:my_embedding')).toBe('embedding:my_embedding');
|
||||
expect(addWeightToLora('embedding:character_emb')).toBe('embedding:character_emb');
|
||||
expect(addWeightToLora('embedding:style_embedding')).toBe('embedding:style_embedding');
|
||||
});
|
||||
|
||||
test('should not modify embedding tags with existing weight', () => {
|
||||
expect(addWeightToLora('embedding:my_embedding:0.8')).toBe('embedding:my_embedding:0.8');
|
||||
expect(addWeightToLora('embedding:character_emb:1.2')).toBe('embedding:character_emb:1.2');
|
||||
expect(addWeightToLora('embedding:style_embedding:0.5')).toBe('embedding:style_embedding:0.5');
|
||||
});
|
||||
|
||||
test('should not modify embedding tags regardless of case', () => {
|
||||
expect(addWeightToLora('EMBEDDING:my_embedding')).toBe('EMBEDDING:my_embedding');
|
||||
expect(addWeightToLora('Embedding:character_emb')).toBe('Embedding:character_emb');
|
||||
expect(addWeightToLora('EmBeDdInG:style_emb')).toBe('EmBeDdInG:style_emb');
|
||||
expect(addWeightToLora('EMBEDDING:my_embedding:0.9')).toBe('EMBEDDING:my_embedding:0.9');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
import { settingValues } from './settings.js';
|
||||
import { NodeInfo } from './node-info.js';
|
||||
|
||||
|
||||
/**
|
||||
* Determines if the text content should be auto-formatted.
|
||||
*
|
||||
* Format conditions:
|
||||
* 1. Skip formatting if node is in blocklist
|
||||
* 2. Skip formatting if text contains only numbers or single letters (separated by commas)
|
||||
* 3. Format if text contains "word + comma" pattern at least twice
|
||||
* 4. Otherwise, don't format
|
||||
*
|
||||
* @param {NodeInfo} nodeInfo - The node information.
|
||||
* @returns {boolean} - True if the text should be formatted, false otherwise.
|
||||
*/
|
||||
function shouldAutoFormat(text, nodeInfo) {
|
||||
if (!text || text.trim().length === 0) return false;
|
||||
|
||||
// 1. Check if the node name is in the blocklist
|
||||
const blocklist = [
|
||||
["Power Puter (rgthree)", "code"],
|
||||
["LoraLoaderBlockWeight //Inspire", "block_vector"]
|
||||
];
|
||||
|
||||
const isBlocklisted = blocklist.some(([type, input]) =>
|
||||
type === nodeInfo.nodeType && input === nodeInfo.inputName
|
||||
);
|
||||
|
||||
if (isBlocklisted) {
|
||||
// console.debug(`[Autocomplete-Plus] auto-formatter on blur => nodeType: ${nodeInfo.nodeType}, inputName: ${nodeInfo.inputName} => blocklisted`);
|
||||
return false;
|
||||
} else {
|
||||
// console.debug(`[Autocomplete-Plus] auto-formatter on blur => nodeType: ${nodeInfo.nodeType}, inputName: ${nodeInfo.inputName}`);
|
||||
}
|
||||
|
||||
|
||||
const trimmedText = text.trim();
|
||||
|
||||
// 2. Check if the text is purely numeric data or single-letter placeholders with commas
|
||||
// (e.g., "0,0,0,1,1,1" or "0.5, -1.2, 0.8" or "A,B,R" for LoRA Block Weight)
|
||||
const elements = trimmedText.split(',').map(el => el.trim());
|
||||
const isSingleLetterOrNumeric = elements.every(el => {
|
||||
if (/^[A-Za-z]$/.test(el)) return true;
|
||||
if (/^-?\d+(\.\d+)?$/.test(el)) return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
if (isSingleLetterOrNumeric && elements.length > 0) {
|
||||
return false; // Don't format numeric data or single-letter template patterns
|
||||
}
|
||||
|
||||
// 3. Check if the text contains the pattern "word + comma"
|
||||
const wordCommaPattern = /\w+\s*,/g;
|
||||
const matches = trimmedText.match(wordCommaPattern);
|
||||
|
||||
if (matches == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true; // Text should be formatted
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the prompt text: add a comma and space after each tag, and remove extra spaces.
|
||||
* Preserve special syntax such as weights (tag:1.2), parentheses, and wildcards.
|
||||
* @param {string} text - The original text.
|
||||
* @returns {string} - The formatted text.
|
||||
*/
|
||||
export function formatPromptText(text) {
|
||||
if (!text || text.trim().length === 0) return text;
|
||||
|
||||
// Split text into individual lines for processing
|
||||
const lines = text.split('\n');
|
||||
const formattedLines = [];
|
||||
|
||||
for (const line of lines) {
|
||||
const trimmedLine = line.trim();
|
||||
|
||||
// Keep empty lines unchanged
|
||||
if (trimmedLine.length === 0) {
|
||||
formattedLines.push('');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Split the line by commas into raw tag segments
|
||||
const rawTags = trimmedLine.split(',');
|
||||
|
||||
const cleanedTags = [];
|
||||
for (const tag of rawTags) {
|
||||
// Trim spaces around each tag
|
||||
const trimmedTag = tag.trim();
|
||||
|
||||
// Keep only non-empty tags
|
||||
if (trimmedTag.length > 0) {
|
||||
cleanedTags.push(trimmedTag);
|
||||
}
|
||||
}
|
||||
|
||||
// Rejoin cleaned tags with ", "
|
||||
let formattedLine = cleanedTags.join(', ');
|
||||
|
||||
// Add a trailing comma and space if the line contains valid tags
|
||||
if (formattedLine.length > 0) {
|
||||
formattedLine += ', ';
|
||||
}
|
||||
|
||||
formattedLines.push(formattedLine);
|
||||
}
|
||||
|
||||
// Rejoin all lines with newline characters
|
||||
return formattedLines.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the content of a textarea when it loses focus.
|
||||
* @param {HTMLTextAreaElement} textarea - The target textarea element.
|
||||
*/
|
||||
export function formatTextareaOnBlur(textarea) {
|
||||
const originalText = textarea.value;
|
||||
const formattedText = formatPromptText(originalText);
|
||||
|
||||
if (originalText !== formattedText) {
|
||||
const cursorPos = textarea.selectionStart;
|
||||
textarea.value = formattedText;
|
||||
|
||||
// Try to preserve cursor position
|
||||
const newCursorPos = Math.min(cursorPos, formattedText.length);
|
||||
textarea.setSelectionRange(newCursorPos, newCursorPos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for auto-formatting functionality
|
||||
*/
|
||||
export class AutoFormatterEventHandler {
|
||||
constructor() { }
|
||||
|
||||
/**
|
||||
* Handle blur event to trigger auto-formatting
|
||||
* @param {Event} event - The blur event
|
||||
*/
|
||||
handleBlur(event, nodeInfo) {
|
||||
if (
|
||||
settingValues.enableAutoFormat &&
|
||||
settingValues.autoFormatTrigger === 'auto' &&
|
||||
event.target.tagName === 'TEXTAREA'
|
||||
) {
|
||||
const textarea = event.target;
|
||||
const text = textarea.value;
|
||||
|
||||
// Check if the content should be auto-formatted
|
||||
if (shouldAutoFormat(text, nodeInfo)) {
|
||||
formatTextareaOnBlur(textarea);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Placeholder methods to maintain consistency with other event handlers
|
||||
handleInput(event) { }
|
||||
handleFocus(event) { }
|
||||
handleKeyDown(event) { }
|
||||
handleKeyUp(event) { }
|
||||
handleMouseMove(event) { }
|
||||
handleClick(event) { }
|
||||
|
||||
/**
|
||||
* Format textarea content via manual trigger (e.g., keyboard shortcut)
|
||||
* @param {HTMLTextAreaElement} textarea - The textarea element to format
|
||||
* @param {NodeInfo} nodeInfo - The node information
|
||||
* @returns {boolean} - True if formatting was performed, false otherwise
|
||||
*/
|
||||
applyFormatTextarea(textarea, nodeInfo) {
|
||||
if (!textarea || textarea.tagName !== 'TEXTAREA') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!settingValues.enableAutoFormat) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const text = textarea.value;
|
||||
|
||||
if (shouldAutoFormat(text, nodeInfo)) {
|
||||
formatTextareaOnBlur(textarea);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Export functions for testing
|
||||
const isTestEnvironment = typeof process !== 'undefined' && process.env.NODE_ENV === 'test';
|
||||
export const __test__ = isTestEnvironment
|
||||
? {
|
||||
shouldAutoFormat
|
||||
}
|
||||
: undefined;
|
||||
+21
-13
@@ -18,7 +18,8 @@ import {
|
||||
getCurrentTagRange,
|
||||
getViewportMargin,
|
||||
getScrollbarWidth,
|
||||
IconSvgHtmlString
|
||||
IconSvgHtmlString,
|
||||
addWeightToLora
|
||||
} from './utils.js';
|
||||
import { settingValues } from './settings.js';
|
||||
|
||||
@@ -305,7 +306,7 @@ function getCurrentPartialTag(inputElement) {
|
||||
* Inserts the selected tag into the textarea, replacing the partial tag,
|
||||
* making the change undoable.
|
||||
* @param {HTMLTextAreaElement} inputElement
|
||||
* @param {TagData} tagDataToInsert The raw tag string to insert.
|
||||
* @param {TagData} tagDataToInsert
|
||||
*/
|
||||
function insertTagToTextArea(inputElement, tagDataToInsert) {
|
||||
if (!inputElement || !tagDataToInsert) {
|
||||
@@ -331,8 +332,11 @@ function insertTagToTextArea(inputElement, tagDataToInsert) {
|
||||
let replaceEnd = cursorPos;
|
||||
|
||||
let normalizedTag;
|
||||
if (Object.values(ModelTagSource).includes(tagDataToInsert.source)) {
|
||||
// If the tag is from a model tag source, don't want to normalize it
|
||||
if (tagDataToInsert.source === ModelTagSource.Lora) {
|
||||
// If the tag is from a LoRA source, add weight to it
|
||||
normalizedTag = addWeightToLora(tagDataToInsert.tag);
|
||||
} else if (Object.values(ModelTagSource).includes(tagDataToInsert.source)) {
|
||||
// If the tag is from other model tag sources (e.g., Embeddings), don't normalize it
|
||||
normalizedTag = tagDataToInsert.tag;
|
||||
} else {
|
||||
normalizedTag = normalizeTagToInsert(tagDataToInsert.tag);
|
||||
@@ -347,9 +351,9 @@ function insertTagToTextArea(inputElement, tagDataToInsert) {
|
||||
const needsSpaceBefore = text[replaceStart - 1] === ',';
|
||||
const prefix = needsSpaceBefore ? ' ' : '';
|
||||
|
||||
// Standard separator (comma + space)
|
||||
// Standard separator (comma + space, or empty if autoInsertComma is disabled)
|
||||
const needsSuffixAfter = !",:".includes(text[replaceEnd]); // TODO: If ":" is part of the emoticon, a suffix is required (e.g. ":o")
|
||||
const suffix = needsSuffixAfter ? ', ' : '';
|
||||
const suffix = (needsSuffixAfter && settingValues.autoInsertComma) ? ', ' : '';
|
||||
|
||||
const textToInsertWithAffixes = prefix + normalizedTag + suffix;
|
||||
|
||||
@@ -404,8 +408,11 @@ class AutocompleteUI {
|
||||
// Add event listener for clicks on items
|
||||
this.tagsList.addEventListener('mousedown', (e) => {
|
||||
const row = e.target.closest('.autocomplete-plus-item');
|
||||
if (row && row.dataset.tag) {
|
||||
this.#insertTag(row.dataset);
|
||||
if (row && row.dataset.index !== undefined) {
|
||||
const tagData = this.candidates[parseInt(row.dataset.index, 10)];
|
||||
if (tagData) {
|
||||
this.#insertTag(tagData);
|
||||
}
|
||||
e.preventDefault(); // Prevent focus loss from input
|
||||
e.stopPropagation();
|
||||
}
|
||||
@@ -496,26 +503,27 @@ class AutocompleteUI {
|
||||
const existingTags = extractTagsFromTextArea(this.target);
|
||||
const currentTag = getCurrentPartialTag(this.target);
|
||||
|
||||
this.candidates.forEach((tagData) => {
|
||||
this.candidates.forEach((tagData, index) => {
|
||||
const isExactMatch = tagData.tag === currentTag && (existingTags.filter(item => item === currentTag).length == 1);
|
||||
const isExistingTag = !isExactMatch && existingTags.includes(tagData.tag);
|
||||
this.#createTagElement(tagData, isExistingTag);
|
||||
this.#createTagElement(tagData, index, isExistingTag);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a tag element for the autocomplete list.
|
||||
* @param {TagData} tagData
|
||||
* @param {number} tagDataIndex
|
||||
* @param {boolean} isExisting
|
||||
*/
|
||||
#createTagElement(tagData, isExisting) {
|
||||
#createTagElement(tagData, tagDataIndex, isExisting) {
|
||||
const categoryText = TagCategory[tagData.source][tagData.category] || "unknown";
|
||||
const aliasText = tagData.alias.join(', ');
|
||||
|
||||
const tagRow = document.createElement('div');
|
||||
tagRow.classList.add('autocomplete-plus-item', tagData.source);
|
||||
tagRow.dataset.tag = tagData.tag;
|
||||
tagRow.dataset.tagCategory = categoryText;
|
||||
tagRow.dataset.index = tagDataIndex;
|
||||
tagRow.dataset.tagCategory = categoryText; // Used to color by CSS
|
||||
|
||||
// Tag icon and name
|
||||
const tagSourceIconHtml = `<svg class="autocomplete-plus-tag-icon-svg"><use xlink:href="#autocomplete-plus-icon-${tagData.source}"></use></svg>`;
|
||||
|
||||
+141
-38
@@ -6,23 +6,27 @@ import { loadCSS } from "./utils.js";
|
||||
import { TagSource, loadDataAsync } from "./data.js";
|
||||
import { AutocompleteEventHandler } from "./autocomplete.js";
|
||||
import { RelatedTagsEventHandler } from "./related-tags.js";
|
||||
import { AutoFormatterEventHandler } from "./auto-formatter.js";
|
||||
import { NodeInfo } from "./node-info.js";
|
||||
|
||||
// --- Constants ---
|
||||
const id = "AutocompletePlus";
|
||||
const name = "Autocomplete Plus";
|
||||
|
||||
// --- Module-level variables ---
|
||||
const autocompleteEventHandler = new AutocompleteEventHandler();
|
||||
const relatedTagsEventHandler = new RelatedTagsEventHandler();
|
||||
const autoFormatterEventHandler = new AutoFormatterEventHandler();
|
||||
const attachedElementNodeInfoMap = new WeakMap(); // Map to track attached elements and their node info
|
||||
|
||||
// --- Functions ---
|
||||
/**
|
||||
* Initialize event handlers for the autocomplete and related tags features.
|
||||
*/
|
||||
function initializeEventHandlers() {
|
||||
const autocompleteEventHandler = new AutocompleteEventHandler();
|
||||
const relatedTagsEventHandler = new RelatedTagsEventHandler();
|
||||
const attachedElements = new WeakSet(); // Keep track of elements that have listeners attached
|
||||
|
||||
// Function to attach listeners
|
||||
function attachListeners(element) {
|
||||
if (attachedElements.has(element)) return; // Prevent double attachment
|
||||
function attachListeners(element, nodeInfo) {
|
||||
if (attachedElementNodeInfoMap.has(element)) return; // Prevent double attachment
|
||||
|
||||
element.addEventListener('input', handleInput);
|
||||
element.addEventListener('focus', handleFocus);
|
||||
@@ -35,7 +39,7 @@ function initializeEventHandlers() {
|
||||
element.addEventListener('mousemove', handleMouseMove);
|
||||
element.addEventListener('click', handleClick);
|
||||
|
||||
attachedElements.add(element); // Mark as attached
|
||||
attachedElementNodeInfoMap.set(element, nodeInfo); // Mark as attached and store node info
|
||||
}
|
||||
|
||||
// Attempt Widget Override as the primary method
|
||||
@@ -48,12 +52,14 @@ function initializeEventHandlers() {
|
||||
|
||||
// Check if the widget has an inputEl and if it's a TEXTAREA
|
||||
// This is to ensure we are targeting multiline text inputs, related to '.comfy-multiline-input'
|
||||
if (result && result.widget && result.widget.inputEl && result.widget.inputEl.tagName === 'TEXTAREA') {
|
||||
if (result && result.widget
|
||||
&& result.widget.inputEl && result.widget.inputEl.tagName === 'TEXTAREA' && !result.widget.inputEl.readOnly) {
|
||||
const widgetConfig = inputData && inputData[1] ? inputData[1] : {};
|
||||
// Future: Add checks for Autocomplete Plus specific configurations if needed
|
||||
// e.g., if (widgetConfig["AutocompletePlus.enabled"] === false) return result;
|
||||
|
||||
attachListeners(result.widget.inputEl);
|
||||
const nodeInfo = new NodeInfo(node.comfyClass || node.constructor.name, inputName);
|
||||
attachListeners(result.widget.inputEl, nodeInfo);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -73,9 +79,11 @@ function initializeEventHandlers() {
|
||||
targetSelectors.forEach(selector => {
|
||||
// Check if the added node itself matches or contains matching elements
|
||||
if (node.matches(selector)) {
|
||||
attachListeners(node);
|
||||
attachListeners(node, new NodeInfo('Fallback', 'unknown'));
|
||||
} else {
|
||||
node.querySelectorAll(selector).forEach(attachListeners);
|
||||
node.querySelectorAll(selector).forEach(el => {
|
||||
attachListeners(el, new NodeInfo('Fallback', 'unknown'));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -85,48 +93,72 @@ function initializeEventHandlers() {
|
||||
|
||||
// Initial scan for existing elements
|
||||
targetSelectors.forEach(selector => {
|
||||
document.querySelectorAll(selector).forEach(attachListeners);
|
||||
document.querySelectorAll(selector).forEach(el => {
|
||||
attachListeners(el, new NodeInfo('Fallback', 'unknown'));
|
||||
});
|
||||
});
|
||||
|
||||
// Start observing the document body for changes
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get NodeInfo for the event target element
|
||||
* @param {Event} event - The DOM event
|
||||
* @returns {Object|null} NodeInfo object or undefined if not found
|
||||
*/
|
||||
function getNodeInfo(event) {
|
||||
const nodeInfo = attachedElementNodeInfoMap.get(event.target);
|
||||
if (!nodeInfo) {
|
||||
console.warn('[Autocomplete-Plus] Node info not found for element in ', event.target);
|
||||
return null;
|
||||
}
|
||||
|
||||
return nodeInfo;
|
||||
}
|
||||
|
||||
function handleInput(event) {
|
||||
autocompleteEventHandler.handleInput(event);
|
||||
relatedTagsEventHandler.handleInput(event);
|
||||
autoFormatterEventHandler.handleInput(event);
|
||||
}
|
||||
|
||||
function handleFocus(event) {
|
||||
autocompleteEventHandler.handleFocus(event);
|
||||
relatedTagsEventHandler.handleFocus(event);
|
||||
autoFormatterEventHandler.handleFocus(event);
|
||||
}
|
||||
|
||||
function handleBlur(event) {
|
||||
const nodeInfo = getNodeInfo(event); // Get node info to pass to auto formatter
|
||||
|
||||
autocompleteEventHandler.handleBlur(event);
|
||||
relatedTagsEventHandler.handleBlur(event);
|
||||
autoFormatterEventHandler.handleBlur(event, nodeInfo);
|
||||
}
|
||||
|
||||
function handleKeyDown(event) {
|
||||
autocompleteEventHandler.handleKeyDown(event);
|
||||
relatedTagsEventHandler.handleKeyDown(event);
|
||||
autoFormatterEventHandler.handleKeyDown(event);
|
||||
}
|
||||
|
||||
function handleKeyUp(event) {
|
||||
autocompleteEventHandler.handleKeyUp(event);
|
||||
relatedTagsEventHandler.handleKeyUp(event);
|
||||
autoFormatterEventHandler.handleKeyUp(event);
|
||||
}
|
||||
|
||||
// New event handler for mousemove to show related tags on hover
|
||||
function handleMouseMove(event) {
|
||||
autocompleteEventHandler.handleMouseMove(event);
|
||||
relatedTagsEventHandler.handleMouseMove(event);
|
||||
autoFormatterEventHandler.handleMouseMove(event);
|
||||
}
|
||||
|
||||
// New event handler for click to show related tags
|
||||
function handleClick(event) {
|
||||
autocompleteEventHandler.handleClick(event);
|
||||
relatedTagsEventHandler.handleClick(event);
|
||||
autoFormatterEventHandler.handleClick(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,13 +203,13 @@ async function addExtraSettings() {
|
||||
checkButton.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fetch last check time from API
|
||||
let lastCheckTimeText = "Loading...";
|
||||
try {
|
||||
const response = await fetch('/autocomplete-plus/csv/last-check-time');
|
||||
const data = await response.json();
|
||||
|
||||
|
||||
if (data.last_check_time) {
|
||||
const lastCheckDate = new Date(data.last_check_time);
|
||||
lastCheckTimeText = "Last checked: " + lastCheckDate.toLocaleString();
|
||||
@@ -244,11 +276,51 @@ app.registerExtension({
|
||||
await loadDataAsync();
|
||||
},
|
||||
|
||||
// --- Commands ---
|
||||
commands: [
|
||||
{
|
||||
id: id + ".formatPrompt",
|
||||
label: name + ": Format Prompt",
|
||||
function: () => {
|
||||
const activeEl = document.activeElement;
|
||||
|
||||
if (!activeEl || activeEl.tagName !== 'TEXTAREA') {
|
||||
// console.debug('[Autocomplete-Plus] Format command: No textarea is currently focused');
|
||||
return;
|
||||
}
|
||||
|
||||
const nodeInfo = attachedElementNodeInfoMap.get(activeEl);
|
||||
if (!nodeInfo) {
|
||||
console.warn('[Autocomplete-Plus] Format command: Node info not found for focused textarea');
|
||||
// Use fallback NodeInfo
|
||||
const fallbackNodeInfo = new NodeInfo('Unknown', 'unknown');
|
||||
autoFormatterEventHandler.applyFormatTextarea(activeEl, fallbackNodeInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
const formatted = autoFormatterEventHandler.applyFormatTextarea(activeEl, nodeInfo);
|
||||
if (formatted) {
|
||||
// console.debug('[Autocomplete-Plus] Format command: Formatting applied');
|
||||
} else {
|
||||
// console.debug('[Autocomplete-Plus] Format command: Formatting skipped (blocklisted or not applicable)');
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
// --- Keybindings ---
|
||||
keybindings: [
|
||||
{
|
||||
combo: { key: "f", alt: true, shift: true },
|
||||
commandId: id + ".formatPrompt"
|
||||
}
|
||||
],
|
||||
|
||||
// One the Settings Screen, displays reverse order in same category
|
||||
settings: [
|
||||
// --- Tag source Settings ---
|
||||
{
|
||||
id: id + ".tag_source_icon_position",
|
||||
id: id + ".TagSource.IconPosition",
|
||||
name: "Tag Source Icon Position",
|
||||
type: "combo",
|
||||
options: ["left", "right", "hidden"],
|
||||
@@ -259,7 +331,7 @@ app.registerExtension({
|
||||
}
|
||||
},
|
||||
{
|
||||
id: id + ".primary_tag_source",
|
||||
id: id + ".TagSource.PrimaryTagSource",
|
||||
name: "Primary source for 'all' Source",
|
||||
tooltip: "When 'Autocomplete Tag Source' is 'all', this determines which source's tags appear first in suggestions.",
|
||||
type: "combo",
|
||||
@@ -271,7 +343,7 @@ app.registerExtension({
|
||||
}
|
||||
},
|
||||
{
|
||||
id: id + ".tag_source",
|
||||
id: id + ".TagSource",
|
||||
name: "Autocomplete Tag Source",
|
||||
tooltip: "Select the tag source for autocomplete suggestions. 'all' includes tags from all loaded sources.",
|
||||
type: "combo",
|
||||
@@ -285,9 +357,9 @@ app.registerExtension({
|
||||
|
||||
// --- Autocomplete Settings ---
|
||||
{
|
||||
id: id + ".use_fast_search",
|
||||
id: id + ".Autocompletion.UseFastSearch",
|
||||
name: "Use Fast Search",
|
||||
tooltip: "Tag search processing during text input operates faster, improving responsiveness",
|
||||
tooltip: "Tag search processing during text input operates faster, improving responsiveness.",
|
||||
type: "boolean",
|
||||
defaultValue: false,
|
||||
category: [name, "Autocompletion", "Use Fast Search"],
|
||||
@@ -296,9 +368,8 @@ app.registerExtension({
|
||||
}
|
||||
},
|
||||
{
|
||||
id: id + ".enable_models",
|
||||
id: id + ".Autocompletion.EnableModels",
|
||||
name: "Enable Loras and Embeddings",
|
||||
tooltip: "Enable Lora and Embedding suggestions",
|
||||
type: "boolean",
|
||||
defaultValue: true,
|
||||
category: [name, "Autocompletion", "Enable Loras and Embeddings"],
|
||||
@@ -307,7 +378,7 @@ app.registerExtension({
|
||||
}
|
||||
},
|
||||
{
|
||||
id: id + ".replace_underscore_with_space",
|
||||
id: id + ".Autocompletion.ReplaceUnderscoreWithSpace",
|
||||
name: "Replace '_' with 'Space'",
|
||||
tooltip: "This setting also affects related tags display.",
|
||||
type: "boolean",
|
||||
@@ -318,7 +389,18 @@ app.registerExtension({
|
||||
}
|
||||
},
|
||||
{
|
||||
id: id + ".max_suggestions",
|
||||
id: id + ".Autocompletion.AutoInsertComma",
|
||||
name: "Auto-Insert Comma",
|
||||
tooltip: "Automatically insert a comma after tags when inserting from autocomplete.",
|
||||
type: "boolean",
|
||||
defaultValue: true,
|
||||
category: [name, "Autocompletion", "Auto-Insert Comma"],
|
||||
onChange: (newVal, oldVal) => {
|
||||
settingValues.autoInsertComma = newVal;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: id + ".Autocompletion.MaxSuggestions",
|
||||
name: "Max suggestions",
|
||||
type: "slider",
|
||||
attrs: {
|
||||
@@ -333,9 +415,8 @@ app.registerExtension({
|
||||
}
|
||||
},
|
||||
{
|
||||
id: id + ".boolean",
|
||||
id: id + ".Autocompletion.Enable",
|
||||
name: "Enable Autocomplete",
|
||||
description: "Enable or disable the autocomplete feature.",
|
||||
type: "boolean",
|
||||
defaultValue: true,
|
||||
category: [name, "Autocompletion", "Enable Autocomplete"],
|
||||
@@ -346,9 +427,9 @@ app.registerExtension({
|
||||
|
||||
// --- Related Tags Settings ---
|
||||
{
|
||||
id: id + ".related_tags_trigger_mode",
|
||||
id: id + ".RelatedTags.RelatedTagsTriggerMode",
|
||||
name: "Related Tags Trigger Mode",
|
||||
description: "Trigger mode for related tags (click or ctrl+click)",
|
||||
tooltip: "Which action will trigger displaying related tags for the entered tag (click only, Ctrl+click).",
|
||||
type: "combo",
|
||||
options: ["click", "ctrl+Click"],
|
||||
defaultValue: "click",
|
||||
@@ -358,9 +439,9 @@ app.registerExtension({
|
||||
}
|
||||
},
|
||||
{
|
||||
id: id + ".related_tags_position",
|
||||
id: id + ".RelatedTags.DisplayPosition",
|
||||
name: "Default Display Position",
|
||||
description: "Display position (relative to Textarea)",
|
||||
tooltip: "Display position (relative to Textarea).",
|
||||
type: "combo",
|
||||
options: ["horizontal", "vertical"],
|
||||
defaultValue: "horizontal",
|
||||
@@ -370,9 +451,8 @@ app.registerExtension({
|
||||
}
|
||||
},
|
||||
{
|
||||
id: id + ".max_related_tags",
|
||||
id: id + ".RelatedTags.MaxRelatedTags",
|
||||
name: "Max related tags",
|
||||
description: "Maximum number of related tags to display",
|
||||
type: "slider",
|
||||
attrs: {
|
||||
min: 5,
|
||||
@@ -386,9 +466,8 @@ app.registerExtension({
|
||||
}
|
||||
},
|
||||
{
|
||||
id: id + ".related_tags_enable",
|
||||
id: id + ".RelatedTags.Enable",
|
||||
name: "Enable Related Tags",
|
||||
description: "Enable or disable the related tags feature.",
|
||||
type: "boolean",
|
||||
defaultValue: true,
|
||||
category: [name, "Related Tags", "Enable Related Tags"],
|
||||
@@ -399,15 +478,39 @@ app.registerExtension({
|
||||
|
||||
// --- Display settings ---
|
||||
{
|
||||
id: id + ".display_hide_alias",
|
||||
id: id + ".Display.HideAlias",
|
||||
name: "Hide Alias",
|
||||
tooltip: "Hide alias in the autocomplete and related tags display",
|
||||
tooltip: "Hide alias column in the autocomplete and related tags display.",
|
||||
type: "boolean",
|
||||
defaultValue: false,
|
||||
category: [name, "Display", "Hide Alias"],
|
||||
onChange: (newVal, oldVal) => {
|
||||
settingValues.hideAlias = newVal;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// --- Auto format settings ---
|
||||
{
|
||||
id: id + '.AutoFormatter.Trigger',
|
||||
name: 'Auto Format Trigger',
|
||||
tooltip: 'Auto: Format automatically when leaving text field.\nManual: Format only via keyboard shortcut. default keybind: (Alt+Shift+F)',
|
||||
type: 'combo',
|
||||
options: ['auto', 'manual'],
|
||||
defaultValue: 'auto',
|
||||
category: [name, 'AutoFormatter', 'Auto Format Trigger'],
|
||||
onChange: (newVal, oldVal) => {
|
||||
settingValues.autoFormatTrigger = newVal;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: id + '.AutoFormatter.EnableAutoFormat',
|
||||
name: 'Enable Auto Format',
|
||||
type: 'boolean',
|
||||
defaultValue: true,
|
||||
category: [name, 'AutoFormatter', 'Enable Auto Format'],
|
||||
onChange: (newVal, oldVal) => {
|
||||
settingValues.enableAutoFormat = newVal;
|
||||
},
|
||||
},
|
||||
]
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Class to hold information about the node attached to an input element.
|
||||
* Used to control behavior based on node information.
|
||||
*/
|
||||
export class NodeInfo {
|
||||
/**
|
||||
* @param {string} nodeType - The type/class name of the node
|
||||
* @param {string} inputName - The name of the input widget
|
||||
*/
|
||||
constructor(nodeType, inputName) {
|
||||
this.nodeType = nodeType;
|
||||
this.inputName = inputName;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ export const settingValues = {
|
||||
enableModels: true, // Enable Lora and Embedding suggestions
|
||||
useFastSearch: false,
|
||||
replaceUnderscoreWithSpace: true, // Replace underscores with spaces in tag insertion
|
||||
autoInsertComma: true,
|
||||
|
||||
// Related tags feature settings
|
||||
enableRelatedTags: true,
|
||||
@@ -20,6 +21,10 @@ export const settingValues = {
|
||||
// Display settings
|
||||
hideAlias: false, // Hide alias in the autocomplete and related tags display
|
||||
|
||||
// Auto format settings
|
||||
enableAutoFormat: true,
|
||||
autoFormatTrigger: 'auto', // Options: 'auto' (format on blur + shortcut), 'manual' (shortcut only)
|
||||
|
||||
|
||||
// Internal logic settings
|
||||
_useFallbackAttachmentForEventListener: false, // Fallback to attach event listener when somthing goes wrong
|
||||
|
||||
+29
-2
@@ -558,11 +558,38 @@ export function getCurrentTagRange(text, cursorPos) {
|
||||
return { start: adjustedStart, end: adjustedEnd, tag: adjustedTag };
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds weight to a lora tag if it doesn't already have one.
|
||||
* @param {string} loraTag The model tag string (e.g., "<lora:my_style01>"
|
||||
* @param {number} defaultWeight The default weight to add if not present
|
||||
* @returns {string} The model tag with weight (e.g., "<lora:my_style01:1.0>")
|
||||
*/
|
||||
export function addWeightToLora(loraTag, defaultWeight = 1.0) {
|
||||
if (!loraTag) return loraTag;
|
||||
|
||||
// Match LoRA format: <lora:name> or <lora:name:weight>
|
||||
const loraMatch = loraTag.match(/^(<lora:[^>:]+)(:[0-9.]+)?>$/i);
|
||||
if (loraMatch) {
|
||||
const existingWeight = loraMatch[2];
|
||||
|
||||
// If weight already exists, return as-is
|
||||
if (existingWeight) {
|
||||
return loraTag;
|
||||
}
|
||||
|
||||
// Add default weight, preserving original case
|
||||
return `${loraMatch[1]}:${defaultWeight.toFixed(1)}>`;
|
||||
}
|
||||
|
||||
// If it's not a recognized model format, return as-is
|
||||
return loraTag;
|
||||
}
|
||||
|
||||
// --- End String Helper Functions ---
|
||||
|
||||
/**
|
||||
* Load a CSS file dynamically.
|
||||
* @param {string} href
|
||||
* @param {string} href
|
||||
*/
|
||||
export function loadCSS(href) {
|
||||
const link = document.createElement('link');
|
||||
@@ -624,6 +651,6 @@ export function getScrollbarWidth() {
|
||||
_cachedScrollbarWidth = outer.offsetWidth - inner.offsetWidth;
|
||||
|
||||
document.body.removeChild(outer);
|
||||
|
||||
|
||||
return _cachedScrollbarWidth;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user