Skip to content

Commit

Permalink
fix: async editing flicker, esp example in Word 365(#1155)
Browse files Browse the repository at this point in the history
* attempt to fix async editing.

* Update KeyEventSink.cpp: fix typo

* DestroyWindow after click_to_select callback called, avoid memory leaking
  • Loading branch information
fxliang authored Apr 21, 2024
1 parent f877364 commit 0544104
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
7 changes: 4 additions & 3 deletions WeaselTSF/Composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void WeaselTSF::_StartComposition(com_ptr<ITfContext> pContext,
if (pStartCompositionEditSession != nullptr) {
HRESULT hr;
pContext->RequestEditSession(_tfClientId, pStartCompositionEditSession,
TF_ES_SYNC | TF_ES_READWRITE, &hr);
TF_ES_ASYNCDONTCARE | TF_ES_READWRITE, &hr);
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@ void WeaselTSF::_EndComposition(com_ptr<ITfContext> pContext, BOOL clear) {
if ((pEditSession = new CEndCompositionEditSession(
this, pContext, _pComposition, clear)) != NULL) {
pContext->RequestEditSession(_tfClientId, pEditSession,
TF_ES_SYNC | TF_ES_READWRITE, &hr);
TF_ES_ASYNCDONTCARE | TF_ES_READWRITE, &hr);
pEditSession->Release();
}
}
Expand Down Expand Up @@ -222,7 +222,7 @@ BOOL WeaselTSF::_UpdateCompositionWindow(com_ptr<ITfContext> pContext) {
}
HRESULT hr;
pContext->RequestEditSession(_tfClientId, pEditSession,
TF_ES_SYNC | TF_ES_READ, &hr);
TF_ES_ASYNCDONTCARE | TF_ES_READ, &hr);
return SUCCEEDED(hr);
}

Expand Down Expand Up @@ -384,6 +384,7 @@ void WeaselTSF::_UpdateComposition(com_ptr<ITfContext> pContext) {

_pEditSessionContext->RequestEditSession(
_tfClientId, this, TF_ES_ASYNCDONTCARE | TF_ES_READWRITE, &hr);
_async_edit = !!(hr == TF_S_ASYNC);
_UpdateCompositionWindow(pContext);
}

Expand Down
3 changes: 2 additions & 1 deletion WeaselTSF/KeyEventSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ STDAPI WeaselTSF::OnKeyUp(ITfContext* pContext,
*pfEaten = TRUE;
} else {
_ProcessKeyEvent(wParam, lParam, pfEaten);
_UpdateComposition(pContext);
if (!_async_edit)
_UpdateComposition(pContext);
}
return S_OK;
}
Expand Down
1 change: 1 addition & 0 deletions WeaselTSF/WeaselTSF.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,5 @@ class WeaselTSF : public ITfTextInputProcessorEx,

// guidatom for the display attibute.
TfGuidAtom _gaDisplayAttributeInput;
BOOL _async_edit = false;
};
4 changes: 3 additions & 1 deletion WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ LRESULT WeaselPanel::OnLeftClickedUp(UINT uMsg,
rect.InflateRect(m_style.hilite_padding_x, m_style.hilite_padding_y);
if (rect.PtInRect(point)) {
size_t i = m_ctx.cinfo.highlighted;
if (_UICallback)
if (_UICallback) {
_UICallback(&i, NULL, NULL, NULL);
DestroyWindow();
}
} else {
RedrawWindow();
}
Expand Down

0 comments on commit 0544104

Please sign in to comment.