]> git.lyx.org Git - features.git/commitdiff
Other small Backspace() fix in text.C and Undo/Redo for insets
authorJürgen Vigna <jug@sad.it>
Tue, 28 Mar 2000 16:18:02 +0000 (16:18 +0000)
committerJürgen Vigna <jug@sad.it>
Tue, 28 Mar 2000 16:18:02 +0000 (16:18 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@633 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/insets/insetcollapsable.C
src/insets/insetfoot.C
src/insets/insettext.C
src/insets/insettext.h
src/text.C

index 5ef10beb740e3f0d1ba9d12a14118111f069a799..40e103f6c19f938af71e4ac3a7b426d47e96049d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2000-03-29  Juergen Vigna  <jug@sad.it>
+
+       * src/insets/insetcollapsable.C (Clone): same as in InsetFoot
+
+       * src/insets/insetfoot.C (Clone): small change as for the below
+       new init function in the text-inset
+
+       * src/insets/insettext.C (init): new function as I've seen that
+       clone did not copy the Paragraph-Data!
+       (LocalDispatch): Added code so that now we have some sort of Undo
+       functionality (well actually we HAVE Undo ;)
+
+       * src/text.C (Backspace): Small fix for the a | a Backspace problem
+
 2000-03-24  Dekel Tsur <dekel@math.tau.ac.il>
        
        * src/paragraph.C (AutoDeleteInsets) Fixed a bug (wrong positions
index 735439b5637bd02247145744026efc8d169856bd..ba13a0c950240b1cf828cea08a47f1a97b6d7871 100644 (file)
@@ -34,7 +34,9 @@ InsetCollapsable::InsetCollapsable(Buffer * bf): InsetText(bf)
 
 Inset * InsetCollapsable::Clone() const
 {
-    Inset * result = new InsetCollapsable(buffer);
+    InsetCollapsable * result = new InsetCollapsable(buffer);
+    result->init(buffer, par);
+
     return result;
 }
 
index 79fbcc83d02f3485640779f7017b38b08e711d9c..05087bb391d89c445e881e4b027744ceaf66d197 100644 (file)
@@ -35,7 +35,9 @@ InsetFoot::InsetFoot(Buffer * bf): InsetCollapsable(bf)
 
 Inset * InsetFoot::Clone() const
 {
-    Inset * result = new InsetFoot(buffer);
+    InsetFoot * result = new InsetFoot(buffer);
+    result->init(buffer, par);
+
     return result;
 }
 
index b1d4e6cf54b4c9154342bcc58bbc3a72dfb2ca7a..54083dbacb29ec29708cc5f04d8be9aa4be7cbaa 100644 (file)
@@ -52,29 +52,39 @@ using std::max;
 #include "Painter.h"
 #include "lyx_gui_misc.h"
 #include "support/LAssert.h"
+#include "lyxtext.h"
+#include "lyxcursor.h"
 
 extern unsigned char getCurrentTextClass(Buffer *);
 
 InsetText::InsetText(Buffer * buf)
 {
     par = new LyXParagraph();
-    the_locking_inset = 0;
-    buffer = buf;
-    cursor_visible = false;
-    maxWidth = old_x = -1;
-    actpos = selection_start = selection_end = 0;
-    interline_space = 1;
-    no_selection = false;
-    init_inset = true;
-    maxAscent = maxDescent = insetWidth = widthOffset = 0;
-    autoBreakRows = false;
-    xpos = 0.0;
+    init(buf);
 }
 
 
 InsetText::InsetText(InsetText const & ins, Buffer * buf)
 {
-    par = new LyXParagraph(ins.par);
+    par = 0;
+    init(buf, ins.par);
+}
+
+void InsetText::init(Buffer * buf, LyXParagraph *p)
+{
+    if (p) {
+       if (par)
+           delete par;
+       par = new LyXParagraph(p);
+       for(int pos = 0; pos < p->Last(); ++pos) {
+           par->InsertChar(pos, p->GetChar(pos));
+           par->SetFont(pos, p->GetFontSettings(pos));
+           if ((p->GetChar(pos) == LyXParagraph::META_INSET) &&
+               p->GetInset(pos)) {
+               par->InsertInset(pos, p->GetInset(pos)->Clone());
+           }
+       }
+    }
     the_locking_inset = 0;
     buffer = buf;
     cursor_visible = false;
@@ -323,6 +333,7 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
     setPos(bv, x,y);
     selection_start = selection_end = actpos;
     current_font = real_current_font = GetFont(par, actpos);
+    bv->text->FinishUndo();
 }
 
 
@@ -482,6 +493,9 @@ InsetText::LocalDispatch(BufferView * bv,
     switch (action) {
        // Normal chars
     case -1:
+       bv->text->SetUndo(Undo::INSERT, 
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        cutSelection();
        actpos = selection_start;
        par->InsertChar(actpos,arg[0]);
@@ -492,11 +506,13 @@ InsetText::LocalDispatch(BufferView * bv,
        break;
         // --- Cursor Movements ---------------------------------------------
     case LFUN_RIGHTSEL:
+       bv->text->FinishUndo();
        moveRight(bv, false);
        selection_end = actpos;
        UpdateLocal(bv, false);
        break;
     case LFUN_RIGHT:
+       bv->text->FinishUndo();
        result= DISPATCH_RESULT(moveRight(bv));
        if (hasSelection()) {
            selection_start = selection_end = actpos;
@@ -506,25 +522,29 @@ InsetText::LocalDispatch(BufferView * bv,
        }
        break;
     case LFUN_LEFTSEL:
+       bv->text->FinishUndo();
        moveLeft(bv, false);
        selection_end = actpos;
        UpdateLocal(bv, false);
        break;
     case LFUN_LEFT:
-          result= DISPATCH_RESULT(moveLeft(bv));
-         if (hasSelection()) {
-             selection_start = selection_end = actpos;
-             UpdateLocal(bv, false);
-         } else {
-             selection_start = selection_end = actpos;
-         }
-          break;
+       bv->text->FinishUndo();
+       result= DISPATCH_RESULT(moveLeft(bv));
+       if (hasSelection()) {
+               selection_start = selection_end = actpos;
+               UpdateLocal(bv, false);
+       } else {
+               selection_start = selection_end = actpos;
+       }
+       break;
     case LFUN_DOWNSEL:
+       bv->text->FinishUndo();
        moveDown(bv, false);
        selection_end = actpos;
        UpdateLocal(bv, false);
        break;
     case LFUN_DOWN:
+       bv->text->FinishUndo();
        result= DISPATCH_RESULT(moveDown(bv));
        if (hasSelection()) {
            selection_start = selection_end = actpos;
@@ -534,11 +554,13 @@ InsetText::LocalDispatch(BufferView * bv,
        }
        break;
     case LFUN_UPSEL:
+       bv->text->FinishUndo();
        moveUp(bv, false);
        selection_end = actpos;
        UpdateLocal(bv, false);
        break;
     case LFUN_UP:
+       bv->text->FinishUndo();
        result= DISPATCH_RESULT(moveUp(bv));
        if (hasSelection()) {
            selection_start = selection_end = actpos;
@@ -548,7 +570,7 @@ InsetText::LocalDispatch(BufferView * bv,
        }
        break;
     case LFUN_BACKSPACE:
-       if (!actpos || par->IsNewline(actpos-1)) {
+       if (!actpos) { // || par->IsNewline(actpos-1)) {
            if (hasSelection()) {
                selection_start = selection_end = actpos;
                UpdateLocal(bv, false);
@@ -558,6 +580,9 @@ InsetText::LocalDispatch(BufferView * bv,
        moveLeft(bv);
     case LFUN_DELETE:
        bool ret;
+       bv->text->SetUndo(Undo::DELETE, 
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        if (hasSelection())
            ret = cutSelection();
        else
@@ -571,6 +596,9 @@ InsetText::LocalDispatch(BufferView * bv,
        }
        break;
     case LFUN_CUT:
+       bv->text->SetUndo(Undo::DELETE, 
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        if (cutSelection()) { // we need update
            actpos = selection_end = selection_start;
            UpdateLocal(bv, true);
@@ -580,6 +608,7 @@ InsetText::LocalDispatch(BufferView * bv,
        }
        break;
     case LFUN_COPY:
+       bv->text->FinishUndo();
        if (copySelection()) { // we need update
            selection_start = selection_end = actpos;
            UpdateLocal(bv, true);
@@ -589,12 +618,16 @@ InsetText::LocalDispatch(BufferView * bv,
        }
        break;
     case LFUN_PASTE:
+       bv->text->SetUndo(Undo::INSERT, 
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        if (pasteSelection()) {
            selection_start = selection_end = actpos;
            UpdateLocal(bv, true);
        }
        break;
     case LFUN_HOME:
+       bv->text->FinishUndo();
        for(; actpos > rows[actrow].pos; --actpos)
            cx -= SingleWidth(bv->getPainter(), par, actpos);
        cx -= SingleWidth(bv->getPainter(), par, actpos);
@@ -607,6 +640,7 @@ InsetText::LocalDispatch(BufferView * bv,
        break;
     case LFUN_END:
     {
+       bv->text->FinishUndo();
        int checkpos = (int)rows[actrow + 1].pos;
        if ((actrow + 2) < (int)rows.size())
            --checkpos;
@@ -621,6 +655,9 @@ InsetText::LocalDispatch(BufferView * bv,
     }
     break;
     case LFUN_MATH_MODE:   // Open or create a math inset
+       bv->text->SetUndo(Undo::INSERT, 
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        InsertInset(bv, new InsetFormula);
        if (hasSelection()) {
            selection_start = selection_end = actpos;
@@ -630,6 +667,9 @@ InsetText::LocalDispatch(BufferView * bv,
        }
        return DISPATCHED;
     case LFUN_BREAKLINE:
+       bv->text->SetUndo(Undo::INSERT, 
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+           bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        par->InsertChar(actpos,LyXParagraph::META_NEWLINE);
        par->SetFont(actpos,real_current_font);
        UpdateLocal(bv, true);
@@ -1233,8 +1273,6 @@ void InsetText::computeTextRows(Painter & pain, float x) const
            width -= lastWordWidth;
        } else {
            // assign last row data
-//         width = lastWordWidth;
-//         lastWordWidth = 0;
            rows.back().asc = max(oasc, wordAscent);
            rows.back().desc = max(odesc, wordDescent);
        }
index 6a744589bf4f374c95c0fb1ed59b1df8aa1f2d87..85067aab78cde83d96704402edbb0dce188489f4 100644 (file)
@@ -101,6 +101,8 @@ public:
     UpdatableInset * GetLockingInset();
     ///
     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
+    ///
+    void init(Buffer *, LyXParagraph * p = 0);
 
     LyXParagraph * par;
 
index a121c7b09ac7e532bb80b9802e2a62f3098507c4..1043b7038d628776eb4cea8fc06e5b37ac26a6c4 100644 (file)
@@ -3454,7 +3454,19 @@ void LyXText::Backspace()
                SetUndo(Undo::DELETE, 
                        cursor.par->ParFromPos(cursor.pos)->previous, 
                        cursor.par->ParFromPos(cursor.pos)->next); 
-               CursorLeftIntern();
+               // We used to do CursorLeftIntern() here, but it is
+               // not a good idea since it triggers the auto-delete
+               // mechanism. So we do a CursorLeftIntern()-lite,
+               // without the dreaded mechanism. (JMarc)
+               if (cursor.pos > 0) {
+                       SetCursorIntern(cursor.par, cursor.pos - 1);
+               }
+               else if (cursor.par->Previous()) { 
+                       // steps into the above paragraph.
+                       SetCursorIntern(cursor.par->Previous(), 
+                                       cursor.par->Previous()->Last());
+               }
+//             CursorLeftIntern();
                
                // some insets are undeletable here
                if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {