Skip to content

Commit

Permalink
Merge pull request #226 from chewing/fix-end-composition-on-blur
Browse files Browse the repository at this point in the history
fix: end composition and hide windows on blur
  • Loading branch information
kanru authored Dec 21, 2024
2 parents d22da83 + 997732e commit 03cb8ca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
25 changes: 17 additions & 8 deletions ChewingTextService/ChewingTextService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,27 @@ void TextService::onDeactivate() {
freeChewingContext();

hideMessage();

if(candidateWindow_) {
showingCandidates_ = false;
candidateWindow_ = nullptr;
}
hideCandidates();
}

// virtual
void TextService::onFocus() {
}

// virtual
void TextService::onKillFocus() {
if (isComposing()) {
// end current composition if needed
ITfContext* context = currentContext();
if (context) {
endComposition(context);
context->Release();
}
}
hideCandidates();
hideMessage();
}

// virtual
bool TextService::filterKeyDown(Ime::KeyEvent& keyEvent) {
Config& cfg = config();
Expand Down Expand Up @@ -647,8 +657,7 @@ void TextService::onKeyboardStatusChanged(bool opened) {
context->Release();
}
}
if(showingCandidates()) // disable candidate window if it's opened
hideCandidates();
hideCandidates();
hideMessage(); // hide message window, if there's any
freeChewingContext(); // IME is closed, chewingContext is not needed
}
Expand Down Expand Up @@ -862,8 +871,8 @@ void TextService::showCandidates(Ime::EditSession* session) {

// hide candidate list window
void TextService::hideCandidates() {
assert(candidateWindow_);
if(candidateWindow_) {
candidateWindow_->hide();
candidateWindow_ = nullptr;
}
showingCandidates_ = false;
Expand Down
1 change: 1 addition & 0 deletions ChewingTextService/ChewingTextService.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TextService: public Ime::TextService {
virtual void onDeactivate();

virtual void onFocus();
virtual void onKillFocus();

virtual bool filterKeyDown(Ime::KeyEvent& keyEvent);
virtual bool onKeyDown(Ime::KeyEvent& keyEvent, Ime::EditSession* session);
Expand Down
13 changes: 7 additions & 6 deletions libIME/TextService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,8 @@ STDMETHODIMP TextService::QueryInterface(REFIID riid, void **ppvObj) {
*ppvObj = (ITfTextInputProcessor*)this;
else if(IsEqualIID(riid, IID_ITfTextInputProcessorEx))
*ppvObj = (ITfTextInputProcessorEx*)this;
//else if(IsEqualIID(riid, IID_ITfThreadMgrEventSink))
// *ppvObj = (ITfThreadMgrEventSink*)this;
else if(IsEqualIID(riid, IID_ITfThreadMgrEventSink))
*ppvObj = (ITfThreadMgrEventSink*)this;
else if(IsEqualIID(riid, IID_ITfTextEditSink))
*ppvObj = (ITfTextEditSink*)this;
else if(IsEqualIID(riid, IID_ITfKeyEventSink))
Expand Down Expand Up @@ -820,6 +820,11 @@ STDMETHODIMP TextService::OnUninitDocumentMgr(ITfDocumentMgr *pDocMgr) {
}

STDMETHODIMP TextService::OnSetFocus(ITfDocumentMgr *pDocMgrFocus, ITfDocumentMgr *pDocMgrPrevFocus) {
if(pDocMgrFocus != nullptr) {
onSetFocus();
} else {
onKillFocus();
}
return S_OK;
}

Expand Down Expand Up @@ -876,10 +881,6 @@ STDMETHODIMP TextService::OnEndEdit(ITfContext *pContext, TfEditCookie ecReadOnl

// ITfKeyEventSink
STDMETHODIMP TextService::OnSetFocus(BOOL fForeground) {
if(fForeground)
onSetFocus();
else
onKillFocus();
return S_OK;
}

Expand Down

0 comments on commit 03cb8ca

Please sign in to comment.