ソースを参照

ComPDFKit.Demo(win) - 修复内容编辑多选时属性面板设置问题

TangJinZhou 7 ヶ月 前
コミット
75724dee69

+ 190 - 115
Demo/Examples/Compdfkit.Controls/Edit/PDFImageEdit/PDFImageEditControl/PDFImageEditControl.xaml.cs

@@ -17,7 +17,6 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls.Primitives;
 using System.Windows.Input;
-using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using ComPDFKit.Tool.DrawTool;
 using ComPDFKitViewer.Helper;
@@ -78,27 +77,32 @@ namespace ComPDFKit.Controls.Edit
             if (ToolView.GetIsCropMode())
             {
                 GetImageArea(out List<CPDFEditImageArea> imageAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-                foreach (var imageArea in imageAreas)
+                if (imageAreas.Count == 0 || pdfPage == null || editPage == null)
+                    return;
+
+                SelectedRect selectedRect = ToolView.GetSelectedRectForEditAreaObject(imageAreas[0]);
+                if (selectedRect == null)
+                    return;
+
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageAreas[0].GetFrame());
+                double currentZoom = ToolView.GetCPDFViewer().CurrentRenderFrame.ZoomFactor;
+                Rect rect = selectedRect.GetRect();
+                Rect maxRect = selectedRect.GetMaxRect();
+                Rect pdfRect = new Rect((rect.X - maxRect.X) / currentZoom, (rect.Y - maxRect.Y) / currentZoom, rect.Width / currentZoom, rect.Height / currentZoom);
+                pdfRect = DpiHelper.StandardRectToPDFRect(pdfRect);
+                CRect newCRect = new CRect((float)pdfRect.Left, (float)pdfRect.Bottom, (float)pdfRect.Right, (float)pdfRect.Top);
+                if(imageAreas[0].CutWithRect(newCRect))
                 {
-                    SelectedRect selectedRect = ToolView.GetSelectedRectForEditAreaObject(imageArea);
-                    if (selectedRect != null)
-                    {
-                        Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
-                        double currentZoom = ToolView.GetCPDFViewer().CurrentRenderFrame.ZoomFactor;
-                        Rect rect = selectedRect.GetRect();
-                        Rect maxRect = selectedRect.GetMaxRect();
-
-                        Rect pdfRect = new Rect((rect.X - maxRect.X) / currentZoom, (rect.Y - maxRect.Y) / currentZoom, rect.Width / currentZoom, rect.Height / currentZoom);
-                        pdfRect = DpiHelper.StandardRectToPDFRect(pdfRect);
-                        CRect newCRect = new CRect((float)pdfRect.Left, (float)pdfRect.Bottom, (float)pdfRect.Right, (float)pdfRect.Top);
-                        imageArea.CutWithRect(newCRect);
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
 
-                        ToolView.UpdateRender(oldRect, imageArea);
-                        editPage.EndEdit();
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, imageAreas[0]);
+                 }
 
-                        SetImageThumb();
-                    }
-                }
+                editPage.EndEdit();
+                SetImageThumb();
             }
         }
 
