Keep prompt position when using controls
This commit is contained in:
@@ -289,6 +289,14 @@ function configure(node) {
|
||||
let autocompleteRange = null;
|
||||
let promptFrame = null;
|
||||
let suggestionLayer = null;
|
||||
const focusPrompt = () => {
|
||||
if (!prompt) return;
|
||||
try {
|
||||
prompt.focus({ preventScroll: true });
|
||||
} catch (_) {
|
||||
prompt.focus();
|
||||
}
|
||||
};
|
||||
const segments = [];
|
||||
const handles = [];
|
||||
const updateTimeline = () => {
|
||||
@@ -304,7 +312,10 @@ function configure(node) {
|
||||
clip.slots.forEach((slot, index) => {
|
||||
const segment = el("button", `Shot ${index + 1}\n${(slot.text || "unscripted").slice(0, 18)}`); segment.type = "button";
|
||||
segment.style.cssText = `position:absolute;top:0;height:100%;border:0;border-right:2px solid #292929;color:white;background:${palette[index % palette.length]};white-space:pre-wrap;font-size:10px;overflow:hidden;padding:2px;cursor:pointer`;
|
||||
segment.onclick = () => { prompt.focus(); }; segments.push(segment); timeline.append(segment);
|
||||
segment.onclick = (event) => {
|
||||
event.preventDefault(); event.stopPropagation();
|
||||
focusPrompt();
|
||||
}; segments.push(segment); timeline.append(segment);
|
||||
});
|
||||
clip.slots.slice(0, -1).forEach((slot, index) => {
|
||||
const next = clip.slots[index + 1];
|
||||
@@ -359,11 +370,12 @@ function configure(node) {
|
||||
const chip = el("button", chipText || `Shot ${index + 1}`); chip.type = "button";
|
||||
chip.title = `Jump to Shot ${index + 1}`;
|
||||
chip.style.cssText = `max-width:180px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding:3px 8px;border:1px solid ${palette[index % palette.length]};border-radius:4px;background:#1e1e1e;color:#e6e6e6;font:11px Arial;cursor:pointer`;
|
||||
chip.onclick = () => {
|
||||
chip.onclick = (event) => {
|
||||
event.preventDefault(); event.stopPropagation();
|
||||
if (!prompt) return;
|
||||
const marker = `[Shot ${index + 1}]`;
|
||||
const position = prompt.value.indexOf(marker);
|
||||
prompt.focus();
|
||||
focusPrompt();
|
||||
if (position >= 0) prompt.setSelectionRange(position, position + marker.length);
|
||||
};
|
||||
shotChips.append(chip);
|
||||
@@ -418,7 +430,7 @@ function configure(node) {
|
||||
const token = `@R${index} `;
|
||||
prompt.value = prompt.value.slice(0, start) + token + prompt.value.slice(end);
|
||||
const caret = start + token.length;
|
||||
prompt.focus(); prompt.setSelectionRange(caret, caret);
|
||||
focusPrompt(); prompt.setSelectionRange(caret, caret);
|
||||
promptSelectionStart = caret; promptSelectionEnd = caret;
|
||||
promptText = prompt.value; clip.prompt = prompt.value;
|
||||
syncPrompt(clip, clip.prompt); persistState();
|
||||
@@ -484,7 +496,7 @@ function configure(node) {
|
||||
const token = `@R${index} `;
|
||||
prompt.value = prompt.value.slice(0, start) + token + prompt.value.slice(end);
|
||||
const caret = start + token.length;
|
||||
prompt.focus(); prompt.setSelectionRange(caret, caret);
|
||||
focusPrompt(); prompt.setSelectionRange(caret, caret);
|
||||
promptSelectionStart = caret; promptSelectionEnd = caret;
|
||||
promptText = prompt.value; clip.prompt = prompt.value;
|
||||
syncPrompt(clip, clip.prompt); persistState(); closeAutocomplete();
|
||||
@@ -555,7 +567,7 @@ function configure(node) {
|
||||
const token = `${prefix}${text} `;
|
||||
prompt.value = before + token + after;
|
||||
const caret = before.length + token.length;
|
||||
prompt.focus(); prompt.setSelectionRange(caret, caret);
|
||||
focusPrompt(); prompt.setSelectionRange(caret, caret);
|
||||
promptSelectionStart = caret; promptSelectionEnd = caret;
|
||||
promptText = prompt.value; clip.prompt = prompt.value;
|
||||
syncPrompt(clip, clip.prompt); persistState();
|
||||
|
||||
Reference in New Issue
Block a user