From 19e4bf8d044182a10ee65127567183e608aea2b3 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 4 Dec 2015 01:47:43 +0000 Subject: [PATCH] Fix SynEdit IME handler / crash on short section of only one char, loop for FRightPosForTarget not entered. Issue #0029126 git-svn-id: trunk@50592 - --- components/synedit/lazsynimm.pas | 39 ++++++++++++-------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/components/synedit/lazsynimm.pas b/components/synedit/lazsynimm.pas index 4c99a55de0..fe472eabec 100644 --- a/components/synedit/lazsynimm.pas +++ b/components/synedit/lazsynimm.pas @@ -789,18 +789,13 @@ begin if (FLeftPosForTarget < 0) or (FLeftPosForTarget > xy.x) then FLeftPosForTarget := xy.x; inc(i); - while longword(i) < ImeCount do begin - if (ord(p[i]) <> ATTR_TARGET_CONVERTED) or (i = ImeCount-1) then begin - if (ord(p[i]) = ATTR_TARGET_CONVERTED) then - inc(i); - xy.x := x + CharToByte(x, i); - FImeBlockSelection2.EndLineBytePos := xy; - if (FRightPosForTarget < 0) or (FRightPosForTarget > xy.x) then - FRightPosForTarget := xy.x; - break; - end; + + while (longword(i) < ImeCount) and (ord(p[i]) = ATTR_TARGET_CONVERTED) do inc(i); - end; + xy.x := x + CharToByte(x, i); + FImeBlockSelection2.EndLineBytePos := xy; + if (FRightPosForTarget < 0) or (FRightPosForTarget < xy.x) then + FRightPosForTarget := xy.x; //break; end; @@ -811,18 +806,13 @@ begin FLeftPosForTarget := xy.x; FImeBlockSelection3.StartLineBytePos := xy; inc(i); - while longword(i) < ImeCount do begin - if (ord(p[i]) <> ATTR_TARGET_NOTCONVERTED) or (i = ImeCount-1) then begin - if (ord(p[i]) = ATTR_TARGET_NOTCONVERTED) then - inc(i); - xy.x := x + CharToByte(x, i); - FImeBlockSelection3.EndLineBytePos := xy; - if (FRightPosForTarget < 0) or (FRightPosForTarget > xy.x) then - FRightPosForTarget := xy.x; - break; - end; + + while (longword(i) < ImeCount) and (ord(p[i]) = ATTR_TARGET_NOTCONVERTED) do inc(i); - end; + xy.x := x + CharToByte(x, i); + FImeBlockSelection3.EndLineBytePos := xy; + if (FRightPosForTarget < 0) or (FRightPosForTarget < xy.x) then + FRightPosForTarget := xy.x; //break; end; @@ -837,8 +827,9 @@ begin if (FLeftPosForTarget > 0) and FAdjustLeftCharForTargets then begin FLeftPosForTarget := ViewedTextBuffer.LogicalToPhysicalPos (Point(FLeftPosForTarget, FImeBlockSelection.FirstLineBytePos.Y)).x; - FRightPosForTarget := ViewedTextBuffer.LogicalToPhysicalPos - (Point(FRightPosForTarget, FImeBlockSelection.FirstLineBytePos.Y)).x; + if FRightPosForTarget > 0 then + FRightPosForTarget := ViewedTextBuffer.LogicalToPhysicalPos + (Point(FRightPosForTarget, FImeBlockSelection.FirstLineBytePos.Y)).x; EnsureLeftChar; end; end;