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

Ports the associated phrases feature from the macOS version #107

Merged
merged 16 commits into from
Jan 25, 2024
Merged

Ports the associated phrases feature from the macOS version #107

merged 16 commits into from
Jan 25, 2024

Conversation

zonble
Copy link
Collaborator

@zonble zonble commented Jan 17, 2024

A new settings is added. When the setting is on, a user can see a menu of associated phrases menu each time enter a character in the Plain Bopomofo mode. He or she can also trigger associated phrases using the shift + enter key in the McBopomofo mode.

@zonble zonble requested a review from lukhnos January 17, 2024 15:45
Copy link
Collaborator

@lukhnos lukhnos left a comment

Choose a reason for hiding this comment

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

LGTM overall. I made some comments re the C++ coding convention, and please take a look at #108, since I discovered a crasher due to KeyHandler's using the state callback twice while handing the candidate event for plain Bopomofo mode when associated phrases are enabled.

@@ -27,7 +27,9 @@
#include <array>
#include <cassert>
#include <cstdint>
#include <functional>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you also bring the diff in reading_grid_test.cpp to here so that we can make sure 'findInSpan` has its proper test coverage?

src/InputState.h Outdated
@@ -84,6 +84,10 @@ struct Inputting : NotEmpty {
Inputting(const std::string& buf, const size_t index,
const std::string_view& tooltipText = "")
: NotEmpty(buf, index, tooltipText) {}

std::unique_ptr<Inputting> copy() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer creating a copy constructor and then call std::make_unque<T> at the call site, so that we don't need to depend on std::unique_ptr<T> here:

Inputting(const Inputting& o) : NotEmpty(o.buf, o.index, o.tooltipText) {}

std::string phrase =
candidateList->candidate(selectedIndex).text().toString();
#endif
choosingCandidate->candidates[selectedCandidateIndex].value;
std::unique_ptr<InputStates::ChoosingCandidate> copy =
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you have the copy constructor, then you can do this:

auto copy = std::make_unique<InputStates::ChoosingCandidate>(*choosingCandidate);

std::unique_ptr<InputStates::AssociatedPhrasesPlain> newState =
buildAssociatedPhrasesPlainState(value);
if (newState != nullptr) {
stateCallback(std::move(newState));
Copy link
Collaborator

Choose a reason for hiding this comment

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

The stateCallback is no longer valid (it's now a const reference to a dangling object) because the commit state above will cause the candidate object (which owns the callback object) to be destoryed.

Please review #108; once it's merged, please merge with the mainline so that this will work safely.

@@ -76,6 +76,10 @@ class KeyHandler {
const InputStates::ChoosingCandidate::Candidate& candidate,
const StateCallback& stateCallback);

void candidateAssociatedPhraseSelected(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Due to the issue discovered in #108, please make the callback parameter StateCallback stateCallback instead of const StateCallback& stateCallback).

@@ -118,5 +118,39 @@ std::string SubstringToCodePoints(const std::string& s, size_t cp) {
return {s.cbegin(), i};
}

std::string GetCodePoint(const std::string& s, size_t cp) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we add some tests for this function and the Split function below?

Copy link
Collaborator

@lukhnos lukhnos left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@lukhnos lukhnos merged commit 6ee1c1d into openvanilla:master Jan 25, 2024
3 checks passed
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.

2 participants