]> git.lyx.org Git - features.git/commitdiff
fix several GOTO lfuns (bug 1787, bug 616, bug 781 and bug 835)
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 22 Feb 2005 11:41:22 +0000 (11:41 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 22 Feb 2005 11:41:22 +0000 (11:41 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9663 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/ChangeLog
src/bufferview_funcs.C
src/bufferview_funcs.h
src/lyxtext.h
src/text3.C

index 2011ece20ad51217ba871759fcf7664667dd81e4..918d7a3e33c556cc94bdc93fbf9b17fc578a8bd7 100644 (file)
@@ -275,9 +275,7 @@ void BufferView::gotoLabel(string const & label)
                vector<string> labels;
                it->getLabelList(*buffer(), labels);
                if (find(labels.begin(),labels.end(),label) != labels.end()) {
-                       cursor().clearSelection();
-                       text()->setCursor(cursor(), it.pit(), it.pos());
-                       cursor().resetAnchor();
+                       setCursor(it);
                        update();
                        return;
                }
@@ -324,12 +322,13 @@ LyXText * BufferView::text() const
 }
 
 
-void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
+void BufferView::setCursor(DocIterator const & dit)
 {
-       for (int i = 0, n = par.depth(); i < n; ++i)
-               par[i].inset().edit(cursor(), true);
+       size_t const n = dit.depth();
+       for (size_t i = 0; i < n; ++i)
+               dit[i].inset().edit(cursor(), true);
 
-       cursor().setCursor(makeDocIterator(par, pos));
+       cursor().setCursor(dit);
        cursor().selection() = false;
 }
 
@@ -337,11 +336,9 @@ void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
 void BufferView::putSelectionAt(DocIterator const & cur,
                                int length, bool backwards)
 {
-       ParIterator par(cur);
-
        cursor().clearSelection();
 
-       setCursor(par, cur.pos());
+       setCursor(cur);
 
        if (length) {
                if (backwards) {
index 88d307daf82eb60b8eaf02d8419cc545eddd04f6..ccd6befaa38f1280153b2bbddf16609bff9f351a 100644 (file)
@@ -165,7 +165,7 @@ public:
        ///
        LyXText * text() const;
        ///
-       void setCursor(ParIterator const & par, lyx::pos_type pos);
+       void setCursor(DocIterator const &);
        /* Sets the selection. When \c backwards == false, set anchor
         * to \c cur and cursor to \c cur + \c length. When \c
         * backwards == true, set anchor to \c cur and cursor to \c
index 2527b900449661f1b3802714004e85400b2ca28d..2ed15ec3ceadf5bb93e0cf400275892437bd0f78 100644 (file)
@@ -76,6 +76,7 @@
 #include <boost/bind.hpp>
 
 #include <functional>
+#include <vector>
 
 using lyx::pos_type;
 
@@ -96,6 +97,7 @@ using std::min;
 using std::max;
 using std::string;
 using std::mem_fun_ref;
+using std::vector;
 
 
 extern BufferList bufferlist;
@@ -132,7 +134,6 @@ T * getInsetByCode(LCursor & cur, InsetBase::Code code)
        return inset;
 }
 
-
 } // anon namespace
 
 
@@ -722,8 +723,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
        if (par == buffer_->par_iterator_end())
                return;
 
-       bv_->text()->setCursor(cursor_, par.pit(),
-               min(par->size(), saved_positions[i].par_pos));
+       bv_->setCursor(makeDocIterator(par, min(par->size(), saved_positions[i].par_pos)));
 
        if (i > 0)
                owner_->message(bformat(_("Moved to bookmark %1$d"), i));
@@ -966,6 +966,9 @@ FuncStatus BufferView::Pimpl::getStatus(FuncRequest const & cmd)
        case LFUN_BOOKMARK_SAVE:
        case LFUN_REF_GOTO:
        case LFUN_GOTO_PARAGRAPH:
+       case LFUN_GOTOERROR:
+       case LFUN_GOTONOTE:
+       case LFUN_REFERENCE_GOTO:
        case LFUN_WORD_FIND:
        case LFUN_WORD_REPLACE:
        case LFUN_MARK_OFF:
@@ -1102,13 +1105,29 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
                }
 
                // Set the cursor
-               bv_->setCursor(par, 0);
+               bv_->setCursor(makeDocIterator(par, 0));
 
                update();
                switchKeyMap();
                break;
        }
 
+       case LFUN_GOTOERROR:
+               bv_funcs::gotoInset(bv_, InsetBase::ERROR_CODE, false);
+               break;
+
+       case LFUN_GOTONOTE:
+               bv_funcs::gotoInset(bv_, InsetBase::NOTE_CODE, false);
+               break;
+
+       case LFUN_REFERENCE_GOTO: {
+               vector<InsetBase_code> tmp;
+               tmp.push_back(InsetBase::LABEL_CODE);
+               tmp.push_back(InsetBase::REF_CODE);
+               bv_funcs::gotoInset(bv_, tmp, true);
+               break;
+       }
+
        case LFUN_TRACK_CHANGES:
                trackChanges();
                break;
index 1194eb208cf16240b114ff0469210b84d7724e5a..c3c105139b3b41f4ddc048fb2f53e55bbc421ea1 100644 (file)
@@ -1,3 +1,23 @@
+2005-02-14  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * BufferView.C (setCursor): change to use a DocIterator.
+       (gotoLabel): use BufferView::setCursor (other part of bug 781).
+       (putSelectionAt): adapt to BufferView::setCursor change.
+
+       * bufferview_funcs.C (gotoNextInset, gotoInset): new functions,
+       moved here from LyXText and rewritten to use proper cursor
+       methods. Fixes bug 1787, 616 and 835.
+
+       * BufferView_pimpl.C (restorePosition): set the cursor correctly
+       when inside an inset (part of bug 781).
+       (dispatch): adapt to change of BufferView::setCursor.
+       (getStatus, dispatch): handle LFUN_GOTOERROR,
+       LFUN_GOTONOTE and LFUN_REFERENCE_GOTO.
+
+       * text3.C (getStatus, dispatch): do not handle LFUN_GOTOERROR,
+       LFUN_GOTONOTE and LFUN_REFERENCE_GOTO.
+       * text3.C (gotoNextInset, gotoInset): removed.
+
 2005-02-20  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * lyx_main.C (queryUserLyXDir): fix test for rerunning configure
index 74688ae6b43e7459a1a77b96ba84d6f795005fa5..5559aae990a01b4d9dc13d6fe9704de4fc0f3a96 100644 (file)
@@ -33,6 +33,7 @@
 #include "frontends/Alert.h"
 #include "frontends/LyXView.h"
 
+#include "insets/insetcommand.h"
 #include "insets/insettext.h"
 
 #include "support/convert.h"
@@ -44,6 +45,7 @@ using lyx::support::bformat;
 using std::istringstream;
 using std::ostringstream;
 using std::string;
+using std::vector;
 
 
 namespace bv_funcs {
@@ -209,5 +211,66 @@ CurStatus status(BufferView const * bv, DocIterator const & dit)
                return CUR_BELOW;
 }
 
+namespace {
+
+bool gotoNextInset(LCursor & cur,
+                  vector<InsetBase_code> const & codes, 
+                  string const & contents)
+{
+       LCursor tmpcur = cur;
+       
+       while (tmpcur) {
+               InsetBase const * inset = tmpcur.nextInset();
+               if (inset 
+                   && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() 
+                   && (contents.empty() ||
+                       static_cast<InsetCommand const *>(inset)->getContents() == contents)) {
+                       cur = tmpcur;
+                       return true;
+               }
+               tmpcur.forwardInset();
+       }
+
+       return false;
+}
+
+}
+
+
+void gotoInset(BufferView * bv, vector<InsetBase_code> const & codes, 
+              bool same_content)
+{
+       string contents;
+       LCursor tmpcur = bv->cursor();
+       tmpcur.forwardInset();
+
+       if (same_content) {
+               InsetBase const * inset = tmpcur.nextInset();
+               if (inset 
+                   && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
+                       contents = static_cast<InsetCommand const *>(inset)->getContents();
+               }
+       }
+
+       if (!gotoNextInset(tmpcur, codes, contents)) {
+               if (tmpcur != doc_iterator_begin(tmpcur.inset())) {
+                       tmpcur.reset(tmpcur.bottom().inset());
+                       if (!gotoNextInset(tmpcur, codes, contents)) 
+                               bv->cursor().message(_("No more insets"));
+               } else {
+                       bv->cursor().message(_("No more insets"));
+               }
+       }
+       
+       tmpcur.clearSelection();
+       bv->setCursor(tmpcur);
+}
+
+
+void gotoInset(BufferView * bv, InsetBase_code code, bool same_content)
+{
+       gotoInset(bv, vector<InsetBase_code>(1, code), same_content);
+}
+
 
 } // namespace bv_funcs
index 7bc244ac21499e13a4c4a592045f9d9fed5ff41b..712e58d278aa2308fe7d6e10ec5ca5eaa323d078 100644 (file)
 #define BUFFERVIEW_FUNCS_H
 
 #include <string>
+#include <vector>
 
 class LyXFont;
 class Point;
 class DocIterator;
 class BufferView;
+class InsetBase_code;
 
 
 namespace bv_funcs {
@@ -49,6 +51,13 @@ CurStatus status(BufferView const * bv, DocIterator const & dit);
 
 Point coordOffset(DocIterator const & dit);
 
+// Moves cursor to the next inset with one of the given codes.
+void gotoInset(BufferView * bv, std::vector<InsetBase_code> const & codes, 
+              bool same_content);
+
+// Moves cursor to the next inset with given code.
+void gotoInset(BufferView * bv, InsetBase_code code, bool same_content);
+
 
 } // namespace bv_funcs
 
index b95d96f1813f9f6e8348b7b39cf83bed6e5d1cf5..5153b1e5149bf7b05952bf0c6d92e6e0d09bd44a 100644 (file)
@@ -255,16 +255,6 @@ public:
        /// needed to insert the selection
        void insertStringAsParagraphs(LCursor & cur, std::string const & str);
 
-       /// Find next inset of some specified type.
-       bool gotoNextInset(LCursor & cur,
-               std::vector<InsetBase_code> const & codes,
-               std::string const & contents = std::string());
-       ///
-       void gotoInset(LCursor & cur,
-               std::vector<InsetBase_code> const & codes, bool same_content);
-       ///
-       void gotoInset(LCursor & cur, InsetBase_code code, bool same_content);
-
        /// current text width
        int width() const;
 
index 9ddee5cf60f2574b5ce4fd8a2e52492ee0aa6687..2b7f2c434f62abe5f58193da9c9d9ff792daceb0 100644 (file)
@@ -74,10 +74,8 @@ using lyx::support::isStrUnsignedInt;
 using lyx::support::token;
 
 using std::endl;
-using std::find;
 using std::string;
 using std::istringstream;
-using std::vector;
 
 
 extern string current_layout;
@@ -181,77 +179,6 @@ string const freefont2string()
 
 }
 
-bool LyXText::gotoNextInset(LCursor & cur,
-       vector<InsetBase_code> const & codes, string const & contents)
-{
-       BOOST_ASSERT(this == cur.text());
-       pit_type end = paragraphs().size();
-       pit_type pit = cur.pit();
-       pos_type pos = cur.pos();
-
-       InsetBase * inset;
-       do {
-               if (pos + 1 < pars_[pit].size()) {
-                       ++pos;
-               } else  {
-                       ++pit;
-                       pos = 0;
-               }
-
-       } while (pit != end &&
-                !(pars_[pit].isInset(pos) &&
-                  (inset = pars_[pit].getInset(pos)) != 0 &&
-                  find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
-                  (contents.empty() ||
-                   static_cast<InsetCommand *>(pars_[pit].getInset(pos))->getContents()
-                   == contents)));
-
-       if (pit == end)
-               return false;
-
-       setCursor(cur, pit, pos, false);
-       return true;
-}
-
-
-void LyXText::gotoInset(LCursor & cur,
-       vector<InsetBase_code> const & codes, bool same_content)
-{
-       cur.clearSelection();
-
-       string contents;
-       if (same_content
-           && cur.pos() < cur.lastpos()
-           && cur.paragraph().isInset(cur.pos())) {
-               InsetBase const * inset = cur.paragraph().getInset(cur.pos());
-               if (find(codes.begin(), codes.end(), inset->lyxCode())
-                   != codes.end())
-                       contents = static_cast<InsetCommand const *>(inset)->getContents();
-       }
-
-       if (!gotoNextInset(cur, codes, contents)) {
-               if (cur.pos() || cur.pit() != 0) {
-                       CursorSlice tmp = cur.top();
-                       cur.pit() = 0;
-                       cur.pos() = 0;
-                       if (!gotoNextInset(cur, codes, contents)) {
-                               cur.top() = tmp;
-                               cur.message(_("No more insets"));
-                       }
-               } else {
-                       cur.message(_("No more insets"));
-               }
-       }
-       cur.resetAnchor();
-}
-
-
-void LyXText::gotoInset(LCursor & cur, InsetBase_code code, bool same_content)
-{
-       gotoInset(cur, vector<InsetBase_code>(1, code), same_content);
-}
-
-
 bool LyXText::cursorPrevious(LCursor & cur)
 {
        pos_type cpos = cur.pos();
@@ -997,22 +924,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_GOTOERROR:
-               gotoInset(cur, InsetBase::ERROR_CODE, false);
-               break;
-
-       case LFUN_GOTONOTE:
-               gotoInset(cur, InsetBase::NOTE_CODE, false);
-               break;
-
-       case LFUN_REFERENCE_GOTO: {
-               vector<InsetBase_code> tmp;
-               tmp.push_back(InsetBase::LABEL_CODE);
-               tmp.push_back(InsetBase::REF_CODE);
-               gotoInset(cur, tmp, true);
-               break;
-       }
-
        case LFUN_QUOTE: {
                lyx::cap::replaceSelection(cur);
                Paragraph & par = cur.paragraph();
@@ -1887,9 +1798,6 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
        case LFUN_GETLAYOUT:
        case LFUN_LAYOUT:
        case LFUN_PASTESELECTION:
-       case LFUN_GOTOERROR:
-       case LFUN_GOTONOTE:
-       case LFUN_REFERENCE_GOTO:
        case LFUN_DATE_INSERT:
        case LFUN_SELFINSERT:
        case LFUN_INSERT_LABEL: