]> git.lyx.org Git - features.git/commitdiff
fix bug 1892 (cursor moves when inserting index or tabular)
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 30 May 2005 15:35:11 +0000 (15:35 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 30 May 2005 15:35:11 +0000 (15:35 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9984 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/factory.C
src/lyxtext.h
src/text2.C
src/text3.C

index dc693f13f7237d598bbd15ccbd10c4cb2cbf50a9..cb46f40a5d761d83b614165f4fbbb4b039da1fa6 100644 (file)
@@ -1,3 +1,18 @@
+2005-05-27  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       Fix bug 1892:
+       
+       * text2.C (getStringToIndex): constify cur argument.
+
+       * factory.C (createInset/LFUN_TABULAR_INSERT): return 0 if no
+       argument has been given
+       (createInset/LFUN_INDEX_INSERT): just return a new inset (do not
+       try to invoke LFUN_INSET_APPLY).
+
+       * text3.C (dispatch/LFUN_TABULAR_INSERT): open the tabular dialog
+       if no inset was created by doInsertInset
+       (doInsertInset): return true if an inset has been inserted.
+
 2005-05-23  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * vspace.C (asGUIName): new method. A version of the space
index ad810c39af9f66d60e7e43c21de736c0773f222a..9b3258a59351e31c8699750d7f8949ac8ad1a471 100644 (file)
@@ -56,9 +56,6 @@
 #include "mathed/math_macrotemplate.h"
 #include "mathed/math_hullinset.h"
 
-#include "frontends/Dialogs.h"
-#include "frontends/LyXView.h"
-
 #include "support/lstrings.h"
 
 #include <boost/assert.hpp>
@@ -163,15 +160,8 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
                        cmd.argument;
                icp.setContents(contents);
 
-               string data = InsetCommandMailer::params2string("index", icp);
-               LyXView * lv = bv->owner();
+               return new InsetIndex(icp);
 
-               if (icp.getContents().empty()) {
-                       lv->getDialogs().show("index", data, 0);
-               } else {
-                       lv->dispatch(FuncRequest(LFUN_INSET_APPLY, data));
-               }
-               return 0;
        }
 
        case LFUN_TABULAR_INSERT:
@@ -183,7 +173,6 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
                        if (c <= 0) c = 2;
                        return new InsetTabular(*bv->buffer(), r, c);
                }
-               bv->owner()->getDialogs().show("tabularcreate");
                return 0;
 
        case LFUN_INSET_CAPTION: {
index a8563e083ec5ad89db7279556b4f7219592967ba..3e67c12b3a50d0606eecc15d61f0f45a45aa9723 100644 (file)
@@ -105,7 +105,7 @@ public:
        void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
 
        ///
-       std::string getStringToIndex(LCursor & cur);
+       std::string getStringToIndex(LCursor const & cur);
 
        /// insert a character at cursor position
        void insertChar(LCursor & cur, char c);
index 858116590dda2bd8ad39d37905188a33082c3eb9..7b51412d69a4f22cb796d5eb09fc8748e1cc73a6 100644 (file)
@@ -527,31 +527,27 @@ void LyXText::toggleFree(LCursor & cur, LyXFont const & font, bool toggleall)
 }
 
 
-string LyXText::getStringToIndex(LCursor & cur)
+string LyXText::getStringToIndex(LCursor const & cur)
 {
        BOOST_ASSERT(this == cur.text());
-       // Try implicit word selection
-       // If there is a change in the language the implicit word selection
-       // is disabled.
-       CursorSlice const reset_cursor = cur.top();
-       bool const implicitSelection =
-               selectWordWhenUnderCursor(cur, lyx::PREVIOUS_WORD);
 
        string idxstring;
-       if (!cur.selection())
-               cur.message(_("Nothing to index!"));
-       else if (cur.selBegin().pit() != cur.selEnd().pit())
-               cur.message(_("Cannot index more than one paragraph!"));
-       else
+       if (cur.selection()) {
                idxstring = cur.selectionAsString(false);
-
-       // Reset cursors to their original position.
-       cur.top() = reset_cursor;
-       cur.resetAnchor();
-
-       // Clear the implicit selection.
-       if (implicitSelection)
-               cur.clearSelection();
+       } else {
+               // Try implicit word selection. If there is a change
+               // in the language the implicit word selection is
+               // disabled.
+               LCursor tmpcur = cur;
+               selectWord(tmpcur, lyx::PREVIOUS_WORD);
+
+               if (!tmpcur.selection())
+                       cur.message(_("Nothing to index!"));
+               else if (tmpcur.selBegin().pit() != tmpcur.selEnd().pit())
+                       cur.message(_("Cannot index more than one paragraph!"));
+               else
+                       idxstring = tmpcur.selectionAsString(false);
+       }
 
        return idxstring;
 }
index 1f706305193f81c68058b2f9a2b366e563609f65..5bb93fc65f31603acebe716b75fbc4e49d060fbc 100644 (file)
@@ -235,12 +235,12 @@ void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
 }
 
 
-void doInsertInset(LCursor & cur, LyXText * text,
+bool doInsertInset(LCursor & cur, LyXText * text,
        FuncRequest const & cmd, bool edit, bool pastesel)
 {
        InsetBase * inset = createInset(&cur.bv(), cmd);
        if (!inset)
-               return;
+               return false;
 
        recordUndo(cur);
        bool gotsel = false;
@@ -255,6 +255,7 @@ void doInsertInset(LCursor & cur, LyXText * text,
 
        if (gotsel && pastesel)
                cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
+       return true;
 }
 
 
@@ -1182,7 +1183,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_INSET_FOOTNOTE:
        case LFUN_INSET_MARGINAL:
        case LFUN_INSET_OPTARG:
-       case LFUN_TABULAR_INSERT:
        case LFUN_ENVIRONMENT_INSERT:
                // Open the inset, and move the current selection
                // inside it.
@@ -1190,6 +1190,15 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                cur.posRight();
                break;
 
+       case LFUN_TABULAR_INSERT:
+               // if there were no arguments, just open the dialog
+               if (doInsertInset(cur, this, cmd, false, true))
+                       cur.posRight();
+               else
+                       bv->owner()->getDialogs().show("tabularcreate");
+
+               break;
+
        case LFUN_INSET_FLOAT:
        case LFUN_INSET_WIDE_FLOAT:
        case LFUN_INSET_WRAP: