-
Notifications
You must be signed in to change notification settings - Fork 718
feat: Support overriding language ID of the text emitted #1837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,10 +14,9 @@ Configurator::~Configurator() {} | |
|
|
||
| void Configurator::Store(Deserializer::KeyType const& key, | ||
| std::wstring const& value) { | ||
| if (!m_pTarget->p_context || key.size() < 2) | ||
| if (!m_pTarget->p_config || key.size() < 2) | ||
| return; | ||
| bool bool_value = (!value.empty() && value != L"0"); | ||
| if (key[1] == L"inline_preedit") { | ||
| m_pTarget->p_config->inline_preedit = bool_value; | ||
| if (key[1] == L"commit_langid") { | ||
| m_pTarget->p_config->commit_langid = _wtoi(value.c_str()); | ||
| } | ||
|
Comment on lines
15
to
21
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,26 @@ BOOL WeaselTSF::_SetCompositionDisplayAttributes(TfEditCookie ec, | |
| return (hr == S_OK); | ||
| } | ||
|
|
||
| BOOL WeaselTSF::_SetRangeLanguage(TfEditCookie ec, | ||
| _In_ ITfContext* pContext, | ||
| ITfRange* pRange) { | ||
| if (!pRange || !_textLangId) | ||
| return FALSE; | ||
|
|
||
| ITfProperty* pLangIdProperty = nullptr; | ||
| HRESULT hr = E_FAIL; | ||
|
|
||
| if (SUCCEEDED(pContext->GetProperty(GUID_PROP_LANGID, &pLangIdProperty))) { | ||
| VARIANT var; | ||
| var.vt = VT_I4; | ||
| var.lVal = _textLangId; | ||
| hr = pLangIdProperty->SetValue(ec, pRange, &var); | ||
| pLangIdProperty->Release(); | ||
|
Comment on lines
+64
to
+69
|
||
| } | ||
|
|
||
| return hr == S_OK; | ||
| } | ||
|
|
||
| BOOL WeaselTSF::_InitDisplayAttributeGuidAtom() { | ||
| ITfCategoryMgr* pCategoryMgr = nullptr; | ||
| HRESULT hr = | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,12 +16,14 @@ STDAPI WeaselTSF::DoEditSession(TfEditCookie ec) { | |||||||||
| _UpdateLanguageBar(_status); | ||||||||||
|
|
||||||||||
| if (ok) { | ||||||||||
| bool inline_preedit = _cand->style().inline_preedit; | ||||||||||
| _textLangId = static_cast<LANGID>(config.commit_langid); | ||||||||||
|
||||||||||
| _textLangId = static_cast<LANGID>(config.commit_langid); | |
| if (config.commit_langid >= 0 && config.commit_langid <= 0xFFFF) { | |
| _textLangId = static_cast<LANGID>(config.commit_langid); | |
| } |
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_textLangId is stored as a mutable WeaselTSF member, but the actual language assignment happens later in separately requested (potentially async) edit sessions (_StartComposition/_InsertText/_ShowInlinePreedit). If multiple edit sessions are queued, _textLangId can be overwritten before those sessions run, causing the wrong LANGID to be applied to the range. Consider capturing the langid per edit-session instance (store it in the edit session object) or applying the GUID_PROP_LANGID value within the same edit session that sets the text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TryGetLangIdFromConfig writes the resulting LANGID into an int without any bounds/type enforcement. Since this value is later serialized over IPC and cast to LANGID, it’s safer to explicitly constrain it to 0..0xFFFF (and treat 0 as “not set”) before storing/sending.