mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-29 08:58:53 -03:00
fix(autocomplete): treat newline as a hard boundary
This commit is contained in:
@@ -947,6 +947,44 @@ describe('AutoComplete widget interactions', () => {
|
|||||||
expect(input.value).toBe('1girl ');
|
expect(input.value).toBe('1girl ');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('treats a newline as a hard boundary after dismissing autocomplete', async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
|
||||||
|
fetchApiMock.mockResolvedValue({
|
||||||
|
json: () => Promise.resolve({ success: true, words: [{ tag_name: '1girl', category: 4, post_count: 500000 }] }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const input = document.createElement('textarea');
|
||||||
|
input.value = '1gi\n';
|
||||||
|
input.selectionStart = input.value.length;
|
||||||
|
document.body.append(input);
|
||||||
|
|
||||||
|
const { AutoComplete } = await import(AUTOCOMPLETE_MODULE);
|
||||||
|
const autoComplete = new AutoComplete(input,'prompt', {
|
||||||
|
debounceDelay: 0,
|
||||||
|
showPreview: false,
|
||||||
|
minChars: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
caretHelperInstance.getBeforeCursor.mockReturnValue('1gi');
|
||||||
|
autoComplete.handleInput('1gi');
|
||||||
|
await vi.runAllTimersAsync();
|
||||||
|
await Promise.resolve();
|
||||||
|
expect(fetchApiMock).toHaveBeenCalled();
|
||||||
|
|
||||||
|
fetchApiMock.mockClear();
|
||||||
|
autoComplete.hide();
|
||||||
|
|
||||||
|
caretHelperInstance.getBeforeCursor.mockReturnValue('1gi\n');
|
||||||
|
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
await vi.runAllTimersAsync();
|
||||||
|
await Promise.resolve();
|
||||||
|
|
||||||
|
expect(autoComplete.getSearchTerm(input.value)).toBe('');
|
||||||
|
expect(fetchApiMock).not.toHaveBeenCalled();
|
||||||
|
expect(autoComplete.isVisible).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('omits the trailing comma for LoRA insertions when the setting is disabled', async () => {
|
it('omits the trailing comma for LoRA insertions when the setting is disabled', async () => {
|
||||||
settingGetMock.mockImplementation((key) => {
|
settingGetMock.mockImplementation((key) => {
|
||||||
if (key === 'loramanager.autocomplete_append_comma') {
|
if (key === 'loramanager.autocomplete_append_comma') {
|
||||||
|
|||||||
@@ -676,7 +676,8 @@ class AutoComplete {
|
|||||||
_getHardBoundaryStart(beforeCursor = '') {
|
_getHardBoundaryStart(beforeCursor = '') {
|
||||||
const lastComma = beforeCursor.lastIndexOf(',');
|
const lastComma = beforeCursor.lastIndexOf(',');
|
||||||
const lastAngle = beforeCursor.lastIndexOf('>');
|
const lastAngle = beforeCursor.lastIndexOf('>');
|
||||||
return Math.max(lastComma, lastAngle) + 1;
|
const lastNewline = Math.max(beforeCursor.lastIndexOf('\n'), beforeCursor.lastIndexOf('\r'));
|
||||||
|
return Math.max(lastComma, lastAngle, lastNewline) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_getMetadataWidget() {
|
_getMetadataWidget() {
|
||||||
|
|||||||
Reference in New Issue
Block a user