Ver código fonte

ComPDFKit.Tool(win)-当选中输入框,然后滑动到其他页导致无法输入任何内容,补充安全检查防止在对象为空

liyijie 3 meses atrás
pai
commit
8b425ffea8
1 arquivos alterados com 34 adições e 23 exclusões
  1. 34 23
      Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.TextEdit.cs

+ 34 - 23
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.TextEdit.cs

@@ -714,16 +714,16 @@ namespace ComPDFKit.Tool
             return editAreaObject;
         }
 
-        public EditAreaObject GetEditAreaObjectListForIndex(int pageIndex,int editIndex)
+        public EditAreaObject GetEditAreaObjectListForIndex(int pageIndex, int editIndex)
         {
-            if(editAreaList==null || editAreaList.Count==0)
+            if (editAreaList == null || editAreaList.Count == 0)
             {
                 return null;
             }
 
-            foreach( EditAreaObject editArea in editAreaList.Values )
+            foreach (EditAreaObject editArea in editAreaList.Values)
             {
-                if(editArea.PageIndex==pageIndex && editArea.EditAreaIndex==editIndex)
+                if (editArea.PageIndex == pageIndex && editArea.EditAreaIndex == editIndex)
                 {
                     return editArea;
                 }
@@ -787,11 +787,11 @@ namespace ComPDFKit.Tool
             }
 
             //Prioritize the selected status
-            List<SelectedRect> checkList= new List<SelectedRect>();
+            List<SelectedRect> checkList = new List<SelectedRect>();
             if (hitTestRects != null && hitTestRects.Count > 0)
             {
                 List<SelectedRect> checkedList = hitTestRects.AsEnumerable().Where(x => x.GetIsSelected() == true).ToList();
-                List<SelectedRect> unCheckList= hitTestRects.AsEnumerable().Where(x => x.GetIsSelected() == false).ToList();
+                List<SelectedRect> unCheckList = hitTestRects.AsEnumerable().Where(x => x.GetIsSelected() == false).ToList();
 
                 checkList.AddRange(checkedList);
                 checkList.AddRange(unCheckList);
@@ -1955,12 +1955,15 @@ namespace ComPDFKit.Tool
             caretVisual.SetSelectRect(SelectLineRects);
             if (SelectLineRects.Count > 0)
             {
-                caretVisual.Draw(true, false);
-                Point HeightPoint = caretVisual.GetCaretHighPoint();
-                Point caretPos = new Point(
-                    HeightPoint.X * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().X,
-                   HeightPoint.Y * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().Y);
-                SetPastePoint(caretPos);
+                if (GetSelectedRectForEditAreaObject(textArea) != null)
+                {
+                    caretVisual.Draw(true, false);
+                    Point HeightPoint = caretVisual.GetCaretHighPoint();
+                    Point caretPos = new Point(
+                        HeightPoint.X * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().X,
+                       HeightPoint.Y * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().Y);
+                    SetPastePoint(caretPos);
+                }
                 caretVisual.StopCaret();
             }
             else
@@ -1968,12 +1971,20 @@ namespace ComPDFKit.Tool
                 caretVisual.Draw(true, drawCaret);
                 if (drawCaret)
                 {
-                    Point HeightPoint = caretVisual.GetCaretHighPoint();
-                    Point caretPos = new Point(
-                        HeightPoint.X * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().X,
-                       HeightPoint.Y * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().Y);
-                    SetPastePoint(caretPos);
-                    caretVisual.StartTimer();
+                    if (GetSelectedRectForEditAreaObject(textArea) != null)
+                    {
+                        Point HeightPoint = caretVisual.GetCaretHighPoint();
+
+                        Point caretPos = new Point(
+                            HeightPoint.X * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().X,
+                           HeightPoint.Y * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().Y);
+                        SetPastePoint(caretPos);
+                        caretVisual.StartTimer();
+                    }
+                    else
+                    {
+                        caretVisual.StopCaret();
+                    }
                 }
                 else
                 {
@@ -2241,7 +2252,7 @@ namespace ComPDFKit.Tool
                             editAreaMultiIndex.Add(editAreaObject.EditAreaIndex);
                             editAreaList.Add(selectedRect, editAreaObject);
                             multiSelectedRect.Children.Add(selectedRect);
-                            multiSelectedRect.SetMulitSelectedRect(selectedRect, editAreaObject.PageIndex,editAreaObject.EditAreaIndex);
+                            multiSelectedRect.SetMulitSelectedRect(selectedRect, editAreaObject.PageIndex, editAreaObject.EditAreaIndex);
 
                             multiSelectedRect.SetRect(selectedRects.GetRect());
                             multiSelectedRect.SetMaxRect(selectedRects.GetMaxRect());
@@ -2355,17 +2366,17 @@ namespace ComPDFKit.Tool
                 {
                     if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
                     {
-                        editAreaObject = GetEditAreaObjectListForIndex(checkPage,checkEdit);
+                        editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
                     }
                 }
-                if(item == null)
+                if (item == null)
                 {
                     continue;
                 }
                 PDFEditHistory pDFEditHistory = new PDFEditHistory();
                 pDFEditHistory.PageIndex = multiPage;
                 pDFEditHistory.EditPage = cPDFEditPage;
-                if(editAreaObject==null)
+                if (editAreaObject == null)
                 {
                     continue;
                 }
@@ -2517,7 +2528,7 @@ namespace ComPDFKit.Tool
                 Rect rect2 = item.GetRect();
                 if (currentZoom < 1)
                 {
-                    rect2.X = rect2.X - editPadding ;
+                    rect2.X = rect2.X - editPadding;
                 }
                 else
                 {