Update js/sequence_prompt_builder.js
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { app } from "../../scripts/app.js";
|
import { app } from "../../scripts/app.js";
|
||||||
|
|
||||||
const CLASS = "DumasH3SequencePromptBuilder";
|
const CLASS = "DumasH3SequencePromptBuilder";
|
||||||
|
// Check the browser console for this line to confirm the patched file loaded.
|
||||||
|
console.info("[DUMAS H3] Prompt Builder autocomplete v2 (input-triggered) loaded");
|
||||||
const MAX_CLIPS = 16;
|
const MAX_CLIPS = 16;
|
||||||
const FIXED_TEXT_WIDGETS = [
|
const FIXED_TEXT_WIDGETS = [
|
||||||
["shared_directive", 84],
|
["shared_directive", 84],
|
||||||
@@ -833,7 +835,17 @@ function configure(node) {
|
|||||||
// by using the panel's origin as the textarea's caret location.
|
// by using the panel's origin as the textarea's caret location.
|
||||||
const positionAutocomplete = () => {
|
const positionAutocomplete = () => {
|
||||||
if (!autocomplete || !prompt?.isConnected) { closeAutocomplete(); return; }
|
if (!autocomplete || !prompt?.isConnected) { closeAutocomplete(); return; }
|
||||||
const caret = textareaCaretRect(prompt, prompt.selectionStart ?? prompt.value.length);
|
let caret;
|
||||||
|
try {
|
||||||
|
caret = textareaCaretRect(prompt, prompt.selectionStart ?? prompt.value.length);
|
||||||
|
if (!Number.isFinite(caret.left) || !Number.isFinite(caret.bottom)) throw new Error("invalid caret coordinates");
|
||||||
|
} catch (error) {
|
||||||
|
// Keep autocomplete usable even if a host UI layout cannot be
|
||||||
|
// mirrored precisely. The fallback anchors at the textarea.
|
||||||
|
const box = prompt.getBoundingClientRect();
|
||||||
|
caret = { left: box.left + 12, top: box.top, bottom: box.top + 22 };
|
||||||
|
console.warn("[DUMAS H3] Caret positioning fallback:", error);
|
||||||
|
}
|
||||||
const gutter = 8;
|
const gutter = 8;
|
||||||
const gap = 5;
|
const gap = 5;
|
||||||
const width = autocomplete.offsetWidth;
|
const width = autocomplete.offsetWidth;
|
||||||
@@ -947,12 +959,32 @@ function configure(node) {
|
|||||||
window.removeEventListener("resize", onViewportChange);
|
window.removeEventListener("resize", onViewportChange);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
prompt.oninput = () => {
|
// Trigger on the actual text insertion, not only keydown. On some
|
||||||
|
// browsers / keyboard layouts an input event follows the @ keydown;
|
||||||
|
// the old handler immediately CLOSED the menu it had just opened.
|
||||||
|
// Handling the inserted character works with UK keyboards, IMEs and
|
||||||
|
// browser-mediated text input without manually inserting duplicates.
|
||||||
|
prompt.oninput = (event) => {
|
||||||
|
const before = String(promptText ?? clip.prompt ?? "");
|
||||||
|
const after = prompt.value;
|
||||||
|
const caret = prompt.selectionStart ?? after.length;
|
||||||
|
const atCaret = caret > 0 && after.charAt(caret - 1) === "@";
|
||||||
|
const insertedSingleAt = atCaret && event?.inputType !== "insertFromPaste" && (
|
||||||
|
(event?.data === "@") ||
|
||||||
|
(after.length === before.length + 1 &&
|
||||||
|
after.slice(0, caret - 1) === before.slice(0, caret - 1) &&
|
||||||
|
after.slice(caret) === before.slice(caret - 1))
|
||||||
|
);
|
||||||
rememberPromptSelection();
|
rememberPromptSelection();
|
||||||
promptText = prompt.value; clip.prompt = prompt.value;
|
promptText = after;
|
||||||
// If they keep typing a literal @R token, don't obstruct typing.
|
clip.prompt = after;
|
||||||
// The menu is shown by @ and stays up for arrow/Enter navigation.
|
if (insertedSingleAt) {
|
||||||
if (autocomplete) closeAutocomplete();
|
openAutocomplete(caret - 1);
|
||||||
|
} else if (autocomplete) {
|
||||||
|
// Typing anything after the @ lets the user continue with a
|
||||||
|
// literal token, e.g. @R1, without an obstructing menu.
|
||||||
|
closeAutocomplete();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
prompt.onpaste = () => {
|
prompt.onpaste = () => {
|
||||||
closeAutocomplete();
|
closeAutocomplete();
|
||||||
@@ -976,7 +1008,16 @@ function configure(node) {
|
|||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
prompt.onselect = rememberPromptSelection;
|
prompt.onselect = rememberPromptSelection;
|
||||||
prompt.onkeyup = rememberPromptSelection;
|
prompt.onkeyup = (event) => {
|
||||||
|
rememberPromptSelection();
|
||||||
|
// Fallback for environments that deliver keyboard text changes
|
||||||
|
// without a normal InputEvent. Never fabricate the @ character.
|
||||||
|
if (event.key === "@" && !autocomplete &&
|
||||||
|
promptSelectionStart > 0 &&
|
||||||
|
prompt.value.charAt(promptSelectionStart - 1) === "@") {
|
||||||
|
openAutocomplete(promptSelectionStart - 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
prompt.onmouseup = rememberPromptSelection;
|
prompt.onmouseup = rememberPromptSelection;
|
||||||
prompt.onblur = () => {
|
prompt.onblur = () => {
|
||||||
closeAutocomplete();
|
closeAutocomplete();
|
||||||
@@ -1007,16 +1048,10 @@ function configure(node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.key !== "@" || event.ctrlKey || event.metaKey || event.altKey) return;
|
if (event.key !== "@" || event.ctrlKey || event.metaKey || event.altKey) return;
|
||||||
event.preventDefault(); event.stopPropagation();
|
// Let the browser insert @. The input event opens the menu after
|
||||||
const start = prompt.selectionStart ?? prompt.value.length;
|
// the selection/caret has advanced to its true position.
|
||||||
const end = prompt.selectionEnd ?? start;
|
// Stop ComfyUI graph-level keyboard shortcuts from intercepting it.
|
||||||
prompt.value = prompt.value.slice(0, start) + "@" + prompt.value.slice(end);
|
event.stopPropagation();
|
||||||
prompt.setSelectionRange(start + 1, start + 1);
|
|
||||||
promptSelectionStart = start;
|
|
||||||
promptSelectionEnd = start + 1;
|
|
||||||
promptText = prompt.value; clip.prompt = prompt.value;
|
|
||||||
syncPrompt(clip, clip.prompt); persistState();
|
|
||||||
openAutocomplete(start);
|
|
||||||
};
|
};
|
||||||
promptFrame = el("div");
|
promptFrame = el("div");
|
||||||
promptFrame.style.cssText = "position:relative;overflow:visible;width:100%;box-sizing:border-box";
|
promptFrame.style.cssText = "position:relative;overflow:visible;width:100%;box-sizing:border-box";
|
||||||
|
|||||||
Reference in New Issue
Block a user