@@ -231,12 +235,37 @@ namespace ComPDFKit.Controls.Edit
         private void FlipUI_FlipChanged(object sender, bool e)
         {
             GetImageArea(out List<CPDFEditImageArea> imageAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            if (imageAreas.Count > 0)
+            if (imageAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if(ToolView.CurrentEditAreaObject() != null)
+            {
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageAreas[0].GetFrame());
+                bool result;
+                if (e)
+                {
+                    result = imageAreas[0].VerticalMirror();
+                }
+                else
+                {
+                    result = imageAreas[0].HorizontalMirror();
+                }
+
+                if (result)
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, imageAreas[0]);
+                }
+            }
+            else
             {
+                GroupHistory groupHistory = new GroupHistory();
                 foreach (CPDFEditImageArea imageArea in imageAreas)
                 {
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
-                    bool result = false;
+                    bool result;
                     if (e)
                     {
                         result = imageArea.VerticalMirror();
@@ -245,28 +274,24 @@ namespace ComPDFKit.Controls.Edit
                     {
                         result = imageArea.HorizontalMirror();
                     }
+
                     if (result)
                     {
                         PDFEditHistory editHistory = new PDFEditHistory();
                         editHistory.EditPage = editPage;
-                        if (pdfPage != null)
-                        {
-                            editHistory.PageIndex = pdfPage.PageIndex;
-                        }
-
-                        ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
-                        ToolView.UpdateRender(oldRect, imageArea);
-                        editPage.EndEdit();
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
                 }
 
-                if (imageAreas.Count == 1)
-                {
-                    SetImageThumb();
-                }
-
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
             }
 
+            editPage.EndEdit();
+            if (imageAreas.Count == 1)
+                SetImageThumb();
+
             //if (EditMultiEvents != null)
             //{
             //    foreach (PDFEditEvent editEvent in EditMultiEvents)
@@ -287,30 +312,43 @@ namespace ComPDFKit.Controls.Edit
         private void RotateUI_RotationChanged(object sender, double e)
         {
             GetImageArea(out List<CPDFEditImageArea> imageAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            if (imageAreas.Count > 0)
+            if (imageAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if(ToolView.CurrentEditAreaObject() != null)
+            {
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageAreas[0].GetFrame());
+                if (imageAreas[0].Rotate((int)e))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, imageAreas[0]);
+                }
+            }
+            else
             {
+                GroupHistory groupHistory = new GroupHistory();
                 foreach (CPDFEditImageArea imageArea in imageAreas)
                 {
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
                     if (imageArea.Rotate((int)e))
                     {
-                        ToolView.UpdateRender(oldRect, imageArea);
+                        PDFEditHistory editHistory = new PDFEditHistory();
+                        editHistory.EditPage = editPage;
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
                 }
-                
-                PDFEditHistory editHistory = new PDFEditHistory();
-                editHistory.EditPage = editPage;
-                if (pdfPage != null)
-                {
-                    editHistory.PageIndex = pdfPage.PageIndex;
-                } 
-                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
 
-                RotationTxb.Text = imageAreas.FirstOrDefault().GetRotation().ToString();
-                editPage.EndEdit();
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
+            }
 
+            editPage.EndEdit();
+            RotationTxb.Text = imageAreas.FirstOrDefault().GetRotation().ToString();
+            if (imageAreas.Count == 1)
                 SetImageThumb();
-            }
 
             //if (EditMultiEvents != null)
             //{
@@ -338,31 +376,44 @@ namespace ComPDFKit.Controls.Edit
             {
                 slider.Tag = "true";
             }
+
             GetImageArea(out List<CPDFEditImageArea> imageAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            foreach (CPDFEditImageArea imageArea in imageAreas)
+            if (imageAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if (ToolView.CurrentEditAreaObject() != null)
             {
-                if (imageArea != null)
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageAreas[0].GetFrame());
+                if (imageAreas[0].SetImageTransparency((byte)(ImasgeOpacitySlider.Value * 255)))
                 {
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
-                    if (imageArea.SetImageTransparency((byte)(ImasgeOpacitySlider.Value * 255)))
-                    { 
-                        ToolView.UpdateRender(oldRect, imageArea);
-                        editPage.EndEdit();
-                    }
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, imageAreas[0]);
                 }
             }
-            PDFEditHistory editHistory = new PDFEditHistory();
-            editHistory.EditPage = editPage;
-            if (pdfPage != null)
+            else
             {
-                editHistory.PageIndex = pdfPage.PageIndex;
+                GroupHistory groupHistory = new GroupHistory();
+                foreach (CPDFEditImageArea imageArea in imageAreas)
+                {
+                    if (imageArea.SetImageTransparency((byte)(ImasgeOpacitySlider.Value * 255)))
+                    {
+                        PDFEditHistory editHistory = new PDFEditHistory();
+                        editHistory.EditPage = editPage;
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
+                    }
+                }
+
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
             }
-            ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
 
+            editPage.EndEdit();
             if (imageAreas.Count == 1)
-            {
                 SetImageThumb();
-            }
         }
 
         private void SliderOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
@@ -377,33 +428,44 @@ namespace ComPDFKit.Controls.Edit
             {
                 return;
             }
+
             GetImageArea(out List<CPDFEditImageArea> imageAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            if (imageAreas == null)
-            {
+            if (imageAreas.Count == 0 || pdfPage == null || editPage == null)
                 return;
+
+            if (ToolView.CurrentEditAreaObject() != null)
+            {
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageAreas[0].GetFrame());
+                if (imageAreas[0].SetImageTransparency((byte)(ImasgeOpacitySlider.Value * 255)))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, imageAreas[0]);
+                }
             }
