Skip to content

Commit

Permalink
Sync Scintilla IMR_DOCUMENTFEED changes, issue #127.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed May 6, 2023
1 parent 4a977fa commit 72ef5d6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
65 changes: 60 additions & 5 deletions scintilla/win32/ScintillaWin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ class ScintillaWin final :
void ImeStartComposition();
void ImeEndComposition();
LRESULT ImeOnReconvert(LPARAM lParam);
LRESULT ImeOnDocumentFeed(LPARAM lParam) const;
sptr_t HandleCompositionWindowed(uptr_t wParam, sptr_t lParam);
sptr_t HandleCompositionInline(uptr_t wParam, sptr_t lParam);

Expand Down Expand Up @@ -1933,6 +1934,9 @@ sptr_t ScintillaWin::IMEMessage(unsigned int iMessage, uptr_t wParam, sptr_t lPa
if (wParam == IMR_RECONVERTSTRING) {
return ImeOnReconvert(lParam);
}
if (wParam == IMR_DOCUMENTFEED) {
return ImeOnDocumentFeed(lParam);
}
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}

Expand Down Expand Up @@ -3326,21 +3330,24 @@ LRESULT ScintillaWin::ImeOnReconvert(LPARAM lParam) {
const Sci::Position mainStart = sel.RangeMain().Start().Position();
const Sci::Position mainEnd = sel.RangeMain().End().Position();
const Sci::Line curLine = pdoc->SciLineFromPosition(mainStart);
if (curLine != pdoc->SciLineFromPosition(mainEnd))
if (curLine != pdoc->SciLineFromPosition(mainEnd)) {
return 0;
}
const Sci::Position baseStart = pdoc->LineStart(curLine);
const Sci::Position baseEnd = pdoc->LineEnd(curLine);
if ((baseStart == baseEnd) || (mainEnd > baseEnd))
if ((baseStart == baseEnd) || (mainEnd > baseEnd)) {
return 0;
}

const UINT codePage = CodePageOfDocument();
const std::wstring rcFeed = StringDecode(RangeText(baseStart, baseEnd), codePage);
const DWORD rcFeedLen = static_cast<DWORD>(rcFeed.length()) * sizeof(wchar_t);
const DWORD rcSize = sizeof(RECONVERTSTRING) + rcFeedLen + sizeof(wchar_t);

RECONVERTSTRING *rc = static_cast<RECONVERTSTRING *>(PtrFromSPtr(lParam));
if (!rc)
if (!rc) {
return rcSize; // Immediately be back with rcSize of memory block.
}

wchar_t *rcFeedStart = reinterpret_cast<wchar_t*>(rc + 1);
memcpy(rcFeedStart, rcFeed.data(), rcFeedLen);
Expand All @@ -3361,11 +3368,13 @@ LRESULT ScintillaWin::ImeOnReconvert(LPARAM lParam) {
rc->dwTargetStrOffset = rc->dwCompStrOffset;

const IMContext imc(MainHWND());
if (!imc.hIMC)
if (!imc.hIMC) {
return 0;
}

if (!::ImmSetCompositionStringW(imc.hIMC, SCS_QUERYRECONVERTSTRING, rc, rcSize, nullptr, 0))
if (!::ImmSetCompositionStringW(imc.hIMC, SCS_QUERYRECONVERTSTRING, rc, rcSize, nullptr, 0)) {
return 0;
}

// No selection asks IME to fill target fields with its own value.
const DWORD tgWlen = rc->dwTargetStrLen;
Expand Down Expand Up @@ -3402,6 +3411,52 @@ LRESULT ScintillaWin::ImeOnReconvert(LPARAM lParam) {
return rcSize;
}

LRESULT ScintillaWin::ImeOnDocumentFeed(LPARAM lParam) const {
// This is called while typing preedit string in.
// So there is no selection.
// Limit feed within one line without EOL.
// Look around: lineStart |<-- |compStart| - caret - compEnd| -->| lineEnd.

const Sci::Position curPos = CurrentPosition();
const Sci::Line curLine = pdoc->SciLineFromPosition(curPos);
const Sci::Position lineStart = pdoc->LineStart(curLine);
const Sci::Position lineEnd = pdoc->LineEnd(curLine);

const std::wstring rcFeed = StringDecode(RangeText(lineStart, lineEnd), CodePageOfDocument());
const size_t rcFeedLen = rcFeed.length() * sizeof(wchar_t);
const size_t rcSize = sizeof(RECONVERTSTRING) + rcFeedLen + sizeof(wchar_t);

RECONVERTSTRING *rc = static_cast<RECONVERTSTRING *>(PtrFromSPtr(lParam));
if (!rc) {
return rcSize;
}

wchar_t *rcFeedStart = reinterpret_cast<wchar_t*>(rc + 1);
memcpy(rcFeedStart, &rcFeed[0], rcFeedLen);

const IMContext imc(MainHWND());
if (!imc.hIMC) {
return 0;
}

const size_t compStrLen = imc.GetCompositionString(GCS_COMPSTR).size();
const int imeCaretPos = imc.GetImeCaretPos();
const Sci::Position compStart = pdoc->GetRelativePositionUTF16(curPos, -imeCaretPos);
const Sci::Position compStrOffset = pdoc->CountUTF16(lineStart, compStart);

// Fill in reconvert structure.
// Let IME to decide what the target is.
rc->dwVersion = 0; //constant
rc->dwStrLen = static_cast<DWORD>(rcFeed.length());
rc->dwStrOffset = sizeof(RECONVERTSTRING); //constant
rc->dwCompStrLen = static_cast<DWORD>(compStrLen);
rc->dwCompStrOffset = static_cast<DWORD>(compStrOffset) * sizeof(wchar_t);
rc->dwTargetStrLen = rc->dwCompStrLen;
rc->dwTargetStrOffset = rc->dwCompStrOffset;

return rcSize; // MS API says reconv structure to be returned.
}

void ScintillaWin::GetIntelliMouseParameters() noexcept {
// This retrieves the number of lines per scroll as configured in the Mouse Properties sheet in Control Panel
::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &linesPerScroll, 0);
Expand Down
6 changes: 3 additions & 3 deletions version.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ git clone https://github.com/XhmikosR/notepad2-mod.git
Scintilla (upstream)
hg clone http://hg.code.sf.net/p/scintilla/code scintilla
5.3.4
2023-04-14 9345:66fdea058cc1
2023-05-06 9349:dcbeefaf7d8c

Lexilla (upstream)
git clone https://github.com/ScintillaOrg/lexilla.git
5.2.4
2023-03-27 43ea736569d52ba6cf7e7325cf39009409e7282b
2023-05-05 3124f9e2bd8164ebb0bb6a0f95e9a29d3b7a8517

SciTE (upstream)
hg clone http://hg.code.sf.net/p/scintilla/scite
5.3.5
2023-04-14 6118:6ea425943cef
2023-04-22 6119:3b944ea15374

init submodule:
git submodule init
Expand Down

0 comments on commit 72ef5d6

Please sign in to comment.