From 34e68e162865bbfe2fbae24ff9dc3f336c22a150 Mon Sep 17 00:00:00 2001 From: Disty0 Date: Mon, 5 May 2025 21:44:51 +0300 Subject: [PATCH] Fix SDNext ModernUI by following the cursor (#327) --- javascript/tagAutocomplete.js | 11 +++++++---- scripts/shared_paths.py | 5 ++++- scripts/tag_autocomplete_helper.py | 9 ++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 1744c33..7abc11f 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -31,7 +31,7 @@ const autocompleteCSS = ` position: absolute; z-index: 999; max-width: calc(100% - 1.5rem); - margin: 5px 0 0 0; + flex-direction: column; /* Ensure children stack vertically */ } .autocompleteResults { background-color: var(--results-bg) !important; @@ -44,6 +44,7 @@ const autocompleteCSS = ` overflow-y: var(--results-overflow-y); overflow-x: hidden; word-break: break-word; + margin-top: 10px; /* Margin to create space below the cursor */ } .sideInfo { display: none; @@ -362,10 +363,12 @@ function showResults(textArea) { parentDiv.style.display = "flex"; if (TAC_CFG.slidingPopup) { - let caretPosition = getCaretCoordinates(textArea, textArea.selectionEnd).left; - let offset = Math.min(textArea.offsetLeft - textArea.scrollLeft + caretPosition, textArea.offsetWidth - parentDiv.offsetWidth); + let caretPosition = getCaretCoordinates(textArea, textArea.selectionEnd); + let offsetTop = textArea.offsetTop + caretPosition.top - textArea.scrollTop + 10; // Adjust this value for desired distance below cursor + let offsetLeft = Math.min(textArea.offsetLeft - textArea.scrollLeft + caretPosition.left, textArea.offsetWidth - parentDiv.offsetWidth); - parentDiv.style.left = `${offset}px`; + parentDiv.style.top = `${offsetTop}px`; // Position below the cursor + parentDiv.style.left = `${offsetLeft}px`; } else { if (parentDiv.style.left) parentDiv.style.removeProperty("left"); diff --git a/scripts/shared_paths.py b/scripts/shared_paths.py index d74bd61..8843e8b 100644 --- a/scripts/shared_paths.py +++ b/scripts/shared_paths.py @@ -20,7 +20,10 @@ except ImportError: TAGS_PATH = Path(scripts.basedir()).joinpath("tags").absolute() # The path to the folder containing the wildcards and embeddings -WILDCARD_PATH = FILE_DIR.joinpath("scripts/wildcards").absolute() +try: # SD.Next + WILDCARD_PATH = Path(shared.opts.wildcards_dir).absolute() +except Exception: # A1111 + WILDCARD_PATH = FILE_DIR.joinpath("scripts/wildcards").absolute() EMB_PATH = Path(shared.cmd_opts.embeddings_dir).absolute() # Forge Classic detection diff --git a/scripts/tag_autocomplete_helper.py b/scripts/tag_autocomplete_helper.py index 33d7c25..77945ee 100644 --- a/scripts/tag_autocomplete_helper.py +++ b/scripts/tag_autocomplete_helper.py @@ -503,7 +503,14 @@ def write_style_names(*args, **kwargs): def write_temp_files(skip_wildcard_refresh = False): # Write wildcards to wc.txt if found if WILDCARD_PATH.exists() and not skip_wildcard_refresh: - wildcards = [WILDCARD_PATH.relative_to(FILE_DIR).as_posix()] + get_wildcards() + try: + # Attempt to create a relative path, but fall back to an absolute path if not possible + relative_wildcard_path = WILDCARD_PATH.relative_to(FILE_DIR).as_posix() + except ValueError: + # If the paths are not relative, use the absolute path + relative_wildcard_path = WILDCARD_PATH.as_posix() + + wildcards = [relative_wildcard_path] + get_wildcards() if wildcards: write_to_temp_file('wc.txt', wildcards)