Skip to content

Commit

Permalink
Merge pull request #108 from openvanilla/dev/fix-dangling-objects
Browse files Browse the repository at this point in the history
Use values, not references, when passing callbacks
  • Loading branch information
zonble authored Jan 21, 2024
2 parents a892883 + 621a0fc commit d1bb925
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
15 changes: 7 additions & 8 deletions src/KeyHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ KeyHandler::KeyHandler(
}

bool KeyHandler::handle(Key key, McBopomofo::InputState* state,
const StateCallback& stateCallback,
const ErrorCallback& errorCallback) {
StateCallback stateCallback,
ErrorCallback errorCallback) {
// From Key's definition, if shiftPressed is true, it can't be a simple key
// that can be represented by ASCII.
char simpleAscii = (key.ctrlPressed || key.shiftPressed) ? '\0' : key.ascii;
Expand Down Expand Up @@ -431,7 +431,7 @@ bool KeyHandler::handle(Key key, McBopomofo::InputState* state,

void KeyHandler::candidateSelected(
const InputStates::ChoosingCandidate::Candidate& candidate,
const StateCallback& stateCallback) {
StateCallback stateCallback) {
if (inputMode_ == InputMode::PlainBopomofo) {
reset();
std::unique_ptr<InputStates::Committing> committingState =
Expand All @@ -446,12 +446,12 @@ void KeyHandler::candidateSelected(

void KeyHandler::dictionaryServiceSelected(std::string phrase, size_t index,
InputState* currentState,
const StateCallback& stateCallback) {
StateCallback stateCallback) {
dictionaryServices_->lookup(std::move(phrase), index, currentState,
stateCallback);
}

void KeyHandler::candidatePanelCancelled(const StateCallback& stateCallback) {
void KeyHandler::candidatePanelCancelled(StateCallback stateCallback) {
if (inputMode_ == InputMode::PlainBopomofo) {
reset();
std::unique_ptr<InputStates::EmptyIgnoringPrevious>
Expand All @@ -465,9 +465,8 @@ void KeyHandler::candidatePanelCancelled(const StateCallback& stateCallback) {
}

bool KeyHandler::handleCandidateKeyForTraditionalBopomofoIfRequired(
Key key,
const SelectCurrentCandidateCallback& SelectCurrentCandidateCallback,
const StateCallback& stateCallback, const ErrorCallback& errorCallback) {
Key key, SelectCurrentCandidateCallback SelectCurrentCandidateCallback,
StateCallback stateCallback, ErrorCallback errorCallback) {
if (inputMode_ != McBopomofo::InputMode::PlainBopomofo) {
return false;
}
Expand Down
14 changes: 6 additions & 8 deletions src/KeyHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,24 @@ class KeyHandler {
// the key should be absorbed, signaling that the key is accepted and handled,
// or false if the event should be let pass through.
bool handle(Key key, McBopomofo::InputState* state,
const StateCallback& stateCallback,
const ErrorCallback& errorCallback);
StateCallback stateCallback, ErrorCallback errorCallback);

// Candidate selected. Can assume the context is in a candidate state.
void candidateSelected(
const InputStates::ChoosingCandidate::Candidate& candidate,
const StateCallback& stateCallback);
StateCallback stateCallback);

void dictionaryServiceSelected(std::string phrase, size_t index,
InputState* currentState,
const StateCallback& stateCallback);
StateCallback stateCallback);

// Candidate panel canceled. Can assume the context is in a candidate state.
void candidatePanelCancelled(const StateCallback& stateCallback);
void candidatePanelCancelled(StateCallback stateCallback);

// Workaround for the Traditional Bopomofo mode.
bool handleCandidateKeyForTraditionalBopomofoIfRequired(
Key key,
const SelectCurrentCandidateCallback& SelectCurrentCandidateCallback,
const StateCallback& stateCallback, const ErrorCallback& errorCallback);
Key key, SelectCurrentCandidateCallback SelectCurrentCandidateCallback,
StateCallback stateCallback, ErrorCallback errorCallback);

void reset();

Expand Down

0 comments on commit d1bb925

Please # to comment.