Re: [PATCH] Bug 1892: inserting an index or a tabular can move the cursor.
Jean-Marc == Jean-Marc Lasgouttes [EMAIL PROTECTED] writes: Jean-Marc Here is a patch for this bug, which boils down to: Jean-Marc createInset should create insets, and dispatch is Jean-Marc responsible for spawning dialogs if needed. The Jean-Marc constification of getStringToIndex is not needed, but I Jean-Marc think it is better. Jean-Marc I will commit on monday if nobody objects. I did it. JMarc
Re: [PATCH] Bug 1892: inserting an index or a tabular can move the cursor.
> "Jean-Marc" == Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes: Jean-Marc> Here is a patch for this bug, which boils down to: Jean-Marc> createInset should create insets, and dispatch is Jean-Marc> responsible for spawning dialogs if needed. The Jean-Marc> constification of getStringToIndex is not needed, but I Jean-Marc> think it is better. Jean-Marc> I will commit on monday if nobody objects. I did it. JMarc
[PATCH] Bug 1892: inserting an index or a tabular can move the cursor.
Here is a patch for this bug, which boils down to: createInset should create insets, and dispatch is responsible for spawning dialogs if needed. The constification of getStringToIndex is not needed, but I think it is better. I will commit on monday if nobody objects. JMarc Index: ChangeLog === RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.2188 diff -u -p -r1.2188 ChangeLog --- ChangeLog 24 May 2005 10:23:29 - 1.2188 +++ ChangeLog 27 May 2005 13:28:15 - @@ -1,3 +1,18 @@ +2005-05-27 Jean-Marc Lasgouttes [EMAIL PROTECTED] + + 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 [EMAIL PROTECTED] * vspace.C (asGUIName): new method. A version of the space Index: factory.C === RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/factory.C,v retrieving revision 1.96 diff -u -p -r1.96 factory.C --- factory.C 4 May 2005 11:21:13 - 1.96 +++ factory.C 27 May 2005 13:28:15 - @@ -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, 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, if (c = 0) c = 2; return new InsetTabular(*bv-buffer(), r, c); } - bv-owner()-getDialogs().show(tabularcreate); return 0; case LFUN_INSET_CAPTION: { Index: lyxtext.h === RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v retrieving revision 1.321 diff -u -p -r1.321 lyxtext.h --- lyxtext.h 12 Apr 2005 18:42:24 - 1.321 +++ lyxtext.h 27 May 2005 13:28:15 - @@ -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: text2.C === RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v retrieving revision 1.607 diff -u -p -r1.607 text2.C --- text2.C 26 Apr 2005 11:12:12 - 1.607 +++ text2.C 27 May 2005 13:28:15 - @@ -527,31 +527,27 @@ void LyXText::toggleFree(LCursor cur, } -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); + } 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); - // Reset cursors to their original position. - cur.top() = reset_cursor; - cur.resetAnchor(); - - // Clear the implicit selection. - if (implicitSelection) - cur.clearSelection(); + 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: text3.C === RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v retrieving revision 1.293 diff -u -p -r1.293 text3.C --- text3.C 5 May 2005 13:13:56 - 1.293 +++ text3.C 27 May 2005 13:28:15 - @@ -235,12 +235,12 @@ void specialChar(LCursor cur, InsetSpe } -void doInsertInset(LCursor cur,
[PATCH] Bug 1892: inserting an index or a tabular can move the cursor.
Here is a patch for this bug, which boils down to: createInset should create insets, and dispatch is responsible for spawning dialogs if needed. The constification of getStringToIndex is not needed, but I think it is better. I will commit on monday if nobody objects. JMarc Index: ChangeLog === RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.2188 diff -u -p -r1.2188 ChangeLog --- ChangeLog 24 May 2005 10:23:29 - 1.2188 +++ ChangeLog 27 May 2005 13:28:15 - @@ -1,3 +1,18 @@ +2005-05-27 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> + + 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 <[EMAIL PROTECTED]> * vspace.C (asGUIName): new method. A version of the space Index: factory.C === RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/factory.C,v retrieving revision 1.96 diff -u -p -r1.96 factory.C --- factory.C 4 May 2005 11:21:13 - 1.96 +++ factory.C 27 May 2005 13:28:15 - @@ -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 @@ -163,15 +160,8 @@ InsetBase * createInset(BufferView * bv, 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, if (c <= 0) c = 2; return new InsetTabular(*bv->buffer(), r, c); } - bv->owner()->getDialogs().show("tabularcreate"); return 0; case LFUN_INSET_CAPTION: { Index: lyxtext.h === RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v retrieving revision 1.321 diff -u -p -r1.321 lyxtext.h --- lyxtext.h 12 Apr 2005 18:42:24 - 1.321 +++ lyxtext.h 27 May 2005 13:28:15 - @@ -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: text2.C === RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v retrieving revision 1.607 diff -u -p -r1.607 text2.C --- text2.C 26 Apr 2005 11:12:12 - 1.607 +++ text2.C 27 May 2005 13:28:15 - @@ -527,31 +527,27 @@ void LyXText::toggleFree(LCursor & cur, } -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); + } 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); - // Reset cursors to their original position. - cur.top() = reset_cursor; - cur.resetAnchor(); - - // Clear the implicit selection. - if (implicitSelection) - cur.clearSelection(); + 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: text3.C === RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v retrieving revision 1.293 diff -u -p -r1.293 text3.C --- text3.C 5 May 2005 13:13:56 - 1.293 +++ text3.C 27 May 2005 13:28:15 - @@ -235,12 +235,12 @@ void specialChar(LCursor & cur, InsetSpe } -void