From: Jean-Marc Lasgouttes Date: Tue, 22 Feb 2005 11:41:22 +0000 (+0000) Subject: fix several GOTO lfuns (bug 1787, bug 616, bug 781 and bug 835) X-Git-Tag: 1.6.10~14514 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=3f4d173edf668019f3620ab652ebb1de6d5e0e85;p=features.git fix several GOTO lfuns (bug 1787, bug 616, bug 781 and bug 835) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9663 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView.C b/src/BufferView.C index 2011ece20a..918d7a3e33 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -275,9 +275,7 @@ void BufferView::gotoLabel(string const & label) vector 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) { diff --git a/src/BufferView.h b/src/BufferView.h index 88d307daf8..ccd6befaa3 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -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 diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 2527b90044..2ed15ec3ce 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -76,6 +76,7 @@ #include #include +#include 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 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; diff --git a/src/ChangeLog b/src/ChangeLog index 1194eb208c..c3c105139b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,23 @@ +2005-02-14 Jean-Marc Lasgouttes + + * 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 * lyx_main.C (queryUserLyXDir): fix test for rerunning configure diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 74688ae6b4..5559aae990 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -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 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(inset)->getContents() == contents)) { + cur = tmpcur; + return true; + } + tmpcur.forwardInset(); + } + + return false; +} + +} + + +void gotoInset(BufferView * bv, vector 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(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(1, code), same_content); +} + } // namespace bv_funcs diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index 7bc244ac21..712e58d278 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -15,11 +15,13 @@ #define BUFFERVIEW_FUNCS_H #include +#include 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 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 diff --git a/src/lyxtext.h b/src/lyxtext.h index b95d96f181..5153b1e514 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -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 const & codes, - std::string const & contents = std::string()); - /// - void gotoInset(LCursor & cur, - std::vector const & codes, bool same_content); - /// - void gotoInset(LCursor & cur, InsetBase_code code, bool same_content); - /// current text width int width() const; diff --git a/src/text3.C b/src/text3.C index 9ddee5cf60..2b7f2c434f 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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 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(pars_[pit].getInset(pos))->getContents() - == contents))); - - if (pit == end) - return false; - - setCursor(cur, pit, pos, false); - return true; -} - - -void LyXText::gotoInset(LCursor & cur, - vector 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(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(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 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: