Skip to content

Commit

Permalink
refactor: don't insert preinserted space when not inline_preedit
Browse files Browse the repository at this point in the history
Co-authored-by:  CDHJS <[email protected]>
  • Loading branch information
fxliang and CDHJS committed Jan 2, 2025
1 parent c599f2e commit 2e67b9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
26 changes: 5 additions & 21 deletions WeaselTSF/Composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ class CStartCompositionEditSession : public CEditSession {
public:
CStartCompositionEditSession(com_ptr<WeaselTSF> pTextService,
com_ptr<ITfContext> pContext,
BOOL fCUASWorkaroundEnabled,
BOOL inlinePreeditEnabled)
: CEditSession(pTextService, pContext),
_inlinePreeditEnabled(inlinePreeditEnabled) {
BOOL fCUASWorkaroundEnabled)
: CEditSession(pTextService, pContext) {
_fCUASWorkaroundEnabled = fCUASWorkaroundEnabled;
}

Expand All @@ -21,7 +19,6 @@ class CStartCompositionEditSession : public CEditSession {

private:
BOOL _fCUASWorkaroundEnabled;
BOOL _inlinePreeditEnabled;
};

STDAPI CStartCompositionEditSession::DoEditSession(TfEditCookie ec) {
Expand All @@ -45,22 +42,9 @@ STDAPI CStartCompositionEditSession::DoEditSession(TfEditCookie ec) {
(pComposition != NULL)) {
_pTextService->_SetComposition(pComposition);

/* WORKAROUND:
* CUAS does not provide a correct GetTextExt() position unless the
* composition is filled with characters. So we insert a zero width space
* here. The workaround is only needed when inline preedit is not enabled.
* See https://github.com/rime/weasel/pull/883#issuecomment-1567625762
*/
if (!_inlinePreeditEnabled) {
pRangeComposition->SetText(ec, TF_ST_CORRECTION, L" ", 1);
}

/* set selection */
TF_SELECTION tfSelection;
if (_inlinePreeditEnabled)
pRangeComposition->Collapse(ec, TF_ANCHOR_END);
else
pRangeComposition->Collapse(ec, TF_ANCHOR_START);
pRangeComposition->Collapse(ec, TF_ANCHOR_END);
tfSelection.range = pRangeComposition;
tfSelection.style.ase = TF_AE_NONE;
tfSelection.style.fInterimChar = FALSE;
Expand All @@ -73,8 +57,8 @@ STDAPI CStartCompositionEditSession::DoEditSession(TfEditCookie ec) {
void WeaselTSF::_StartComposition(com_ptr<ITfContext> pContext,
BOOL fCUASWorkaroundEnabled) {
com_ptr<CStartCompositionEditSession> pStartCompositionEditSession;
pStartCompositionEditSession.Attach(new CStartCompositionEditSession(
this, pContext, fCUASWorkaroundEnabled, _cand->style().inline_preedit));
pStartCompositionEditSession.Attach(
new CStartCompositionEditSession(this, pContext, fCUASWorkaroundEnabled));
_cand->StartUI();
if (pStartCompositionEditSession != nullptr) {
HRESULT hr;
Expand Down
4 changes: 1 addition & 3 deletions output/data/weasel.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Weasel settings
# encoding: utf-8

config_version: "0.22"
config_version: "0.23"

app_options:
cmd.exe:
ascii_mode: true
conhost.exe:
ascii_mode: true
firefox.exe:
inline_preedit: true # workaround for #946

show_notifications: true
# how long a period notifications shows
Expand Down

0 comments on commit 2e67b9b

Please sign in to comment.