mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-06 15:37:15 +01:00
Qt: speed improvement for QTextEdit text insertions when it contains < or > chars. part of issue #22715
git-svn-id: trunk@38367 -
This commit is contained in:
parent
87ed4c7d57
commit
a2cf7dbb61
@ -412,6 +412,20 @@ end;
|
|||||||
procedure TQtMemoStrings.Insert(Index: integer; const S: string);
|
procedure TQtMemoStrings.Insert(Index: integer; const S: string);
|
||||||
var
|
var
|
||||||
W: WideString;
|
W: WideString;
|
||||||
|
QtCursor: QTextCursorH;
|
||||||
|
|
||||||
|
|
||||||
|
function WorkaroundNeeded: Boolean;
|
||||||
|
var
|
||||||
|
HaveLt: Boolean;
|
||||||
|
HaveGt: Boolean;
|
||||||
|
S1: String;
|
||||||
|
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;
|
||||||
@ -423,18 +437,16 @@ begin
|
|||||||
if Index <= FStringList.Count then
|
if Index <= FStringList.Count then
|
||||||
begin
|
begin
|
||||||
FStringList.Insert(Index, S);
|
FStringList.Insert(Index, S);
|
||||||
// to fix #22715 we must use slower insertLine(). Rewriting
|
if (TQtTextEdit(FOwner.Handle).getBlockCount - Index <= 1) then
|
||||||
// handle from QTextEdit to QPlainTextEdit should fix speed.
|
|
||||||
// Currently we are missing Text alignment in QPlainTextEdit class,
|
|
||||||
// so that's why it's not rewritten yet.
|
|
||||||
if (Index < FStringList.Count - 1) and
|
|
||||||
(TQtTextEdit(FOwner.Handle).getBlockCount - Index <= 1) then
|
|
||||||
begin
|
begin
|
||||||
if (System.Pos('<', S) > 0) or (System.Pos('>',S) > 0) then
|
// workaround for qt richtext parser bug. issues #17170 and #22715
|
||||||
|
if WorkaroundNeeded then
|
||||||
begin
|
begin
|
||||||
// workaround for qt richtext parser bug
|
|
||||||
W := GetUTF8String(S);
|
W := GetUTF8String(S);
|
||||||
TQtTextEdit(FOwner.Handle).insertLine(Index, W);
|
if (Index >= FStringList.Count - 1) then
|
||||||
|
TQtTextEdit(FOwner.Handle).appendLine(W)
|
||||||
|
else
|
||||||
|
TQtTextEdit(FOwner.Handle).insertLine(Index, W);
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
// append is much faster in case when we add strings
|
// append is much faster in case when we add strings
|
||||||
|
|||||||
@ -818,6 +818,7 @@ type
|
|||||||
function getSelectionStart: Integer;
|
function getSelectionStart: Integer;
|
||||||
function getSelectionEnd: Integer;
|
function getSelectionEnd: Integer;
|
||||||
function getSelectionLength: Integer;
|
function getSelectionLength: Integer;
|
||||||
|
procedure appendLine(AText: WideString);
|
||||||
procedure insertLine(const AIndex: integer; AText: WideString);
|
procedure insertLine(const AIndex: integer; AText: WideString);
|
||||||
function isUndoAvailable: Boolean;
|
function isUndoAvailable: Boolean;
|
||||||
procedure removeLine(const AIndex: integer);
|
procedure removeLine(const AIndex: integer);
|
||||||
@ -8129,6 +8130,29 @@ begin
|
|||||||
{$note implement TQtTextEdit.setMaxLength}
|
{$note implement TQtTextEdit.setMaxLength}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TQtTextEdit.appendLine(AText: WideString);
|
||||||
|
var
|
||||||
|
QtCursor: QTextCursorH;
|
||||||
|
WrapMode: QTextEditLineWrapMode;
|
||||||
|
begin
|
||||||
|
WrapMode := QTextEdit_lineWrapMode(QTextEditH(Widget));
|
||||||
|
{we must remove wrapping to get correct line !}
|
||||||
|
setLineWrapMode(QTextEditNoWrap);
|
||||||
|
QtCursor := QTextCursor_create();
|
||||||
|
try
|
||||||
|
QTextEdit_textCursor(QTextEditH(Widget), QtCursor);
|
||||||
|
QTextCursor_beginEditBlock(QtCursor);
|
||||||
|
QTextCursor_movePosition(QtCursor, QTextCursorEnd,
|
||||||
|
QTextCursorMoveAnchor, 1);
|
||||||
|
QTextCursor_insertBlock(QtCursor);
|
||||||
|
QTextCursor_endEditBlock(QtCursor);
|
||||||
|
QTextEdit_insertPlainText(QTextEditH(Widget), @AText);
|
||||||
|
finally
|
||||||
|
QTextCursor_destroy(QtCursor);
|
||||||
|
setLineWrapMode(WrapMode);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TQtTextEdit.insertLine(const AIndex: integer; AText: WideString);
|
procedure TQtTextEdit.insertLine(const AIndex: integer; AText: WideString);
|
||||||
var
|
var
|
||||||
QtCursor: QTextCursorH;
|
QtCursor: QTextCursorH;
|
||||||
@ -8141,15 +8165,33 @@ begin
|
|||||||
try
|
try
|
||||||
QTextEdit_textCursor(QTextEditH(Widget), QtCursor);
|
QTextEdit_textCursor(QTextEditH(Widget), QtCursor);
|
||||||
QTextCursor_beginEditBlock(QtCursor);
|
QTextCursor_beginEditBlock(QtCursor);
|
||||||
QTextCursor_movePosition(QtCursor, QTextCursorStart,
|
// QTextCursor slowness
|
||||||
QTextCursorMoveAnchor, 1);
|
// https://bugreports.qt-project.org/browse/QTBUG-3554
|
||||||
QTextCursor_movePosition(QtCursor, QTextCursorStartOfLine,
|
// differentiate append vs. insert issue #22715
|
||||||
QTextCursorMoveAnchor, 1);
|
if AIndex >= FList.Count - 1 then
|
||||||
|
begin
|
||||||
|
QTextCursor_movePosition(QtCursor, QTextCursorEnd,
|
||||||
|
QTextCursorMoveAnchor, 1);
|
||||||
|
QTextCursor_insertBlock(QtCursor);
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
QTextCursor_movePosition(QtCursor, QTextCursorStart,
|
||||||
|
QTextCursorMoveAnchor, 1);
|
||||||
|
QTextCursor_movePosition(QtCursor, QTextCursorStartOfLine,
|
||||||
|
QTextCursorMoveAnchor, 1);
|
||||||
|
end;
|
||||||
|
|
||||||
QTextCursor_movePosition(QtCursor, QTextCursorDown,
|
QTextCursor_movePosition(QtCursor, QTextCursorDown,
|
||||||
QTextCursorMoveAnchor, AIndex);
|
QTextCursorMoveAnchor, AIndex);
|
||||||
QTextCursor_insertBlock(QtCursor);
|
// QTextCursor slowness
|
||||||
QTextCursor_movePosition(QtCursor, QTextCursorUp,
|
// https://bugreports.qt-project.org/browse/QTBUG-3554
|
||||||
QTextCursorMoveAnchor, 1);
|
// differentiate append vs. insert issue #22715
|
||||||
|
if AIndex < FList.Count - 1 then
|
||||||
|
begin
|
||||||
|
QTextCursor_insertBlock(QtCursor);
|
||||||
|
QTextCursor_movePosition(QtCursor, QTextCursorUp,
|
||||||
|
QTextCursorMoveAnchor, 1);
|
||||||
|
end;
|
||||||
QTextCursor_insertText(QtCursor, @AText);
|
QTextCursor_insertText(QtCursor, @AText);
|
||||||
QTextCursor_endEditBlock(QtCursor);
|
QTextCursor_endEditBlock(QtCursor);
|
||||||
finally
|
finally
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user