浏览代码

FIX: Viewer - random crash with enabled caret under Qt (issue #2265)

Alexander Koblov 3 月之前
父节点
当前提交
dd657ed8a1
共有 1 个文件被更改,包括 16 次插入8 次删除
  1. 16 8
      components/viewer/viewercontrol.pas

+ 16 - 8
components/viewer/viewercontrol.pas

@@ -209,6 +209,7 @@ type
     FBlockBeg:           PtrInt;
     FBlockBeg:           PtrInt;
     FBlockEnd:           PtrInt;
     FBlockEnd:           PtrInt;
     FCaretPos:           PtrInt;
     FCaretPos:           PtrInt;
+    FCaretPoint:         TPoint;
     FMouseBlockBeg:      PtrInt;
     FMouseBlockBeg:      PtrInt;
     FMouseBlockSide:     TCharSide;
     FMouseBlockSide:     TCharSide;
     FSelecting:          Boolean;
     FSelecting:          Boolean;
@@ -682,6 +683,7 @@ begin
 
 
   if FShowCaret and FCaretVisible then
   if FShowCaret and FCaretVisible then
   begin
   begin
+    FCaretPoint.X := -1;
     FCaretVisible := not LCLIntf.HideCaret(Handle);
     FCaretVisible := not LCLIntf.HideCaret(Handle);
   end;
   end;
 
 
@@ -710,6 +712,12 @@ begin
     vcmBook: WriteText;
     vcmBook: WriteText;
     vcmDec,vcmHex : WriteCustom;
     vcmDec,vcmHex : WriteCustom;
   end;
   end;
+
+  if FShowCaret and (FCaretPoint.X > -1) then
+  begin
+    LCLIntf.SetCaretPos(FCaretPoint.X, FCaretPoint.Y);
+    if not FCaretVisible then FCaretVisible:= LCLIntf.ShowCaret(Handle);
+  end;
 end;
 end;
 
 
 procedure TViewerControl.SetViewerMode(Value: TViewerControlMode);
 procedure TViewerControl.SetViewerMode(Value: TViewerControlMode);
@@ -1779,8 +1787,8 @@ var
   begin
   begin
     if FShowCaret and (FCaretPos = LinePos) then
     if FShowCaret and (FCaretPos = LinePos) then
     begin
     begin
-      LCLIntf.SetCaretPos(X, Y);
-      if not FCaretVisible then FCaretVisible:= LCLIntf.ShowCaret(Handle);
+      FCaretPoint.X:= X;
+      FCaretPoint.Y:= Y;
     end;
     end;
   end;
   end;
 
 
@@ -2152,8 +2160,8 @@ begin
 
 
   if FShowCaret and (FCaretPos >= pBegLine) and (FCaretPos <= pEndLine) then
   if FShowCaret and (FCaretPos >= pBegLine) and (FCaretPos <= pEndLine) then
   begin
   begin
-    LCLIntf.SetCaretPos(X + Canvas.TextWidth(GetText(StartPos, FCaretPos - pBegLine, 0)), Y);
-    if not FCaretVisible then FCaretVisible:= LCLIntf.ShowCaret(Handle);
+    FCaretPoint.Y:= Y;
+    FCaretPoint.X:= X + Canvas.TextWidth(GetText(StartPos, FCaretPos - pBegLine, 0));
   end;
   end;
 
 
   // Out of selection, draw normal
   // Out of selection, draw normal
@@ -2208,8 +2216,8 @@ begin
 
 
   if FShowCaret and (FCaretPos >= pBegLine) and (FCaretPos <= pEndLine) then
   if FShowCaret and (FCaretPos >= pBegLine) and (FCaretPos <= pEndLine) then
   begin
   begin
-    LCLIntf.SetCaretPos(X + Canvas.TextWidth(Copy(sText, 1, FCustom.StartAscii + (FCaretPos - pBegLine))), Y);
-    if not FCaretVisible then FCaretVisible:= LCLIntf.ShowCaret(Handle);
+    FCaretPoint.Y:= Y;
+    FCaretPoint.X:= X + Canvas.TextWidth(Copy(sText, 1, FCustom.StartAscii + (FCaretPos - pBegLine)));
   end;
   end;
 
 
   // Out of selection, draw normal
   // Out of selection, draw normal
@@ -2307,8 +2315,8 @@ begin
 
 
   if FShowCaret and (FCaretPos >= pBegLine) and (FCaretPos <= pEndLine) then
   if FShowCaret and (FCaretPos >= pBegLine) and (FCaretPos <= pEndLine) then
   begin
   begin
-    LCLIntf.SetCaretPos(X + Canvas.TextWidth(Copy(sText, 1, FCaretPos - pBegLine)), Y);
-    if not FCaretVisible then FCaretVisible:= LCLIntf.ShowCaret(Handle);
+    FCaretPoint.Y:= Y;
+    FCaretPoint.X:= X + Canvas.TextWidth(Copy(sText, 1, FCaretPos - pBegLine));
   end;
   end;
 
 
   // Out of selection, draw normal
   // Out of selection, draw normal