Skip to content

add OnProperty() for Navigator #626

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/rime/gear/navigator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ Navigator::Navigator(const Ticket& ticket)
Config* config = engine_->schema()->config();
LoadConfig(config, "navigator", Horizontal);
LoadConfig(config, "navigator/vertical", Vertical);
property_update_connection_ = engine_->context()->property_update_notifier().connect(
[this](Context* ctx, const string& property) {
OnPropertyUpdate(ctx, property);
});
}

Navigator::~Navigator() {
property_update_connection_.disconnect();
}

ProcessResult Navigator::ProcessKeyEvent(const KeyEvent& key_event) {
Expand Down Expand Up @@ -223,4 +231,36 @@ bool Navigator::GoToEnd(Context* ctx) {
return false;
}

void Navigator::OnPropertyUpdate(Context *ctx, const string &property) {
if (!ctx->IsComposing())
return;

if (property == "move_by_syllable") {
int num= stoi( ctx->get_property(property) );
if (num >0)
for (int i=0; i<num; i++)
RightBySyllable(ctx);
else if (num <0)
for (int i=0; i>num; i--)
LeftBySyllable(ctx);
}
else if (property == "_navigator") {
string cmd = ctx->get_property(property);
if (cmd == "rewind")
Rewind(ctx);
else if (cmd == "left_by_char")
LeftByChar(ctx);
else if (cmd == "right_by_char")
RightByChar(ctx);
else if (cmd == "left_by_syllable")
LeftBySyllable(ctx);
else if (cmd == "right_by_syllable")
RightBySyllable(ctx);
else if (cmd == "home")
Home(ctx);
else if (cmd == "end")
End(ctx);
}
}

} // namespace rime
4 changes: 4 additions & 0 deletions src/rime/gear/navigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Navigator : public Processor, public KeyBindingProcessor<Navigator, 2> {
};

explicit Navigator(const Ticket& ticket);
~Navigator();

ProcessResult ProcessKeyEvent(const KeyEvent& key_event) override;

Expand All @@ -42,9 +43,12 @@ class Navigator : public Processor, public KeyBindingProcessor<Navigator, 2> {
bool MoveRight(Context* ctx);
bool GoHome(Context* ctx);
bool GoToEnd(Context* ctx);
void OnPropertyUpdate(Context *ctx, const string& property);


string input_;
Spans spans_;
connection property_update_connection_;
};

} // namespace rime
Expand Down