forked from rime/weasel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(composition): improve compositions and edit sessions (rime#146)
* fix(composition): update compositions in edit session * fix(composition): insert commit text by set range text
- Loading branch information
1 parent
16c163a
commit fbdb667
Showing
4 changed files
with
112 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,45 @@ | ||
#include "stdafx.h" | ||
#include "WeaselTSF.h" | ||
#include "ResponseParser.h" | ||
|
||
STDAPI WeaselTSF::DoEditSession(TfEditCookie ec) | ||
{ | ||
ITfInsertAtSelection *pInsertAtSelection; | ||
ITfRange *pRange; | ||
TF_SELECTION tfSelection; | ||
// get commit string from server | ||
std::wstring commit; | ||
weasel::Status status; | ||
weasel::Config config; | ||
|
||
if (_pEditSessionContext->QueryInterface(IID_ITfInsertAtSelection, (LPVOID *) &pInsertAtSelection) != S_OK) | ||
return E_FAIL; | ||
auto context = std::make_shared<weasel::Context>(); | ||
|
||
/* insert the text */ | ||
if (pInsertAtSelection->InsertTextAtSelection(ec, 0, _editSessionText.c_str(), _editSessionText.length(), &pRange) != S_OK) | ||
{ | ||
pInsertAtSelection->Release(); | ||
return E_FAIL; | ||
} | ||
|
||
/* update the selection to an insertion point just past the inserted text. */ | ||
pRange->Collapse(ec, TF_ANCHOR_END); | ||
|
||
tfSelection.range = pRange; | ||
tfSelection.style.ase = TF_AE_NONE; | ||
tfSelection.style.fInterimChar = FALSE; | ||
weasel::ResponseParser parser(&commit, context.get(), &status, &config); | ||
|
||
_pEditSessionContext->SetSelection(ec, 1, &tfSelection); | ||
bool ok = m_client.GetResponseData(std::ref(parser)); | ||
|
||
pRange->Release(); | ||
pInsertAtSelection->Release(); | ||
|
||
return S_OK; | ||
if (ok) | ||
{ | ||
if (!commit.empty()) | ||
{ | ||
// For auto-selecting, commit and preedit can both exist. | ||
// Commit and close the original composition first. | ||
if (!_IsComposing()) { | ||
_StartComposition(_pEditSessionContext, _fCUASWorkaroundEnabled && !config.inline_preedit); | ||
} | ||
_InsertText(_pEditSessionContext, commit); | ||
_EndComposition(_pEditSessionContext, false); | ||
} | ||
if (status.composing && !_IsComposing()) | ||
{ | ||
_StartComposition(_pEditSessionContext, _fCUASWorkaroundEnabled && !config.inline_preedit); | ||
} | ||
else if (!status.composing && _IsComposing()) | ||
{ | ||
_EndComposition(_pEditSessionContext, true); | ||
} | ||
if (_IsComposing() && config.inline_preedit) | ||
{ | ||
_ShowInlinePreedit(_pEditSessionContext, context); | ||
} | ||
} | ||
return TRUE; | ||
} | ||
|
||
BOOL WeaselTSF::_InsertText(ITfContext *pContext, const std::wstring& text) | ||
{ | ||
HRESULT hr; | ||
|
||
_pEditSessionContext = pContext; | ||
_editSessionText = text; | ||
|
||
if (_pEditSessionContext->RequestEditSession(_tfClientId, this, TF_ES_ASYNCDONTCARE | TF_ES_READWRITE, &hr) != S_OK || hr != S_OK) | ||
return FALSE; | ||
|
||
return TRUE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters