-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bracket Checker] Also check for the order of brackets #16718
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Now also checks for pairing of escaped brackets (ie. ( ... ), etc)
literal brackets should not be checked as it is not a part of the prompt syntax
it is valid to have mismatch literal brackets
Maybe make it a setting then? since:
Who would have a non-closed brackets anyway? I can't think of a reason to only use either opening or closing bracket alone. Take Booru Tags for example, literal brackets are used to denote franchise or medium, and they are always in pairs. |
If you meant checking the pairings, it's for when you forgot to escape both brackets (eg. |
no actually is the reverse maybe I'm thinking too much I feel like using the same "error message" is misleading when ther is a mismatch bracket a "RED error" appear let the user know something worng and would trigger the fallback behavior I won't have an issue if it instead is highlighted like yellow when it is caused by mismatch literal brackets |
Now that I think about it, in case of And in case of
|
counts[bracket[1]] = (counts[bracket[1]] || 0) + 1; | ||
}); | ||
const errors = []; | ||
(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functionally wise looks good to me
just one more question / issue
is there a particular reason that you decided to wrap this entire thing inside a function?
(function() {
/*...*/
})();
if you did this because to avoid namespace collisions
considering that all these functions already existed for a long time in global space
there shouldn't be any collision issues
apart from only new variable added pairs
I would suggest you rename pairs
to something more like promptBracketCheckerPairs
and leave the structure other as is
or is there some other considerations that makes you move this entire thing into a function?
I feel like it's advantageous to allow other scripts to have access to pairs / promptBracketChecker
this way for some reason an extension wishes to add some additional syntax they could
Yeah, it's mainly to avoid namespace pollution afaik
|
LGTM oh there's a name for this pattern another issue with using IIFE in this case while this is a built-in "extention" (so can be disabled) |
Simple Description
Currently, this script only checks if the number of opening and closing brackets are the same. So if you have mistyped something like
)...(
in the prompts, the checker would not detect it as error.The current regular expression is frankly... difficult to read
(?<!
) may not be supported on all browsers; though when I looked it up, it seems to be supported on all modern browsers.List of Changes
Now also checks for pairing of escaped bracketsonEdit
function to detect user inputs400 ms
, half of token-counterconst pairs = [ ... ]
insidecheckBrackets() { ... }
Checklist
Performance: Checking a textbox filled to ~150 tokens took
0.2 ms