mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-04-19 10:53:29 +00:00
Improve current word selection
This commit is contained in:
parent
31e60adb28
commit
d2ef3465ca
@ -89,24 +89,17 @@ app.registerExtension({
|
|||||||
end = nearestEnclosure.end;
|
end = nearestEnclosure.end;
|
||||||
selectedText = inputField.value.substring(start, end);
|
selectedText = inputField.value.substring(start, end);
|
||||||
} else {
|
} else {
|
||||||
// Select the current word, find the start and end of the word (first space before and after)
|
// Select the current word, find the start and end of the word
|
||||||
const wordStart = inputField.value.substring(0, start).lastIndexOf(" ") + 1;
|
const delimiters = " .,\\/!?%^*;:{}=-_`~()\r\n\t";
|
||||||
const wordEnd = inputField.value.substring(end).indexOf(" ");
|
|
||||||
// If there is no space after the word, select to the end of the string
|
|
||||||
if (wordEnd === -1) {
|
|
||||||
end = inputField.value.length;
|
|
||||||
} else {
|
|
||||||
end += wordEnd;
|
|
||||||
}
|
|
||||||
start = wordStart;
|
|
||||||
|
|
||||||
// Remove all punctuation at the end and beginning of the word
|
while (!delimiters.includes(inputField.value[start - 1]) && start > 0) {
|
||||||
while (inputField.value[start].match(/[.,\/#!$%\^&\*;:{}=\-_`~()]/)) {
|
start--;
|
||||||
start++;
|
|
||||||
}
|
}
|
||||||
while (inputField.value[end - 1].match(/[.,\/#!$%\^&\*;:{}=\-_`~()]/)) {
|
|
||||||
end--;
|
while (!delimiters.includes(inputField.value[end]) && end < inputField.value.length) {
|
||||||
|
end++;
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedText = inputField.value.substring(start, end);
|
selectedText = inputField.value.substring(start, end);
|
||||||
if (!selectedText) return;
|
if (!selectedText) return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user