Skip to content
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

Simplify ResizingTextEdit::isFirstWord to avoid invalid QString index warnings #3285

Merged
merged 5 commits into from
Oct 16, 2021

Conversation

zneix
Copy link
Collaborator

@zneix zneix commented Oct 15, 2021

Pull request checklist:

  • CHANGELOG.md was updated, if applicable

Description

As pointed out in #3234 (comment) I've localized the issue and fixed it.
Turns out that our complicated logic with iterating over QTextEdit's plainText and checking whether it contains space or not can be just replaced with a simple QString::contains which does exactly the same thing as our function did before.
While this might be a bit silly logic for detecting a first word, this is something to think of in the future, not something I'm focusing on approaching in this PR.

I've confirmed it Fixes #3234

@zneix zneix requested review from fourtf, Mm2PL and pajlada October 15, 2021 11:05
@zneix
Copy link
Collaborator Author

zneix commented Oct 15, 2021

Considering this warning/bug was quite annoying, noticed by quite some ppl and also breaking for Qt6 builds I've decided to put a changelog entry for it.

Copy link
Collaborator

@Mm2PL Mm2PL left a comment

Choose a reason for hiding this comment

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

looks good to me, BroBalt

@zneix zneix removed the request for review from fourtf October 15, 2021 19:26
@pajlada
Copy link
Member

pajlada commented Oct 16, 2021

Initial fix didn't account for the feature where if you move your cursor to the start an already started message: <CURSOR> hello!! and type @pajl and press tab, it would include a comma since it was autocompleting as the first word.

The commit I added brings that feature back while keeping the improved (and much simpler) check

Example variable values:
Input box: Hello @pajl<CURSOR>
plainText: Hello @pajl
portionBeforeCursor: Hello @pajl
Autocompleting will insert @pajlada

Input box: Hello @pajl<CURSOR>xD
plainText: Hello @pajlxD
portionBeforeCursor: Hello @pajl
Autocompleting will insert @pajlada

Input box: @pajl<CURSOR> Hello xD
plainText: @pajl Hello xD
portionBeforeCursor: @pajl
Autocompleting will insert @pajlada,

@zneix
Copy link
Collaborator Author

zneix commented Oct 16, 2021

Thanks so much for noticing my oversight and making a comment covering it 👍

@zneix zneix enabled auto-merge (squash) October 16, 2021 10:54
@zneix zneix merged commit 2bd05fd into master Oct 16, 2021
@zneix zneix deleted the zneix/fix/qcharref-bug branch October 16, 2021 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QCharRef with an index pointing outside the valid range of a QString warning
3 participants