From 5664481cc9ddd28db35c3155f7ddf83a55b65275 Mon Sep 17 00:00:00 2001 From: nameoverflow Date: Fri, 13 Apr 2018 23:58:09 +0800 Subject: [PATCH] fix(tsf): use `ITfContext::GetSelection` to get cursor position avoid any insertion which could active document focus fix #193, #194 --- WeaselTSF/Composition.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/WeaselTSF/Composition.cpp b/WeaselTSF/Composition.cpp index ef3454825..bf3f282ec 100644 --- a/WeaselTSF/Composition.cpp +++ b/WeaselTSF/Composition.cpp @@ -153,12 +153,13 @@ STDAPI CGetTextExtentEditSession::DoEditSession(TfEditCookie ec) ITfRange *pRangeComposition = NULL; RECT rc; BOOL fClipped; - if ((_pContext->QueryInterface(IID_ITfInsertAtSelection, (LPVOID *) &pInsertAtSelection)) != S_OK) + TF_SELECTION selection; + ULONG nSelection; + if (FAILED(_pContext->QueryInterface(IID_ITfInsertAtSelection, (LPVOID *) &pInsertAtSelection))) goto Exit; - if ((pInsertAtSelection->InsertTextAtSelection(ec, TF_IAS_QUERYONLY, NULL, 0, &pRangeComposition)) != S_OK) + if (FAILED(_pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &selection, &nSelection))) goto Exit; - - if ((_pContextView->GetTextExt(ec, pRangeComposition, &rc, &fClipped)) == S_OK && (rc.left != 0 || rc.top != 0)) + if ((_pContextView->GetTextExt(ec, selection.range, &rc, &fClipped)) == S_OK && (rc.left != 0 || rc.top != 0)) _pTextService->_SetCompositionPosition(rc); Exit: