bool Cursor::popBackward()
{
BOOST_ASSERT(!empty());
- //lyxerr << "Leaving inset from in front" << endl;
- inset().notifyCursorLeaves(*this);
if (depth() == 1)
return false;
pop();
BOOST_ASSERT(!empty());
//lyxerr << "Leaving inset from in back" << endl;
const pos_type lp = (depth() > 1) ? (*this)[depth() - 2].lastpos() : 0;
- inset().notifyCursorLeaves(*this);
if (depth() == 1)
return false;
pop();
// known position around the cursor:
pos_type known_pos = boundary() ? pos() - 1 : pos();
+ // edge case: if we're at the end of the paragraph, things are a little
+ // different (because lastpos is a position which does not really "exist"
+ // --- there's no character there yet).
+ if (known_pos == lastpos()) {
+ if (par.isRTL(buf.params())) {
+ left_pos = -1;
+ right_pos = bidi.vis2log(row.pos());
+ }
+ else { // LTR paragraph
+ right_pos = -1;
+ left_pos = bidi.vis2log(row.endpos() - 1);
+ }
+ return;
+ }
+
// Whether 'known_pos' is to the left or to the right of the cursor depends
// on whether it is an RTL or LTR character...
bool const cur_is_RTL =
// determine the other one:
if (known_pos_on_right) {
- // edge-case: we're at the end of the paragraph, there isn't really any
- // position any further to the right
- if (known_pos == lastpos()) {
- right_pos = -1;
- left_pos = row.endpos() - 1;
- return;
- }
- // the normal case
right_pos = known_pos;
// *visual* position of 'left_pos':
pos_type v_left_pos = bidi.log2vis(right_pos) - 1;
}
}
else { // known_pos is on the left
- // edge-case: we're at the end of the paragraph, there isn't really any
- // position any further to the left
- if (known_pos == lastpos()) {
- left_pos = -1;
- right_pos = row.endpos() - 1;
- return;
- }
- // the normal case
left_pos = known_pos;
// *visual* position of 'right_pos'
pos_type v_right_pos = bidi.log2vis(left_pos) + 1;
}
-bool notifyCursorLeaves(DocIterator const & old, Cursor & cur)
+bool notifyCursorLeaves(Cursor const & old, Cursor & cur)
{
// find inset in common
size_type i;
// notify everything on top of the common part in old cursor,
// but stop if the inset claims the cursor to be invalid now
for (; i < old.depth(); ++i) {
- if (old[i].inset().notifyCursorLeaves(cur))
+ Cursor insetPos = old;
+ insetPos.cutOff(i);
+ if (old[i].inset().notifyCursorLeaves(insetPos, cur))
return true;
}