⎗
✓
diff --git a/javascript/_textAreas.js b/javascript/_textAreas.js
index 267d2fb..129f831 100644
--- a/javascript/_textAreas.js
+++ b/javascript/_textAreas.js
@@ -93,6 +93,14 @@ const thirdParty = {
         "selectors": [
             "Tag Prompt"
         ]
+    },
+    "json-builder": {
+        "base": "#txt2img_json_builder, #img2img_json_builder",
+        "hasIds": true,
+        "selectors": [
+            ".jb-root textarea",
+            ".jb-root input[type='text']"
+        ]
     }
 }

diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js
index 61cb7db..a957193 100644
--- a/javascript/tagAutocomplete.js
+++ b/javascript/tagAutocomplete.js
@@ -365,16 +365,43 @@ function showResults(textArea) {
     parentDiv.style.display = "flex";

     if (TAC_CFG.slidingPopup) {
-        let caretPosition = getCaretCoordinates(textArea, textArea.selectionEnd);
-        // Top cursor offset fix for SDNext modern UI, based on code by https://github.com/Nyx01
-        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);
+        const caretPosition = getCaretCoordinates(textArea, textArea.selectionEnd);
+        let offsetTop, offsetLeft;
+
+        if (textArea.closest(".jb-root")) {
+            // Measure the popup's real coordinate origin. Setting top/left to 0
+            // avoids relying on offsetParent, which differs inside JSON Builder.
+            parentDiv.style.top = "0px";
+            parentDiv.style.left = "0px";
+            const origin = parentDiv.getBoundingClientRect();
+            const area = textArea.getBoundingClientRect();
+
+            // Compensate for the canvas transform/zoom.
+            const popupScaleX = origin.width / parentDiv.offsetWidth || 1;
+            const popupScaleY = origin.height / parentDiv.offsetHeight || 1;
+            const areaScaleX = area.width / textArea.offsetWidth || 1;
+            const areaScaleY = area.height / textArea.offsetHeight || 1;
+
+            offsetLeft = (
+                area.left - origin.left +
+                (caretPosition.left - textArea.scrollLeft) * areaScaleX
+            ) / popupScaleX;
+
+            offsetTop = (
+                area.top - origin.top +
+                (caretPosition.top - textArea.scrollTop) * areaScaleY
+            ) / popupScaleY + 10;
+        } else {
+            // Keep the existing behavior for core prompts/other third-party areas
+            offsetTop = textArea.offsetTop + caretPosition.top - textArea.scrollTop + 10;
+            offsetLeft = Math.min(
+                textArea.offsetLeft - textArea.scrollLeft + caretPosition.left,
+                textArea.offsetWidth - parentDiv.offsetWidth
+            );
+        }

-        parentDiv.style.top = `${offsetTop}px`; // Position below the cursor
+        parentDiv.style.top = `${offsetTop}px`;
         parentDiv.style.left = `${offsetLeft}px`;
-    } else {
-        if (parentDiv.style.left)
-            parentDiv.style.removeProperty("left");
     }
     // Reset here too to make absolutely sure the browser registers it
     parentDiv.scrollTop = 0;
@@ -1561,6 +1588,13 @@ async function setup() {
     // Add mutation observer to accordions inside a base that has onDemand set to true
     addOnDemandObservers(addAutocompleteToArea);

+    // JSON Builder (and similar dynamic fields) can be created after setup
+    const jsonBuilder = thirdParty["json-builder"];
+    gradioApp().addEventListener("focusin", (e) => {
+        if (e.target.matches?.(jsonBuilder.selectors.join(", ")))
+            addAutocompleteToArea(e.target);
+    });
+
     // Add event listener to apply settings button so we can mirror the changes to our internal config
     let applySettingsButton = gradioApp().querySelector("#tab_settings #settings_submit") || gradioApp().querySelector("#tab_settings > div > .gr-button-primary");
     applySettingsButton?.addEventListener("click", () => {
Edit

Pub: 20 Nov 2026 18:00 UTC

Views: 17