mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-24 19:31:40 +02:00
Qt: fixed TQtMemoString.Insert() and TQtTextEdit.insertLine(). issue #29670
git-svn-id: trunk@51658 -
This commit is contained in:
parent
724c7e9cd6
commit
f9d4440db3
@ -418,51 +418,22 @@ end;
|
|||||||
procedure TQtMemoStrings.Insert(Index: integer; const S: string);
|
procedure TQtMemoStrings.Insert(Index: integer; const S: string);
|
||||||
var
|
var
|
||||||
W: WideString;
|
W: WideString;
|
||||||
|
|
||||||
function WorkaroundNeeded: Boolean;
|
|
||||||
var
|
|
||||||
HaveLt: Boolean;
|
|
||||||
HaveGt: Boolean;
|
|
||||||
begin
|
|
||||||
HaveLt := System.Pos('<', S) > 0;
|
|
||||||
HaveGt := System.Pos('>', S) > 0;
|
|
||||||
Result := HaveLt or HaveGt;
|
|
||||||
end;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if FTextChanged then InternalUpdate;
|
if FTextChanged then InternalUpdate;
|
||||||
if Index < 0 then Index := 0;
|
if Index < 0 then Index := 0;
|
||||||
|
|
||||||
{$ifdef VerboseQtMemoStrings}
|
{$ifdef VerboseQtMemoStrings}
|
||||||
writeln('TQtMemoStrings.Insert Index=',Index);
|
writeln('TQtMemoStrings.Insert Index=',Index,' COUNT=',FStringList.Count);
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
if Index <= FStringList.Count then
|
// simplified because of issue #29670
|
||||||
begin
|
// allow insert invalid index like others do
|
||||||
|
if Index >= FStringlist.Count then
|
||||||
|
Index := FStringList.Add(S)
|
||||||
|
else
|
||||||
FStringList.Insert(Index, S);
|
FStringList.Insert(Index, S);
|
||||||
if (TQtTextEdit(FOwner.Handle).getBlockCount - Index <= 1) then
|
W := GetUTF8String(S);
|
||||||
begin
|
TQtTextEdit(FOwner.Handle).insertLine(Index, W);
|
||||||
// workaround for qt richtext parser bug. issues #17170 and #22715
|
|
||||||
if WorkaroundNeeded then
|
|
||||||
begin
|
|
||||||
W := GetUTF8String(S);
|
|
||||||
if (Index >= FStringList.Count - 1) then
|
|
||||||
TQtTextEdit(FOwner.Handle).appendLine(W)
|
|
||||||
else
|
|
||||||
TQtTextEdit(FOwner.Handle).insertLine(Index, W);
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
// append is much faster in case when we add strings
|
|
||||||
W := S;
|
|
||||||
ExternalUpdate(W, False, False);
|
|
||||||
FTextChanged := False;
|
|
||||||
end;
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
W := GetUTF8String(S);
|
|
||||||
TQtTextEdit(FOwner.Handle).insertLine(Index, W);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TQtMemoStrings.LoadFromFile(const FileName: string);
|
procedure TQtMemoStrings.LoadFromFile(const FileName: string);
|
||||||
|
|||||||
@ -9544,7 +9544,8 @@ begin
|
|||||||
// QTextCursor slowness
|
// QTextCursor slowness
|
||||||
// https://bugreports.qt-project.org/browse/QTBUG-3554
|
// https://bugreports.qt-project.org/browse/QTBUG-3554
|
||||||
// differentiate append vs. insert issue #22715
|
// differentiate append vs. insert issue #22715
|
||||||
if AIndex >= FList.Count - 1 then
|
// added check for AIndex. issue #29670
|
||||||
|
if (AIndex > 0) and (AIndex >= FList.Count - 1) then
|
||||||
begin
|
begin
|
||||||
QTextCursor_movePosition(QtCursor, QTextCursorEnd,
|
QTextCursor_movePosition(QtCursor, QTextCursorEnd,
|
||||||
QTextCursorMoveAnchor, 1);
|
QTextCursorMoveAnchor, 1);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user