Closed ShengYenPeng closed 8 years ago
the reason is that I just enter phrase and leave empty in bopomofo, so the phrase is pushed into ctx.
after I click refresh then the phrase is added into list.
but I think it could add phrase without bopomofo after clicking OK
Now can only add phrase by giving both phrase and bopomofo. See https://github.com/chewing/chewing-editor/issues/2
Chewing can automatically remember phrases when you are typing. You thought that you added the phrase without bopomofo successfully because you could see it after refreshing the list. But maybe it just failed and you loaded the same phrase remembered by itself (not added from chewing-editor).
@ShengYenPeng see https://github.com/chewing/chewing-editor/issues/94
ok, thanks!
I think now that we can add phrase just by typing, we should let chewing-editor have same behavior, because typing bopomofo is very time-consuming. If editor found that user don't type bopomofo, maybe it can call API in libchewing to return bopomofo.
or the simplest idea is that if editor found that no bopomofo, just call refresh, so that the phrase would be added into list by libchewing.
If editor found that user don't type bopomofo, maybe it can call API in libchewing to return bopomofo.
See https://github.com/chewing/libchewing/issues/143
or the simplest idea is that if editor found that no bopomofo, just call refresh, so that the phrase would be added into list by libchewing.
But it's not always become into one phrase. Maybe "蜘蛛人" you typed will become "蜘蛛" and "人", it's not the phrase wanted by user.
ok, I got it.
thanks!
Hi @david50407 ,
According to chewing can automatically remember phrases when you are typing and refresh will push back these phrase into chewing-list, I think I can use the phrase in the bottom of chewing-list to create the phrase that I want add.
I wrote some code into add function in UserphraseModel.cpp, and it seems works.
if (ret > 0) {
emit beginResetModel();
userphrase_.insert(Userphrase{
phrase,
bopomofo
});
emit endResetModel();
emit addNewPhraseCompleted(userphrase_[userphrase_.size()-1]);
} else {
qWarning() << "chewing_userphrase_add() returns" << ret;
//---------- NEW ( add userphrase without bopomofo) ------------------
// refresh to make related phrase inserted into bottom of chewing-editor list
refresh();
int newPhrasePos = phrase.size()-1;
QString tmpBopomofo;
int idx = userphrase_.size()-1;
bool foundMatchPhrase = false;
//iterative searching correct phrase in userphrase list and add record bopomofo
while(newPhrasePos >=0 ){
foundMatchPhrase = false;
idx = userphrase_.size()-1;
//searching correct phrase
while( foundMatchPhrase == false ){
QString comparePhrase = userphrase_[idx].phrase_;
if( comparePhrase.size() > newPhrasePos+ 1)
{
--idx;
continue;
}
for( int phraseShift= 0 ; phraseShift < comparePhrase.size() ; ++phraseShift ){
if( phrase[newPhrasePos - phraseShift ] != comparePhrase[ comparePhrase.size() -1-phraseShift ] ){
--idx;
break;
}
else if( phrase[newPhrasePos - phraseShift ] == comparePhrase[ comparePhrase.size() -1-phraseShift ] && phraseShift == comparePhrase.size()-1 )
foundMatchPhrase = true;
}
}
// recording bopomofo
if( newPhrasePos == phrase.size() -1)
tmpBopomofo=userphrase_[idx].bopomofo_;
else
tmpBopomofo = userphrase_[idx].bopomofo_+" "+tmpBopomofo;
newPhrasePos -= userphrase_[idx].phrase_.size();
}
//add
if( newPhrasePos == - 1 & phrase.size() != 0)
{
add( phrase , tmpBopomofo );
}
//--------------------------------------------
}
example:
I found that the code can't handle the invalid phrase like: "哈囉a", and the chewing-editor would crash...
Please always clip your screenshots. We would crop pictures to concentrate on major difference.
OK! I modified the screenshots.
Hi,
I add new userphrase via "Add new phrase",
and I think the new phrase should appear in the list after I click "OK", but I should click refresh button to make new phrase appear now.
The delete button works well, it just delete phrase after I delete, I don't need to click refresh button to make phrase disappear.