From 462bafa5e4c45e42465d18a900af37f3a2f936b5 Mon Sep 17 00:00:00 2001 From: shinich39 Date: Thu, 5 Dec 2024 12:31:56 +0900 Subject: [PATCH 1/6] fix cursor detection --- web/js/autocompleter.js | 4 +++- web/js/common/autocomplete.js | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/web/js/autocompleter.js b/web/js/autocompleter.js index d0fb2ec..691cefc 100644 --- a/web/js/autocompleter.js +++ b/web/js/autocompleter.js @@ -6,6 +6,8 @@ import { TextAreaAutoComplete } from "./common/autocomplete.js"; import { ModelInfoDialog } from "./common/modelInfoDialog.js"; import { LoraInfoDialog } from "./modelInfo.js"; +const MAX_ROW_COUNT = 50; + function parseCSV(csvText) { const rows = []; const delimiter = ","; @@ -525,7 +527,7 @@ app.registerExtension({ TextAreaAutoComplete.insertOnTab = localStorage.getItem(id + ".InsertOnTab") !== "false"; TextAreaAutoComplete.insertOnEnter = localStorage.getItem(id + ".InsertOnEnter") !== "false"; TextAreaAutoComplete.lorasEnabled = localStorage.getItem(id + ".ShowLoras") === "true"; - TextAreaAutoComplete.suggestionCount = +localStorage.getItem(id + ".SuggestionCount") || 20; + TextAreaAutoComplete.suggestionCount = +localStorage.getItem(id + ".SuggestionCount") || MAX_ROW_COUNT; }, setup() { async function addEmbeddings() { diff --git a/web/js/common/autocomplete.js b/web/js/common/autocomplete.js index d4c461a..372a2e4 100644 --- a/web/js/common/autocomplete.js +++ b/web/js/common/autocomplete.js @@ -494,7 +494,7 @@ export class TextAreaAutoComplete { } #getFilteredWords(term) { - term = term.toLocaleLowerCase(); + term = term.toLocaleLowerCase() const priorityMatches = []; const prefixMatches = []; @@ -536,9 +536,11 @@ export class TextAreaAutoComplete { #update() { let before = this.helper.getBeforeCursor(); if (before?.length) { - const m = before.match(/([^\s|,|;|"]+)$/); + const m = before.match(/([^,;"]+)$/); if (m) { - before = m[0]; + before = m[0] + .replace(/^\s+/, "") + .replace(/\s/g, "_") || null; } else { before = null; } From 02d0e3e56d40496c98e03b67ec8ac1914025725d Mon Sep 17 00:00:00 2001 From: shinich39 Date: Thu, 5 Dec 2024 12:35:53 +0900 Subject: [PATCH 2/6] fix cursor detection --- web/js/autocompleter.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web/js/autocompleter.js b/web/js/autocompleter.js index 691cefc..d0fb2ec 100644 --- a/web/js/autocompleter.js +++ b/web/js/autocompleter.js @@ -6,8 +6,6 @@ import { TextAreaAutoComplete } from "./common/autocomplete.js"; import { ModelInfoDialog } from "./common/modelInfoDialog.js"; import { LoraInfoDialog } from "./modelInfo.js"; -const MAX_ROW_COUNT = 50; - function parseCSV(csvText) { const rows = []; const delimiter = ","; @@ -527,7 +525,7 @@ app.registerExtension({ TextAreaAutoComplete.insertOnTab = localStorage.getItem(id + ".InsertOnTab") !== "false"; TextAreaAutoComplete.insertOnEnter = localStorage.getItem(id + ".InsertOnEnter") !== "false"; TextAreaAutoComplete.lorasEnabled = localStorage.getItem(id + ".ShowLoras") === "true"; - TextAreaAutoComplete.suggestionCount = +localStorage.getItem(id + ".SuggestionCount") || MAX_ROW_COUNT; + TextAreaAutoComplete.suggestionCount = +localStorage.getItem(id + ".SuggestionCount") || 20; }, setup() { async function addEmbeddings() { From d89dae5c28fd77005d68f7408193f5d13d20ea13 Mon Sep 17 00:00:00 2001 From: shinich39 Date: Thu, 12 Dec 2024 06:33:23 +0900 Subject: [PATCH 3/6] fix cursor detection --- web/js/common/autocomplete.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/web/js/common/autocomplete.js b/web/js/common/autocomplete.js index 372a2e4..21bda1b 100644 --- a/web/js/common/autocomplete.js +++ b/web/js/common/autocomplete.js @@ -494,17 +494,18 @@ export class TextAreaAutoComplete { } #getFilteredWords(term) { - term = term.toLocaleLowerCase() + term = term.toLocaleLowerCase(); const priorityMatches = []; const prefixMatches = []; const includesMatches = []; for (const word of Object.keys(this.words)) { const lowerWord = word.toLocaleLowerCase(); - if (lowerWord === term) { - // Dont include exact matches - continue; - } + // Show exact matches + // if (lowerWord === term) { + // // Dont include exact matches + // continue; + // } const pos = lowerWord.indexOf(term); if (pos === -1) { @@ -621,6 +622,10 @@ export class TextAreaAutoComplete { value = TextAreaAutoComplete.replacer(value); } value = this.#escapeParentheses(value); + + // Remove underscore + value = value.replace("_", " "); + const afterCursor = this.helper.getAfterCursor(); const shouldAddSeparator = !afterCursor.trim().startsWith(this.separator.trim()); this.helper.insertAtCursor( From 8e815e2af5a24abb04bb46676d1dd3ffef48258c Mon Sep 17 00:00:00 2001 From: shinich39 Date: Thu, 12 Dec 2024 06:40:00 +0900 Subject: [PATCH 4/6] fix cursor detection --- web/js/common/autocomplete.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/web/js/common/autocomplete.js b/web/js/common/autocomplete.js index 21bda1b..8bd0755 100644 --- a/web/js/common/autocomplete.js +++ b/web/js/common/autocomplete.js @@ -501,11 +501,10 @@ export class TextAreaAutoComplete { const includesMatches = []; for (const word of Object.keys(this.words)) { const lowerWord = word.toLocaleLowerCase(); - // Show exact matches - // if (lowerWord === term) { - // // Dont include exact matches - // continue; - // } + if (lowerWord === term) { + // Dont include exact matches + continue; + } const pos = lowerWord.indexOf(term); if (pos === -1) { @@ -624,7 +623,7 @@ export class TextAreaAutoComplete { value = this.#escapeParentheses(value); // Remove underscore - value = value.replace("_", " "); + value = value.replace(/_/g, " "); const afterCursor = this.helper.getAfterCursor(); const shouldAddSeparator = !afterCursor.trim().startsWith(this.separator.trim()); From b0715ddddac3167a3fa746644126d5ae85407891 Mon Sep 17 00:00:00 2001 From: shinich39 Date: Tue, 17 Dec 2024 04:31:01 +0900 Subject: [PATCH 5/6] Add brackets detection to getBeforeCursor() --- web/js/common/autocomplete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/js/common/autocomplete.js b/web/js/common/autocomplete.js index 8bd0755..9769332 100644 --- a/web/js/common/autocomplete.js +++ b/web/js/common/autocomplete.js @@ -536,7 +536,7 @@ export class TextAreaAutoComplete { #update() { let before = this.helper.getBeforeCursor(); if (before?.length) { - const m = before.match(/([^,;"]+)$/); + const m = before.match(/([^,;"|{}()]+)$/); if (m) { before = m[0] .replace(/^\s+/, "") From 772ff041648255f5a21ede9e75cf647cdc33dc3a Mon Sep 17 00:00:00 2001 From: shinich39 Date: Tue, 24 Dec 2024 06:05:53 +0900 Subject: [PATCH 6/6] Add linebreak to regex. --- web/js/common/autocomplete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/js/common/autocomplete.js b/web/js/common/autocomplete.js index 9769332..9716408 100644 --- a/web/js/common/autocomplete.js +++ b/web/js/common/autocomplete.js @@ -536,7 +536,7 @@ export class TextAreaAutoComplete { #update() { let before = this.helper.getBeforeCursor(); if (before?.length) { - const m = before.match(/([^,;"|{}()]+)$/); + const m = before.match(/([^,;"|{}()\n]+)$/); if (m) { before = m[0] .replace(/^\s+/, "")