- // no such inset found, just take something "above"
- if (!popLeft()) {
- //lyxerr << "updown: popleft failed (strange case)" << endl;
- int ylow = up ? 0 : yo + 1;
- int yhigh = up ? yo - 1 : bv().workHeight();
- return bruteFind(*this, xo, yo, 0, bv().workWidth(), ylow, yhigh);
+ // with and without selection are handled differently
+ if (!selection()) {
+ int yo = bv().getPos(*this, boundary()).y_;
+ Cursor old = *this;
+ // To next/previous row
+ if (up)
+ tm.editXY(*this, xo, yo - textRow().ascent() - 1);
+ else
+ tm.editXY(*this, xo, yo + textRow().descent() + 1);
+ clearSelection();
+
+ // This happens when you move out of an inset.
+ // And to give the DEPM the possibility of doing
+ // something we must provide it with two different
+ // cursors. (Lgb)
+ Cursor dummy = *this;
+ if (dummy == old)
+ ++dummy.pos();
+ if (bv().checkDepm(dummy, old)) {
+ updateNeeded = true;
+ // Make sure that cur gets back whatever happened to dummy(Lgb)
+ operator=(dummy);
+ }
+ } else {
+ // if there is a selection, we stay out of any inset, and just jump to the right position:
+ Cursor old = *this;
+ if (up) {
+ if (row > 0) {
+ top().pos() = std::min(tm.x2pos(pit(), row - 1, xo), top().lastpos());
+ } else if (pit() > 0) {
+ --pit();
+ ParagraphMetrics const & pmcur = bv_->parMetrics(text(), pit());
+ top().pos() = std::min(tm.x2pos(pit(), pmcur.rows().size() - 1, xo), top().lastpos());
+ }
+ } else {
+ if (row + 1 < int(pm.rows().size())) {
+ top().pos() = std::min(tm.x2pos(pit(), row + 1, xo), top().lastpos());
+ } else if (pit() + 1 < int(text()->paragraphs().size())) {
+ ++pit();
+ top().pos() = std::min(tm.x2pos(pit(), 0, xo), top().lastpos());
+ }