Skip to content

Add TextBox event handlers #3289

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

Merged
merged 22 commits into from
Jul 10, 2020

Conversation

frenzibyte
Copy link
Member

@frenzibyte frenzibyte commented Feb 20, 2020

Allows for adding custom logic when something happens to a TextBox, will come in handy for moving audio samples from the abstract TextBox to osu!lazer's.

Also has other changes:

  • Changes Commit() return type to bool for indicating that a commit actually occurred. (to avoid potentially executing custom logic on Commit() 2 times when ReleaseFocusOnCommit and CommitOnFocusLost are both set)
  • Adds a bonus feature: whether the caret is currently selecting text while moving, may be useful for playing different sounds based on what state the caret is in.

Salman Ahmed added 3 commits February 20, 2020 05:08
For indication whether text has been commited (internally, whether OnCommit has been invoked).
*(what was I doing)*
Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it even be valid to have a text box that has both ReleaseFocusOnCommit and CommitOnFocusLost set? That just sounds broken by design, I'm not sure why someone would want to shoot themselves in the foot with that gun.

@frenzibyte
Copy link
Member Author

Should it even be valid to have a text box that has both ReleaseFocusOnCommit and CommitOnFocusLost set? That just sounds broken by design, I'm not sure why someone would want to shoot themselves in the foot with that gun.

out-of-scope for this PR but definitely something to open an issue for, in fact, some of the TextBox component logic are outdated and may need to be revised and refactored at some point.

@bdach
Copy link
Collaborator

bdach commented Feb 20, 2020

It is out of scope here but I'd argue it needs to be a prereq PR as the bool Commit() is a little strange in my opinion, and it'd probably end up being a simple exception throw on improper usage or something.

@frenzibyte
Copy link
Member Author

It is out of scope here but I'd argue it needs to be a prereq PR as the bool Commit() is a little strange in my opinion

Why though? this could be useful to block committing on certain conditions with its sub-classes not required to duplicate the checks and just early-return if false is returned in the base method.

Might as well force that on all overridable functions.

@bdach
Copy link
Collaborator

bdach commented Feb 21, 2020

this could be useful to block committing on certain conditions with its sub-classes not required to duplicate the checks and just early-return if false is returned in the base method.

I'd have to see a concrete convincing example that justifies this. Just the ability to do so doesn't convince me as it is added complexity, and I'm not sure that it's necessary.

@frenzibyte
Copy link
Member Author

Should it even be valid to have a text box that has both ReleaseFocusOnCommit and CommitOnFocusLost set?

After rethinking this a bit, this should definitely be valid, this type of TextBox would commit current text when focus has been lost naturally (not by ReleaseFocusOnCommit) and release focus from the TextBox when committing naturally (not by CommitOnFocusLost).

maybe rewriting the check to commit on focus lost only if there is new committable text and remove the early-return check on Commit().

@bdach
Copy link
Collaborator

bdach commented Feb 22, 2020

OK, I agree, if those behaviours are separate they do make more sense, but the double commit still does not. Still a matter for a separate PR, with proper tests and documentation.

@frenzibyte
Copy link
Member Author

OK, I agree, if those behaviours are separate they do make more sense, but the double commit still does not. Still a matter for a separate PR, with proper tests and documentation.

I don't think tests are needed, it's a matter of code quality. I'm pretty sure documentation isn't even needed after separating the checks. (you'll see)

@bdach
Copy link
Collaborator

bdach commented Feb 22, 2020

The publicly-exposed flags steer behaviour the stability of which is important to framework consumers, therefore I'd say it needs to be covered with tests to avoid regressions (which, FWIW, goes for as much public framework API as possible).

Salman Ahmed added 3 commits June 4, 2020 20:09
This would allow for better invoking OnTextAdded(...) and OnTextRemoved(...) without introducing more unnecessary parameters (like suppressing event invokes)
@pull-request-size pull-request-size bot added size/L and removed size/M labels Jun 4, 2020
…ction

*I have an issue with writing which direction I'm imagining...*
@frenzibyte
Copy link
Member Author

@bdach I've resolved the double-commit fuzz with an internal OnTextCommitted(...) event handler for simplicity.

I've also merged addCharacter() to InsertString() and made removeCharacterOrSelection() accept removing more than one character for simplifying IME logic and centralize event invocations of text changes.

Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR overall is really difficult in reviewing. There are changes all over and it's hard for me to confidently arrive at the conclusion that this won't break things.

@frenzibyte
Copy link
Member Author

This PR overall is really difficult in reviewing. There are changes all over and it's hard for me to confidently arrive at the conclusion that this won't break things.

OK I will split all changes into separate PRs, although I put them here just for them to make sense where they belong, but sure if it helps reviewing.

@frenzibyte
Copy link
Member Author

frenzibyte commented Jun 22, 2020

Will leave this unchanged until the prerequisites are merged, then I'm gonna resolve conflicts afterwards.

@peppy
Copy link
Member

peppy commented Jul 9, 2020

Could do with some conflict resolution now.

@pull-request-size pull-request-size bot added size/M and removed size/L labels Jul 9, 2020
Salman Ahmed added 2 commits July 9, 2020 08:46
@peppy
Copy link
Member

peppy commented Jul 10, 2020

Would have been nice to have some very simple test coverage of these events, but I guess it's fine as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants