win32: avoid redundant call for GetRealCount and GetLineStart in TWin32MemoStrings.Insert

git-svn-id: trunk@53294 -
This commit is contained in:
blikblum 2016-11-04 11:32:17 +00:00
parent d99fe899e7
commit f43e1bfde6

View File

@ -140,24 +140,25 @@ end;
procedure TWin32MemoStrings.Insert(Index: integer; const S: string);
var
LineStart: Integer;
LineStart, RealCount: Integer;
NewLine: String;
begin
LineStart := GetLineStart(Index);
if Index < GetRealCount then
RealCount := GetRealCount;
if Index < RealCount then
begin
//insert with LineEnding
LineStart := GetLineStart(Index);
NewLine := S+LineEnding;
SendMessageW(FHandle, EM_SETSEL, LineStart, LineStart);
SendMessageW(FHandle, EM_REPLACESEL, 0, lparam(PWideChar(UTF8ToUTF16(NewLine))))
SendMessageW(FHandle, EM_REPLACESEL, 0, lparam(PWideChar(UTF8ToUTF16(NewLine))));
end
else
begin
//append with a preceding LineEnding
LineStart := GetLineStart(Index-1)+GetLineLength(Index-1);
SendMessageW(FHandle, EM_SETSEL, LineStart, LineStart);
if GetRealCount = Count then
//check if last line is empty
if Get(RealCount - 1) <> '' then
NewLine := LineEnding+S+LineEnding
else
NewLine := S+LineEnding;