feat: add forbidden characters to @ConfigEditorText#72
Open
Knixxx wants to merge 4 commits intoNotEnoughUpdates:v4from
Open
feat: add forbidden characters to @ConfigEditorText#72Knixxx wants to merge 4 commits intoNotEnoughUpdates:v4from
Knixxx wants to merge 4 commits intoNotEnoughUpdates:v4from
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
the problem:
while coding myself i noticed that the
@ConfigEditorTextannotation does check for the presence of a '§' within the textfield and blocks it accordingly, but only if it was typed by hand. if it is pasted, the clipboard content simply gets written as it is.you can see the behavior in
TextFieldComponent:that means, if we would like to copy a '§' and paste it inside of a textfield it would just get placed and you can use color codes inside of the textfield.
Figure 1: Example of Color Codes inside a TextField
this behavior is not intended, as it could potentially cause bugs, if we would like to read from our text variable, where the content gets stored and build something off of that (e.g. we want to write the content of the textfield in the chat).
therefore i added
forbiddenas a parameter to@ConfigEditorText.its purpose is to block any given characters from being pasted in the textfield.
following i modified the
writeTextmethod inTextFieldComponentas follows:we filter the text, that's to be written and remove all forbidden characters. if the string is empty after filtering, we just cancel the event. there is an exception though, if we press backspace, the
writeTextmethod gets called with an empty string already, and thus we don't want to cancel the event (shas to be not empty, otherwise thewriteTextmethod proceeds).after filtering we use
filteredStringto set our text, instead ofs:e.g.:
this prevents pasting forbidden chars, but to prevent typing them i modified the
CharTypedevent branch as follows:i consciously consume the event, if we type a forbidden character, so we don't always focus the searchbar, as soon as we type one. we just stay inside of the textfield.
i removed the hardcoded version of the previously cancellation of the '§' character:
and replaced it with the standard forbidden character (which gets checked as well by default):
now the user has the option to set forbidden character itself, and the standard forbidden one is really forbidden.
to present this i added to the
TestCategoryA:the forbidden character '§' and 'z'.
notice, that when you set forbidden character yourself, the default one ('§') gets overridden and is not forbidden anymore by default. (you have to add it manually again, if still needed).