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;
}
}
-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;
}
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) {
///
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
#include <boost/bind.hpp>
#include <functional>
+#include <vector>
using lyx::pos_type;
using std::max;
using std::string;
using std::mem_fun_ref;
+using std::vector;
extern BufferList bufferlist;
return inset;
}
-
} // anon namespace
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));
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:
}
// 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;
+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
#include "frontends/Alert.h"
#include "frontends/LyXView.h"
+#include "insets/insetcommand.h"
#include "insets/insettext.h"
#include "support/convert.h"
using std::istringstream;
using std::ostringstream;
using std::string;
+using std::vector;
namespace bv_funcs {
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
#define BUFFERVIEW_FUNCS_H
#include <string>
+#include <vector>
class LyXFont;
class Point;
class DocIterator;
class BufferView;
+class InsetBase_code;
namespace bv_funcs {
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
/// 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;
using lyx::support::token;
using std::endl;
-using std::find;
using std::string;
using std::istringstream;
-using std::vector;
extern string current_layout;
}
-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();
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();
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: