Skip to content

Commit 9d12afb

Browse files
Merge pull request #55 from newtextdoc1111/dev
Merge Dev
2 parents 3f84125 + 091ec15 commit 9d12afb

File tree

15 files changed

+403
-86
lines changed

15 files changed

+403
-86
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ When you type in a text input area, tags that partially match the text are displ
4343
- Tags that have already been entered are displayed grayed out.
4444
- You can display Danbooru and e621 tags at the same time. You can also change the priority from the settings.
4545
- Supports autocomplete for Lora and Embedding inputs. You can enable/disable this feature in the settings.
46+
- Clicking the 📖 icon opens the tag's Wiki page. If a tag is selected via keyboard, you can open it with the `F1` key.
4647

4748
## Related Tags
4849

@@ -53,6 +54,7 @@ When you select any tag in a text input area, a list of highly related tags is d
5354
- The display position is primarily at the bottom of the text area and automatically adjusts vertically based on available space.
5455
- You can switch between vertical and horizontal display positions using the "↕️|↔️" button in the header.
5556
- You can toggle the pinned state of the displayed related tags using the "📌|🎯" button in the header. To close the UI when pinned, press the Esc key.
57+
- Clicking the tag in the header opens the tag's Wiki page.
5658
- 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.
5759
- You can display related tags for the cursor position by pressing `Ctrl+Shift+Space`.
5860

@@ -187,6 +189,7 @@ For example, by preparing the following CSV, you can quickly insert correspondin
187189
- **Auto Format Trigger**: Choose when formatting is applied.
188190
- **Auto**: Format automatically when leaving text field
189191
- **Manual**: Format only via keyboard shortcut (default: `Alt+Shift+F`)
192+
- **Use Trailing Comma**: If enabled, ensures all lines end with a trailing comma when formatting. If disabled, removes trailing commas.
190193

191194
## Advanced Settings
192195

docs/README_jp.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
- 入力済みのタグはグレーアウトで表示されます
4242
- Danbooruとe621のタグを同時に表示出来ます。設定から優先順位を変更できます
4343
- LoraとEmbeddingの入力補完に対応しています。設定から有効・無効を切り替えられます
44+
- 「📖」アイコンをクリックするとタグのWikiページを開きます。キーボードで選択中の場合は `F1` キーで開くことが出来ます
4445

4546
## 関連タグ
4647

@@ -51,6 +52,7 @@
5152
- 表示位置は、テキストエリアの下部を基本とし、空きスペースに応じて上下に自動調整されます
5253
- ヘッダーの「↕️|↔️」ボタンで上下と左右の表示位置に切り替えられます
5354
- ヘッダーの「📌|🎯」ボタンで表示する関連タグの固定状態を切り替えられます。固定状態で閉じたい場合はEscキーを押します
55+
- ヘッダーのタグをクリックするとタグのWikiページを開きます
5456
- 入力済みのタグはグレーアウトで表示されます。グレーアウトしたタグを挿入しようとした場合、代わりに入力済みのタグを選択状態にします
5557
- `Ctrl+Shift+Space` キーでカーソル位置の関連タグを表示できます
5658

@@ -185,6 +187,7 @@ worst_quality,5,9999999,
185187
- **Auto Format Trigger**: フォーマットを適用するタイミングを選択します
186188
- **自動**: テキスト欄からフォーカスが外れた際に自動でフォーマットします
187189
- **手動**: キーボードショートカットでのみフォーマットします(デフォルト: `Alt+Shift+F`
190+
- **行末にカンマを使用**: 有効にすると、フォーマット時にすべての行末がカンマで終わるようになります。\n無効にすると行末のカンマが削除されます
188191

189192
## 上級者向け設定
190193

locales/en/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
"manual": "Manual"
8080
}
8181
},
82+
"AutocompletePlus_AutoFormatter_UseTrailingComma": {
83+
"name": "Use Trailing Comma",
84+
"tooltip": "When enabled, ensures all lines end with a trailing comma.\nWhen disabled, removes trailing commas."
85+
},
8286
"AutocompletePlus_AutoFormatter_EnableAutoFormat": {
8387
"name": "Enable Auto Format"
8488
}

locales/ja/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
"manual": "手動"
8080
}
8181
},
82+
"AutocompletePlus_AutoFormatter_UseTrailingComma": {
83+
"name": "行末にカンマを使用",
84+
"tooltip": "有効にすると、すべての行末がカンマで終わるようになります。\n無効にすると行末のカンマが削除されます。"
85+
},
8286
"AutocompletePlus_AutoFormatter_EnableAutoFormat": {
8387
"name": "自動フォーマット機能の有効化"
8488
}

locales/zh-TW/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
"manual": "手動"
8080
}
8181
},
82+
"AutocompletePlus_AutoFormatter_UseTrailingComma": {
83+
"name": "在行末添加逗號",
84+
"tooltip": "啟用時,確保所有行都以逗號結尾。\n停用時,移除結尾逗號。"
85+
},
8286
"AutocompletePlus_AutoFormatter_EnableAutoFormat": {
8387
"name": "啟用自動格式化"
8488
}

locales/zh/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
"manual": "手动"
8080
}
8181
},
82+
"AutocompletePlus_AutoFormatter_UseTrailingComma": {
83+
"name": "在行末添加逗号",
84+
"tooltip": "启用时,确保所有行都以逗号结尾。\n禁用时,移除结尾逗号。"
85+
},
8286
"AutocompletePlus_AutoFormatter_EnableAutoFormat": {
8387
"name": "启用自动格式化"
8488
}

tests/js/auto-formatter.test.js

Lines changed: 91 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
formatPromptText,
33
__test__
44
} from "../../web/js/auto-formatter.js";
5+
import { settingValues } from "../../web/js/settings.js";
56