-            foreach (CPDFEditImageArea imageArea in imageAreas)
+            else
             {
-                if (imageArea != null)
+                GroupHistory groupHistory = new GroupHistory();
+                foreach (CPDFEditImageArea imageArea in imageAreas)
                 {
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
                     if (imageArea.SetImageTransparency((byte)(ImasgeOpacitySlider.Value * 255)))
                     {
-                        ToolView.UpdateRender(oldRect, imageArea);
-                        editPage.EndEdit();
+                        PDFEditHistory editHistory = new PDFEditHistory();
+                        editHistory.EditPage = editPage;
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
                 }
-            }
 
-            PDFEditHistory editHistory = new PDFEditHistory();
-            editHistory.EditPage = editPage;
-            if (pdfPage != null)
-            {
-                editHistory.PageIndex = pdfPage.PageIndex;
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
             }
 
-            ToolView?.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
-            SetImageThumb();
+            editPage.EndEdit();
+            if (imageAreas.Count == 1)
+                SetImageThumb();
         }
 
         private void ImageReplaceBtn_Click(object sender, RoutedEventArgs e)
@@ -420,32 +482,28 @@ namespace ComPDFKit.Controls.Edit
                 if (openFileDialog.ShowDialog() == true)
                 {
                     GetImageArea(out List<CPDFEditImageArea> imageAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-                    CPDFEditImageArea imageArea = imageAreas.FirstOrDefault();
-                    if (imageArea != null)
+                    if (imageAreas.Count == 0 || pdfPage == null || editPage == null)
+                        return;
+
+                    int imageWidth = 0;
+                    int imageHeight = 0;
+                    byte[] imageData = null;
+                    PDFHelp.ImagePathToByte(openFileDialog.FileName, ref imageData, ref imageWidth, ref imageHeight);
+                    if (imageData != null && imageWidth > 0 && imageHeight > 0)
                     {
-                        int imageWidth = 0;
-                        int imageHeight = 0;
-                        byte[] imageData = null;
-                        PDFHelp.ImagePathToByte(openFileDialog.FileName, ref imageData, ref imageWidth, ref imageHeight);
-
-                        if (imageData != null && imageWidth > 0 && imageHeight > 0)
+                        Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageAreas[0].GetFrame());
+                        CRect imageRect = imageAreas[0].GetClipRect();
+                        if (imageAreas[0].ReplaceImageArea(imageRect, imageData, imageWidth, imageHeight))
                         {
-                            Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
-                            CRect imageRect = imageArea.GetClipRect();
-                            if (imageArea.ReplaceImageArea(imageRect, imageData, imageWidth, imageHeight))
-                            {
-                                PDFEditHistory editHistory = new PDFEditHistory();
-                                editHistory.EditPage = editPage;
-                                if (pdfPage != null)
-                                {
-                                    editHistory.PageIndex = pdfPage.PageIndex;
-                                } 
-                                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
-                                SetImageThumb();
-                                ToolView.UpdateRender(oldRect, imageArea);
-                                editPage.EndEdit();
-                            }
+                            PDFEditHistory editHistory = new PDFEditHistory();
+                            editHistory.EditPage = editPage;
+                            editHistory.PageIndex = pdfPage.PageIndex;
+                            ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                            ToolView.UpdateRender(oldRect, imageAreas[0]);
                         }
+
+                        editPage.EndEdit();
+                        SetImageThumb();
                     }
                 }
             }
@@ -538,27 +596,44 @@ namespace ComPDFKit.Controls.Edit
         private void SetAbsRotation(double absRotation)
         {
             GetImageArea(out List<CPDFEditImageArea> imageAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            foreach (CPDFEditImageArea imageArea in imageAreas)
+            if (imageAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if (ToolView.CurrentEditAreaObject() != null)
+            {
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageAreas[0].GetFrame());
+                int rotation = (int)absRotation - imageAreas[0].GetRotation();
+                if (imageAreas[0].Rotate(rotation))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, imageAreas[0]);
+                }
+            }
+            else
             {
-                if (imageArea != null)
+                GroupHistory groupHistory = new GroupHistory();
+                foreach (CPDFEditImageArea imageArea in imageAreas)
                 {
                     int rotation = (int)absRotation - imageArea.GetRotation();
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
                     if (imageArea.Rotate(rotation))
                     {
-                        SetImageThumb();
-                        ToolView.UpdateRender(oldRect, imageArea);
-                        editPage.EndEdit();
+                        PDFEditHistory editHistory = new PDFEditHistory();
+                        editHistory.EditPage = editPage;
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
                 }
+
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
             }
-            PDFEditHistory editHistory = new PDFEditHistory();
-            editHistory.EditPage = editPage;
-            if (pdfPage != null)
-            {
-                editHistory.PageIndex = pdfPage.PageIndex;
-            }
-            ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+
+            editPage.EndEdit();
+            if(imageAreas.Count == 1)
+                SetImageThumb();
         }
 
         private void RotationTxb_LostFocus(object sender, RoutedEventArgs e)

+ 321 - 209
Demo/Examples/Compdfkit.Controls/Edit/PDFTextEdit/PDFTextEditControl/PDFTextEditControl.xaml.cs

@@ -5,7 +5,6 @@ using ComPDFKit.Tool;
 using ComPDFKit.Tool.SettingParam;
 using ComPDFKit.Tool.UndoManger;
 using ComPDFKit.Viewer.Helper;
-using ComPDFKit.Controls.PDFControl;
 using ComPDFKitViewer;
 using System;
 using System.Collections.Generic;
@@ -16,6 +15,7 @@ using System.Windows.Media;
 using System.ComponentModel;
 using System.Runtime.CompilerServices;
 using System.Linq;
+
 namespace ComPDFKit.Controls.Edit
 {
     public partial class PDFTextEditControl : UserControl, INotifyPropertyChanged
@@ -66,7 +66,6 @@ namespace ComPDFKit.Controls.Edit
         #region UI
         public void SetPDFTextEditData(List<TextEditParam> newEvents)
         {
-
             EditEvents = newEvents.Where(newEvent => newEvent.EditIndex >= 0 && newEvent.EditType == CPDFEditType.EditText).ToList();
             TextEditParam defaultEvent = EditEvents.FirstOrDefault();
             if (EditEvents.Count > 0)
@@ -151,47 +150,57 @@ namespace ComPDFKit.Controls.Edit
             }
 
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            if (textAreas.Count > 0)
+            if (textAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if (ToolView.CurrentEditAreaObject() != null)
             {
-                bool result = false;
-                foreach (CPDFEditTextArea textArea in textAreas)
+                bool result;
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(textAreas[0].GetFrame());
+                if (string.IsNullOrEmpty(textAreas[0].SelectText))
                 {
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
-                    if (string.IsNullOrEmpty(textArea.SelectText))
-                    {
-                        string fontName = "Helvetica";
-                        float fontSize = 14;
-                        byte[] fontColor = { 0, 0, 0 };
-                        byte transparency = 255;
-                        bool isBold = false;
-                        bool isItalic = false;
-                        textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
-                        result ^= textArea.SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], (byte)(FontOpacitySlider.Value * 255), isBold, isItalic);
-                    }
-                    else
-                    {
-                        result ^= textArea.SetCharsFontTransparency((byte)(FontOpacitySlider.Value * 255));
-                    }
-
-                    if (result)
-                    {
-                        ToolView.UpdateRender(oldRect, textArea);
-                        editPage.EndEdit();
-                    }
+                    string fontName = "Helvetica";
+                    float fontSize = 14;
+                    byte[] fontColor = { 0, 0, 0 };
+                    byte transparency = 255;
+                    bool isBold = false;
+                    bool isItalic = false;
+                    textAreas[0].GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
+                    result = textAreas[0].SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], (byte)(FontOpacitySlider.Value * 255), isBold, isItalic);
+                }
+                else
+                {
+                    result = textAreas[0].SetCharsFontTransparency((byte)(FontOpacitySlider.Value * 255));
                 }
 
                 if (result)
                 {
                     PDFEditHistory editHistory = new PDFEditHistory();
                     editHistory.EditPage = editPage;
-                    if (pdfPage != null)
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, textAreas[0]);
+                }
+            }
+            else
+            {
+                GroupHistory groupHistory = new GroupHistory();
+                foreach (CPDFEditTextArea textArea in textAreas)
+                {
+                    if (textArea.SetCharsFontTransparency((byte)(FontOpacitySlider.Value * 255)))
                     {
+                        PDFEditHistory editHistory = new PDFEditHistory();
+                        editHistory.EditPage = editPage;
                         editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
-                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
                 }
+
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
             }
-             
+
+            editPage.EndEdit();
             if (EditEvents.Count > 0 && textAreas.Count > 0)
             {
                 EditEvents.FirstOrDefault().Transparency = (byte)(FontOpacitySlider.Value * 255);
@@ -214,45 +223,57 @@ namespace ComPDFKit.Controls.Edit
             }
 
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            if (textAreas.Count > 0)
+            if (textAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if (ToolView.CurrentEditAreaObject() != null)
             {
-                bool result = false;
+                bool result;
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(textAreas[0].GetFrame());
+                if (string.IsNullOrEmpty(textAreas[0].SelectText))
+                {
+                    string fontName = "Helvetica";
+                    float fontSize = 14;
+                    byte[] fontColor = { 0, 0, 0 };
+                    byte transparency = 255;
+                    bool isBold = false;
+                    bool isItalic = false;
+                    textAreas[0].GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
+                    result = textAreas[0].SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], (byte)(FontOpacitySlider.Value * 255), isBold, isItalic);
+                }
+                else
+                {
+                    result = textAreas[0].SetCharsFontTransparency((byte)(FontOpacitySlider.Value * 255));
+                }
 
+                if (result)
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, textAreas[0]);
+                }
+            }
+            else
+            {
+                GroupHistory groupHistory = new GroupHistory();
                 foreach (CPDFEditTextArea textArea in textAreas)
                 {
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
-                    if (string.IsNullOrEmpty(textArea.SelectText))
+                    if (textArea.SetCharsFontTransparency((byte)(FontOpacitySlider.Value * 255)))
                     {
-                        string fontName = "Helvetica";
-                        float fontSize = 14;
-                        byte[] fontColor = { 0, 0, 0 };
-                        byte transparency = 255;
-                        bool isBold = false;
-                        bool isItalic = false;
-                        textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
-                        result ^= textArea.SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], (byte)(FontOpacitySlider.Value * 255), isBold, isItalic);
-                    }
-                    else
-                    {
-                        result ^= textArea.SetCharsFontTransparency((byte)(FontOpacitySlider.Value * 255));
-                    }
-
-                    if (result)
-                    {
-                        ToolView.UpdateRender(oldRect, textArea);
-                        editPage.EndEdit();
+                        PDFEditHistory editHistory = new PDFEditHistory();
+                        editHistory.EditPage = editPage;
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
                 }
 
