#include "frontends/Alert.h"
#include "frontends/LyXView.h"
+#include "insets/insetcommand.h"
#include "insets/insettext.h"
-#include "support/tostr.h"
+#include "support/convert.h"
#include <sstream>
using std::istringstream;
using std::ostringstream;
using std::string;
+using std::vector;
namespace bv_funcs {
int y = 0;
// Contribution of nested insets
- for (size_t i = 1; i != dit.size(); ++i) {
+ for (size_t i = 1; i != dit.depth(); ++i) {
CursorSlice const & sl = dit[i];
- int xx = 0, yy = 0;
+ int xx = 0;
+ int yy = 0;
sl.inset().getCursorPos(sl, xx, yy);
x += xx;
y += yy;
y += par.rows()[rit].height();
y += par.rows()[par.pos2row(sl.pos())].ascent();
x += dit.bottom().text()->cursorX(dit.bottom());
- return Point(x,y);
+ // The following correction should not be there at all.
+ // The cusor looks much better with the -1, though.
+ --x;
+ return Point(x, y);
}
Point getPos(DocIterator const & dit)
{
CursorSlice const & bot = dit.bottom();
- CoordCache::InnerParPosCache & cache = theCoords.pars_[bot.text()];
- CoordCache::InnerParPosCache::iterator it = cache.find(bot.pit());
+ CoordCache::InnerParPosCache const & cache = theCoords.getParPos().find(bot.text())->second;
+ CoordCache::InnerParPosCache::const_iterator it = cache.find(bot.pit());
if (it == cache.end()) {
//lyxerr << "cursor out of view" << std::endl;
- return Point(-1,-1);
+ return Point(-1, -1);
}
Point p = coordOffset(dit); // offset from outer paragraph
p.y_ += it->second.y_;
// this could be used elsewhere as well?
CurStatus status(BufferView const * bv, DocIterator const & dit)
{
- CoordCache::InnerParPosCache & cache = theCoords.pars_[dit.bottom().text()];
+ CoordCache::InnerParPosCache const & cache = theCoords.getParPos().find(dit.bottom().text())->second;
if (cache.find(dit.bottom().pit()) != cache.end())
return CUR_INSIDE;
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