67
const {
78
shouldAutoFormat
@@ -44,37 +45,102 @@ describe('AutoFormatter Functions', () => {
4445
});
4546

4647
describe('formatPromptText', () => {
47-
test('should format text by adding comma and space after tags', () => {
48-
const input = 'tag1,tag2,tag3';
49-
const expected = 'tag1, tag2, tag3, ';
50-
expect(formatPromptText(input)).toBe(expected);
51-
});
48+
// Store original setting value to restore after tests
49+
const originalUseTrailingComma = settingValues.useTrailingComma;
5250

53-
test('should remove extra spaces around tags', () => {
54-
const input = ' tag1 , tag2 ';
55-
const expected = 'tag1, tag2, ';
56-
expect(formatPromptText(input)).toBe(expected);
51+
afterEach(() => {
52+
// Restore original setting after each test
53+
settingValues.useTrailingComma = originalUseTrailingComma;
5754
});
5855

59-
test('should preserve special syntax like weights', () => {
60-
const input = '(tag1:1.2), [tag2]';
61-
// Note: The current implementation splits by comma.
62-
// If the input is "(tag1:1.2), [tag2]", it splits into "(tag1:1.2)" and "[tag2]".
63-
// Then joins with ", ".
64-
const expected = '(tag1:1.2), [tag2], ';
65-
expect(formatPromptText(input)).toBe(expected);
66-
});
56+
describe('with useTrailingComma enabled', () => {
57+
beforeEach(() => {
58+
settingValues.useTrailingComma = true;
59+
});
60+
61+
test('should format text by adding comma and space after tags', () => {
62+
const input = 'tag1,tag2,tag3';
63+
const expected = 'tag1, tag2, tag3, ';
64+
expect(formatPromptText(input)).toBe(expected);
65+
});
66+
67+
test('should remove extra spaces around tags', () => {
68+
const input = ' tag1 , tag2 ';
69+
const expected = 'tag1, tag2, ';
70+
expect(formatPromptText(input)).toBe(expected);
71+
});
72+
73+
test('should preserve special syntax like weights', () => {
74+
const input = '(tag1:1.2), [tag2]';
75+
// Note: The current implementation splits by comma.
76+
// If the input is "(tag1:1.2), [tag2]", it splits into "(tag1:1.2)" and "[tag2]".
77+
// Then joins with ", ".
78+
const expected = '(tag1:1.2), [tag2], ';
79+
expect(formatPromptText(input)).toBe(expected);
80+
});
81+
82+
test('should handle multiple lines', () => {
83+
const input = 'tag1, tag2\ntag3, tag4';
84+
const expected = 'tag1, tag2, \ntag3, tag4, ';
85+
expect(formatPromptText(input)).toBe(expected);
86+
});
87+
88+
test('should keep empty lines unchanged', () => {
89+
const input = 'tag1, tag2\n\ntag3, tag4';
90+
const expected = 'tag1, tag2, \n\ntag3, tag4, ';
91+
expect(formatPromptText(input)).toBe(expected);
92+
});
6793

68-
test('should handle multiple lines', () => {
69-
const input = 'tag1, tag2\ntag3, tag4';
70-
const expected = 'tag1, tag2, \ntag3, tag4, ';
71-
expect(formatPromptText(input)).toBe(expected);
94+
test('should not modify text that already has trailing comma', () => {
95+
const input = 'tag1, tag2, ';
96+
const expected = 'tag1, tag2, ';
97+
expect(formatPromptText(input)).toBe(expected);
98+
});
7299
});
73100

74-
test('should keep empty lines unchanged', () => {
75-
const input = 'tag1, tag2\n\ntag3, tag4';
76-
const expected = 'tag1, tag2, \n\ntag3, tag4, ';
77-
expect(formatPromptText(input)).toBe(expected);
101+
describe('with useTrailingComma disabled', () => {
102+
beforeEach(() => {
103+
settingValues.useTrailingComma = false;
104+
});
105+
106+
test('should format text by adding comma and space after tags without trailing comma', () => {
107+
const input = 'tag1,tag2,tag3';
108+
const expected = 'tag1, tag2, tag3';
109+
expect(formatPromptText(input)).toBe(expected);
110+
});
111+
112+
test('should remove extra spaces around tags without trailing comma', () => {
113+
const input = ' tag1 , tag2 ';
114+
const expected = 'tag1, tag2';
115+
expect(formatPromptText(input)).toBe(expected);
116+
});
117+
118+
test('should preserve special syntax like weights without trailing comma', () => {
119+
const input = '(tag1:1.2), [tag2]';
120+
// Note: The current implementation splits by comma.
121+
// If the input is "(tag1:1.2), [tag2]", it splits into "(tag1:1.2)" and "[tag2]".
122+
// Then joins with ", ".
123+
const expected = '(tag1:1.2), [tag2]';
124+
expect(formatPromptText(input)).toBe(expected);
125+
});
126+
127+
test('should handle multiple lines without trailing comma', () => {
128+
const input = 'tag1, tag2\ntag3, tag4';
129+
const expected = 'tag1, tag2\ntag3, tag4';
130+
expect(formatPromptText(input)).toBe(expected);
131+
});
132+
133+
test('should keep empty lines unchanged without trailing comma', () => {
134+
const input = 'tag1, tag2\n\ntag3, tag4';
135+
const expected = 'tag1, tag2\n\ntag3, tag4';
136+
expect(formatPromptText(input)).toBe(expected);
137+
});
138+
139+
test('should remove existing trailing comma when disabled', () => {
140+
const input = 'tag1, tag2, ';
141+
const expected = 'tag1, tag2';
142+
expect(formatPromptText(input)).toBe(expected);
143+
});
78144
});
79145

80146
test('should handle empty input', () => {

0 commit comments

Comments
 (0)