- // built temporary path to inset
- LyXText * text = bv_->text();
- InsetBase * const inset_hit = text->checkInsetHit(cmd.x, cmd.y);
- if (inset_hit)
- inset_hit->edit(cur, cmd.x, cmd.y);
+ // Either the inset under the cursor or the
+ // surrounding LyXText will handle this event.
+
+ // Build temporary cursor.
+ cmd.y = min(max(cmd.y,-1), workarea().workHeight());
+ InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y);
+ //lyxerr << BOOST_CURRENT_FUNCTION
+ // << " * hit inset at tip: " << inset << endl;
+ //lyxerr << BOOST_CURRENT_FUNCTION
+ // << " * created temp cursor:" << cur << endl;
+
+ // Put anchor at the same position.
+ cur.resetAnchor();
+
+ // Try to dispatch to an non-editable inset near this position
+ // via the temp cursor. If the inset wishes to change the real
+ // cursor it has to do so explicitly by using
+ // cur.bv().cursor() = cur; (or similar)
+ if (inset)
+ inset->dispatch(cur, cmd);
+
+ // Now dispatch to the temporary cursor. If the real cursor should
+ // be modified, the inset's dispatch has to do so explicitly.
+ if (!cur.result().dispatched())
+ cur.dispatch(cmd);
+
+ if (cur.result().dispatched()) {
+ // Redraw if requested or necessary.
+ if (cur.result().update())
+ update(Update::FitCursor | Update::Force);