From 3773d222acc34c8d8797c891585e196192a4e5ce Mon Sep 17 00:00:00 2001 From: Tu Dinh <1257909+dinhngtu@users.noreply.github.com> Date: Sat, 24 Feb 2024 21:53:51 +0100 Subject: [PATCH] fix EditSurroundingWord --- VietTypeATL/EditSurroundingWord.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/VietTypeATL/EditSurroundingWord.cpp b/VietTypeATL/EditSurroundingWord.cpp index 0189623..21b4922 100644 --- a/VietTypeATL/EditSurroundingWord.cpp +++ b/VietTypeATL/EditSurroundingWord.cpp @@ -88,15 +88,16 @@ static HRESULT DoEditSurroundingWord( hr = rangeTest->ShiftStart(ec, -SWF_MAXCHARS, &shifted, &haltcond); HRESULT_CHECK_RETURN(hr, L"%s", L"rangeTest->ShiftStart failed"); - if (!shifted) { + if (shifted >= 0) { return E_NOTIMPL; } + shifted = -shifted; // find word boundary std::array buf; ULONG retrieved; - hr = rangeTest->GetText(ec, 0, &buf[0], shifted, &retrieved); + hr = rangeTest->GetText(ec, 0, &buf[0], std::min(shifted, SWF_MAXCHARS), &retrieved); HRESULT_CHECK_RETURN(hr, L"%s", L"rangeTest->GetText failed"); if (!retrieved) {