-
Notifications
You must be signed in to change notification settings - Fork 206
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
gh-750: Fixed VMenu
set selection behavior around list edges.
#751
Conversation
41e5b38
to
8ab060e
Compare
@alabuzhev, could you please have a look? The PR is ready for review. "Bugs are expected" because the logic around the |
8ab060e
to
a4d3e26
Compare
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.
Looks like the problematic behavior, described in #750, still occurs in some other places, e.g. User Menu, supposedly because deletion is handled separately there.
We probably should review and fix all such places (not necessarily under the same issue).
I see Michael continues using PascalCase for new and refactored methods, whereas Alex is transitioning to underscore_case. @alabuzhev what are the rules you use? I had an impression that we have to adopt underscore_case for both refactored methods and fresh code. |
@yegor-mialyk I try to follow this naming style:
It's not enforced anywhere though. |
To be clear, do you want me to rename the functions (and maybe some other things)? I do not mind, just wanted to make sure this is how you want them to be. |
Up to you, I was just answering Yegor's question. |
Yes, let's wait for beta-testers' complaints. Could you please create a bug for User Menu and assign it to myself? |
0167066
to
029bc93
Compare
I squashed the commits and made it ready for merge, but if there are more issues, I'll be happy to fix them. |
029bc93
to
bcac237
Compare
Another attempt. :) |
bcac237
to
60233a0
Compare
As an aside (not pushing it now). This is how it should be done:-int find_nearest(std::ranges::contiguous_range auto const& Range, const int Pos, const auto Pred, const bool GoBackward, const bool DoWrap)
+int find_nearest(std::ranges::contiguous_range auto const& Range, const int Pos, auto&& Pred, const bool GoBackward, const
bool DoWrap)
{
using namespace std::views;
assert(0 <= Pos && Pos < static_cast<int>(Range.size()));
+ const auto Filter = filter(FWD(Pred));
const auto FindPos =
[&](const auto First, const auto Second)
{
const auto FindPosPart =
[&](const auto Part)
{
- if (auto Filtered = Range | Part | filter(Pred))
+ if (auto Filtered = Range | Part | Filter)
return static_cast<int>(&Filtered.front() - Range.data());
return -1;
};
if (const auto Found{ FindPosPart(First) }; Found != -1) return Found;
if (const auto Found{ FindPosPart(Second) }; Found != -1) return Found;
return -1;
};
return GoBackward
? (DoWrap
? FindPos(take(Pos + 1) | reverse, drop(Pos + 1) | reverse)
: FindPos(take(Pos + 1) | reverse, drop(Pos + 1)))
: (DoWrap
? FindPos(drop(Pos), take(Pos))
: FindPos(drop(Pos), take(Pos) | reverse));
} |
60233a0
to
df5a97e
Compare
Rebased to the latest master. |
Warning! Bugs are expected.
df5a97e
to
0b6156a
Compare
Ping |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Looks good, let's merge if you have nothing to add. |
Thanks for the pointer, I'll watch later. Thank you for merging. No, I was not going to apply forwarding of the predicate; just posted the "right" pattern (to the best of my understanding). It does not matter here, just something to be aware of if we go ranges. BTW, what I really wanted to do was to join the two |
[Tagging @alabuzhev just because the PR is already merged (thank you), and he may overlook the comment.]
I think that the word "cache" here is misleading. A view is an iterator and a sentinel, nothing more, nothing less. We all know the rules about (invalidating) iterators. The same applies to views. It is that simple. Is it a good design? It depends. As it often happens with C++, this design provides for runtime performance, particularly through avoiding indirections. The price is cognitive burden imposed on the programmer. Views do not cache anything. They just wrap an iterator-sentinel pair in a convenient and safe object. When using views, one cannot, syntactically, match an iterator against a wrong sentinel. It's a huge advantage over the traditional C++ iterators. Do we need more? Probably. Will we have it? Hopefully. The very word "view" is a misnomer. In C#, to denote a similar thing, they use the apt word "enumerable." C# enumerables have pretty much the same issue as C++ views, and nobody complains. Except for everyone who starts using them experiences a few pretty dramatic setbacks. But overall, the right word sets the right expectations, and people learn to grab enumerables at the right end. And in C#, enumerable are outrageously expensive, at least from C++ perspective. They are roughly equivalent to C++ |
Summary
Warning! Bugs are expected.
At the very least, deleting the last entry in the view/edit history works as expected.
References
gh-750
Checklist
If not checked, I accept that this work might be rejected in favor of a different great big ineffable plan.
Details
I've rewritten substantial part of
VMenu::SetSelectPos
because the logic was complicated and looked as if it compensated for something which had since disappeared.Let's see what I broke.