-                PDFEditHistory editHistory = new PDFEditHistory();
-                editHistory.EditPage = editPage;
-                if (pdfPage != null)
-                {
-                    editHistory.PageIndex = pdfPage.PageIndex;
-                }
-                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
             }
-             
+
+            editPage.EndEdit();
             if (EditEvents?.Count > 0 && textAreas.Count > 0)
             {
                 EditEvents.FirstOrDefault().Transparency = (byte)(FontOpacitySlider.Value * 255);
@@ -300,44 +321,57 @@ namespace ComPDFKit.Controls.Edit
         private void TextStyleUI_TextSizeChanged(object sender, double e)
         {
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            if (textAreas.Count > 0)
+            if (textAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if (ToolView.CurrentEditAreaObject() != null)
             {
-                foreach (CPDFEditTextArea textArea in textAreas)
+                bool result;
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(textAreas[0].GetFrame());
+                if (string.IsNullOrEmpty(textAreas[0].SelectText))
                 {
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
-                    bool result;
-                    if (string.IsNullOrEmpty(textArea.SelectText))
-                    {
-                        string fontName = "Helvetica";
-                        float fontSize = 14;
-                        byte[] fontColor = { 0, 0, 0 };
-                        byte transparency = 255;
-                        bool isBold = false;
-                        bool isItalic = false;
-                        textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
-                        result = textArea.SetCurTextStyle(fontName, (float)e, fontColor[0], fontColor[1], fontColor[2], transparency, isBold, isItalic);
-                    }
-                    else
-                    {
-                        result = textArea.SetCharsFontSize((float)e, true);
-                    }
+                    string fontName = "Helvetica";
+                    float fontSize = 14;
+                    byte[] fontColor = { 0, 0, 0 };
+                    byte transparency = 255;
+                    bool isBold = false;
+                    bool isItalic = false;
+                    textAreas[0].GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
+                    result = textAreas[0].SetCurTextStyle(fontName, (float)e, fontColor[0], fontColor[1], fontColor[2], transparency, isBold, isItalic);
+                }
+                else
+                {
+                    result = textAreas[0].SetCharsFontSize((float)e, true);
+                }
 
-                    if (result)
+                if (result)
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, textAreas[0]);
+                }
+            }
+            else
+            {
+                GroupHistory groupHistory = new GroupHistory();
+                foreach (CPDFEditTextArea textArea in textAreas)
+                {
+                    if (textArea.SetCharsFontSize((float)e, true))
                     {
                         PDFEditHistory editHistory = new PDFEditHistory();
                         editHistory.EditPage = editPage;
-                        if (pdfPage != null)
-                        {
-                            editHistory.PageIndex = pdfPage.PageIndex;
-                        }
-                        ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
-                        ToolView.UpdateRender(oldRect, textArea);
-                        editPage.EndEdit();
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
                 }
 
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
             }
 
+            editPage.EndEdit();
             if (EditEvents.Count > 0 && textAreas.Count > 0)
             {
                 EditEvents.FirstOrDefault().FontSize = e;
@@ -359,45 +393,57 @@ namespace ComPDFKit.Controls.Edit
         {
             SolidColorBrush newBrush = FontColorUI.Brush as SolidColorBrush;
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            if (textAreas.Count > 0 && newBrush != null)
+            if (textAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if (ToolView.CurrentEditAreaObject() != null)
             {
-                foreach (CPDFEditTextArea textArea in textAreas)
+                bool result;
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(textAreas[0].GetFrame());
+                if (string.IsNullOrEmpty(textAreas[0].SelectText))
                 {
+                    string fontName = "Helvetica";
+                    float fontSize = 14;
+                    byte[] fontColor = { 0, 0, 0 };
+                    byte transparency = 255;
+                    bool isBold = false;
+                    bool isItalic = false;
+                    textAreas[0].GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
+                    result = textAreas[0].SetCurTextStyle(fontName, fontSize, newBrush.Color.R, newBrush.Color.G, newBrush.Color.B, transparency, isBold, isItalic);
+                }
+                else
+                {
+                    result = textAreas[0].SetCharsFontColor(newBrush.Color.R, newBrush.Color.G, newBrush.Color.B);
+                }
 
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
-                    bool result;
-                    if (string.IsNullOrEmpty(textArea.SelectText))
-                    {
-                        string fontName = "Helvetica";
-                        float fontSize = 14;
-                        byte[] fontColor = { 0, 0, 0 };
-                        byte transparency = 255;
-                        bool isBold = false;
-                        bool isItalic = false;
-                        textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
-                        result = textArea.SetCurTextStyle(fontName, fontSize, newBrush.Color.R, newBrush.Color.G, newBrush.Color.B, transparency, isBold, isItalic);
-                    }
-                    else
-                    {
-                        result = textArea.SetCharsFontColor(newBrush.Color.R, newBrush.Color.G, newBrush.Color.B);
-                    }
-
-                    if (result)
+                if (result)
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, textAreas[0]);
+                }
+            }
+            else
+            {
+                GroupHistory groupHistory = new GroupHistory();
+                foreach (CPDFEditTextArea textArea in textAreas)
+                {
+                    if (textArea.SetCharsFontColor(newBrush.Color.R, newBrush.Color.G, newBrush.Color.B))
                     {
                         PDFEditHistory editHistory = new PDFEditHistory();
                         editHistory.EditPage = editPage;
-                        if (pdfPage != null)
-                        {
-                            editHistory.PageIndex = pdfPage.PageIndex;
-                        }
-
-                        ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
-                        ToolView.UpdateRender(oldRect, textArea);
-                        editPage.EndEdit();
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
+
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                    ToolView.GetCPDFViewer()?.UpdateRenderFrame();
                 }
             }
 
+            editPage.EndEdit();
             if (EditEvents.Count > 0 && newBrush != null)
             {
                 byte[] Color = new byte[3];
@@ -413,12 +459,37 @@ namespace ComPDFKit.Controls.Edit
         private void TextAlignUI_TextAlignChanged(object sender, TextAlignType e)
         {
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            if (textAreas.Count > 0)
+            if (textAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if (ToolView.CurrentEditAreaObject() != null)
+            {
+                bool result;
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(textAreas[0].GetFrame());
+                if (textAreas[0].SelectLineRects != null && textAreas[0].SelectLineRects.Count > 0)
+                {
+                    result = textAreas[0].SetTextRangeAlign(e);
+                }
+                else
+                {
+                    result = textAreas[0].SetTextAreaAlign(e);
+                }
+
+                if (result)
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, textAreas[0]);
+                }
+            }
+            else
             {
+                GroupHistory groupHistory = new GroupHistory();
                 foreach (CPDFEditTextArea textArea in textAreas)
                 {
-                    bool result = false;
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
+                    bool result;
                     if (textArea.SelectLineRects != null && textArea.SelectLineRects.Count > 0)
                     {
                         result = textArea.SetTextRangeAlign(e);
@@ -427,21 +498,21 @@ namespace ComPDFKit.Controls.Edit
                     {
                         result = textArea.SetTextAreaAlign(e);
                     }
+
                     if (result)
                     {
                         PDFEditHistory editHistory = new PDFEditHistory();
                         editHistory.EditPage = editPage;
-                        if (pdfPage != null)
-                        {
-                            editHistory.PageIndex = pdfPage.PageIndex;
-                        }
-                        ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
-                        ToolView.UpdateRender(oldRect, textArea);
-                        editPage.EndEdit();
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
                 }
+
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
             }
 
+            editPage.EndEdit();
             if (EditEvents.Count > 0 && textAreas.Count > 0)
             {
                 EditEvents.FirstOrDefault().TextAlign = e;
@@ -462,44 +533,57 @@ namespace ComPDFKit.Controls.Edit
         private void TextStyleUI_TextItalicChanged(object sender, bool e)
         {
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            if (textAreas.Count > 0)
+            if (textAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if (ToolView.CurrentEditAreaObject() != null)
             {
-                foreach (CPDFEditTextArea textArea in textAreas)
+                bool result;
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(textAreas[0].GetFrame());
+                if (string.IsNullOrEmpty(textAreas[0].SelectText))
                 {
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
-                    bool result;
-                    if (string.IsNullOrEmpty(textArea.SelectText))
-                    {
-                        string fontName = "Helvetica";
-                        float fontSize = 14;
-                        byte[] fontColor = { 0, 0, 0 };
-                        byte transparency = 255;
-                        bool isBold = false;
-                        bool isItalic = false;
-                        textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
-                        result = textArea.SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], transparency, isBold, e);
-                    }
-                    else
-                    {
-                        result = textArea.SetCharsFontItalic(e);
-                    }
+                    string fontName = "Helvetica";
+                    float fontSize = 14;
+                    byte[] fontColor = { 0, 0, 0 };
+                    byte transparency = 255;
+                    bool isBold = false;
+                    bool isItalic = false;
+                    textAreas[0].GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
+                    result = textAreas[0].SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], transparency, isBold, e);
+                }
+                else
+                {
+                    result = textAreas[0].SetCharsFontItalic(e);
+                }
 
-                    if (result)
+                if (result)
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, textAreas[0]);
+                }
+            }
+            else
+            {
+                GroupHistory groupHistory = new GroupHistory();
+                foreach (CPDFEditTextArea textArea in textAreas)
+                {
+                    if (textArea.SetCharsFontItalic(e))
                     {
                         PDFEditHistory editHistory = new PDFEditHistory();
                         editHistory.EditPage = editPage;
-                        if (pdfPage != null)
-                        {
-                            editHistory.PageIndex = pdfPage.PageIndex;
-                        }
-
-                        ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
-                        ToolView.UpdateRender(oldRect, textArea);
-                        editPage.EndEdit();
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
                 }
+
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
             }
 
+            editPage.EndEdit();
             if (EditEvents.Count > 0 && textAreas.Count > 0)
             {
                 EditEvents.FirstOrDefault().IsItalic = e;
@@ -520,43 +604,57 @@ namespace ComPDFKit.Controls.Edit
         private void TextStyleUI_TextBoldChanged(object sender, bool e)
         {
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            if (textAreas.Count > 0)
+            if (textAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if (ToolView.CurrentEditAreaObject() != null)
             {
-                foreach (CPDFEditTextArea textArea in textAreas)
+                bool result;
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(textAreas[0].GetFrame());
+                if (string.IsNullOrEmpty(textAreas[0].SelectText))
                 {
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
-                    bool result;
-                    if (string.IsNullOrEmpty(textArea.SelectText))
-                    {
-                        string fontName = "Helvetica";
-                        float fontSize = 14;
-                        byte[] fontColor = { 0, 0, 0 };
-                        byte transparency = 255;
-                        bool isBold = false;
-                        bool isItalic = false;
-                        textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
-                        result = textArea.SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], transparency, e, isItalic);
-                    }
-                    else
-                    {
-                        result = textArea.SetCharsFontBold(e);
-                    }
+                    string fontName = "Helvetica";
+                    float fontSize = 14;
+                    byte[] fontColor = { 0, 0, 0 };
+                    byte transparency = 255;
+                    bool isBold = false;
+                    bool isItalic = false;
+                    textAreas[0].GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
+                    result = textAreas[0].SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], transparency, e, isItalic);
+                }
+                else
+                {
+                    result = textAreas[0].SetCharsFontBold(e);
+                }
 
-                    if (result)
+                if (result)
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, textAreas[0]);
+                }
+            }
+            else
+            {
+                GroupHistory groupHistory = new GroupHistory();
+                foreach (CPDFEditTextArea textArea in textAreas)
+                {
+                    if (textArea.SetCharsFontBold(e))
                     {
                         PDFEditHistory editHistory = new PDFEditHistory();
                         editHistory.EditPage = editPage;
-                        if (pdfPage != null)
-                        {
-                            editHistory.PageIndex = pdfPage.PageIndex;
-                        }
-                        ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
-                        ToolView.UpdateRender(oldRect, textArea);
-                        editPage.EndEdit();
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
                 }
+
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
             }
 
+            editPage.EndEdit();
             if (EditEvents.Count > 0 && textAreas.Count > 0)
             {
                 EditEvents.FirstOrDefault().IsBold = e;
@@ -577,43 +675,57 @@ namespace ComPDFKit.Controls.Edit
         private void TextStyleUI_TextFontChanged(object sender, string e)
         {
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
-            if (textAreas.Count > 0)
+            if (textAreas.Count == 0 || pdfPage == null || editPage == null)
+                return;
+
+            if (ToolView.CurrentEditAreaObject() != null)
             {
-                foreach (CPDFEditTextArea textArea in textAreas)
+                bool result;
+                Rect oldRect = DataConversionForWPF.CRectConversionForRect(textAreas[0].GetFrame());
+                if (string.IsNullOrEmpty(textAreas[0].SelectText))
                 {
-                    Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
-                    bool result;
-                    if (string.IsNullOrEmpty(textArea.SelectText))
-                    {
-                        string fontName = "Helvetica";
-                        float fontSize = 14;
-                        byte[] fontColor = { 0, 0, 0 };
-                        byte transparency = 255;
-                        bool isBold = false;
-                        bool isItalic = false;
-                        textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
-                        result = textArea.SetCurTextStyle(e, fontSize, fontColor[0], fontColor[1], fontColor[2], transparency, isBold, isItalic);
-                    }
-                    else
-                    {
-                        result = textArea.SetCharsFontName(e);
-                    }
+                    string fontName = "Helvetica";
+                    float fontSize = 14;
+                    byte[] fontColor = { 0, 0, 0 };
+                    byte transparency = 255;
+                    bool isBold = false;
+                    bool isItalic = false;
+                    textAreas[0].GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
+                    result = textAreas[0].SetCurTextStyle(e, fontSize, fontColor[0], fontColor[1], fontColor[2], transparency, isBold, isItalic);
+                }
+                else
+                {
+                    result = textAreas[0].SetCharsFontName(e);
+                }
 
-                    if (result)
+                if (result)
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    editHistory.PageIndex = pdfPage.PageIndex;
+                    ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
+                    ToolView.UpdateRender(oldRect, textAreas[0]);
+                }
+            }
+            else
+            {
+                GroupHistory groupHistory = new GroupHistory();
+                foreach (CPDFEditTextArea textArea in textAreas)
+                {
+                    if (textArea.SetCharsFontName(e))
                     {
                         PDFEditHistory editHistory = new PDFEditHistory();
                         editHistory.EditPage = editPage;
-                        if (pdfPage != null)
-                        {
-                            editHistory.PageIndex = pdfPage.PageIndex;
-                        }
-                        ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
-                        ToolView.UpdateRender(oldRect, textArea);
-                        editPage.EndEdit();
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                        groupHistory.Histories.Add(editHistory);
                     }
                 }
+
+                ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
+                ToolView.GetCPDFViewer()?.UpdateRenderFrame();
             }
 
+            editPage.EndEdit();
             if (EditEvents.Count > 0 && textAreas.Count > 0)
             {
                 EditEvents.FirstOrDefault().FontName = e;
@@ -656,7 +768,7 @@ namespace ComPDFKit.Controls.Edit
             {
                 return;
             }
-            if (EditEvents != null)
+            if (EditEvents != null && EditEvents.Count>0 )
             {
                 try
                 {