-
Notifications
You must be signed in to change notification settings - Fork 563
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
feat(language): shared user dictionary per language (Closes #184) #214
Changes from 1 commit
f9f9976
91775a6
db519e6
4c2aa3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,10 @@ bool Memory::DiscardSession() { | |
return user_dict_ && user_dict_->RevertRecentTransaction(); | ||
} | ||
|
||
const Language* Memory::language() const { | ||
return user_dict_ ? user_dict_->language() : nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为什么 language 可以为空值? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 更新了更新了~ |
||
} | ||
|
||
void Memory::OnCommit(Context* ctx) { | ||
if (!user_dict_|| user_dict_->readonly()) | ||
return; | ||
|
@@ -100,7 +104,7 @@ void Memory::OnCommit(Context* ctx) { | |
for (auto& seg : ctx->composition()) { | ||
auto phrase = As<Phrase>(Candidate::GetGenuineCandidate( | ||
seg.GetSelectedCandidate())); | ||
bool recognized = phrase && phrase->language() == language(); | ||
bool recognized = Language::intelligible(phrase, this); | ||
if (recognized) { | ||
commit_entry.AppendPhrase(phrase); | ||
} | ||
|
@@ -119,8 +123,7 @@ void Memory::OnDeleteEntry(Context* ctx) { | |
return; | ||
auto phrase = As<Phrase>(Candidate::GetGenuineCandidate( | ||
ctx->GetSelectedCandidate())); | ||
bool recognized = phrase && phrase->language() == language(); | ||
if (recognized) { | ||
if (Language::intelligible(phrase, this)) { | ||
const DictEntry& entry(phrase->entry()); | ||
LOG(INFO) << "deleting entry: '" << entry.text << "'."; | ||
user_dict_->UpdateEntry(entry, -1); // mark as deleted in user dict | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Copyright RIME Developers | ||
// Distributed under the BSD License | ||
// | ||
#ifndef RIME_LANGUAGE_H_ | ||
#define RIME_LANGUAGE_H_ | ||
|
||
#include <rime/common.h> | ||
|
||
namespace rime { | ||
|
||
class Language { | ||
const string name_; | ||
|
||
public: | ||
Language(const string& name) : name_(name) {} | ||
string name() const { return name_; } | ||
|
||
bool operator== (const Language& other) const { | ||
return name_ == other.name_; | ||
} | ||
|
||
template <class T, class U> | ||
static bool intelligible(const T& t, const U& u) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 有没有办法给 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 講究。你當是寫 Rust? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 有道理 |
||
return t->language() && u->language() && *t->language() == *u->language(); | ||
} | ||
}; | ||
|
||
} // namespace rime | ||
|
||
#endif // RIME_LANGUAGE_H_ |
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.
从 L500 以后
dict_name
变量实际已经变成language_name
之类了?是不是应该使用新的命名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.
我又改回去了。
Language
改成在Memory
類裏創建。這裏求「語言」名字還是爲了給用戶詞典取名。