ecere/gui/EditBox: Clearing Undo buffer on setting contents
[sdk] / ecere / src / gui / controls / EditBox.ec
index b31dfc0..05816d5 100644 (file)
@@ -298,6 +298,15 @@ public:
       else
          delete action;
    }
+
+   void Clear()
+   {
+      actions.Free();
+      actions.size = 8;
+      count = 0;
+      curAction = 0;
+      firstEvent = true;
+   }
 };
 
 static class AddCharAction : UndoAction
@@ -816,6 +825,8 @@ public:
       {
          if(this)
          {
+            undoBuffer.Clear();
+
             undoBuffer.dontRecord++;
             Deselect();
             DelCh(this.lines.first, 0, 0, this.lines.last, this.lineCount-1, ((EditLine)(this.lines.last)).count, true);
@@ -1648,11 +1659,14 @@ private:
                   th = space.h;
                }
                else
+               {
                   surface.TextExtent2(buffer, line.count, &tw, &th, 0, null, &oh);
+                  tw += countTabsExtraSpaces(buffer, tabSize, 0, line.count) * space.w;
+               }
             }
             else if(line == selStartLine)
             {
-               int prevGlyph;
+               int prevGlyph = 0;
                int start = Min(line.count, selStartX);
                int end   = Min(line.count, selEndX);
                surface.TextExtent2(buffer, start, &tw, &th, 0, &prevGlyph, null);