- old.endUndoGroup();
- }
-
- // update completion. We do it here and not in
- // processKeySym to avoid another redraw just for a
- // changed inline completion
- if (cmd.origin() == FuncRequest::KEYBOARD) {
- if (cmd.action() == LFUN_SELF_INSERT
- || (cmd.action() == LFUN_ERT_INSERT && bv->cursor().inMathed()))
- current_view_->updateCompletion(bv->cursor(), true, true);
- else if (cmd.action() == LFUN_CHAR_DELETE_BACKWARD)
- current_view_->updateCompletion(bv->cursor(), false, true);
- else
- current_view_->updateCompletion(bv->cursor(), false, false);
- }
-
- dr = bv->cursor().result();
+
+ // OK, so try the current Buffer itself...
+ bv->buffer().dispatch(cmd, dr);
+ if (dr.dispatched())
+ break;
+
+ // and with the document Buffer.
+ if (doc_bv) {
+ doc_bv->buffer().dispatch(cmd, dr);
+ if (dr.dispatched())
+ break;
+ }
+
+ // Let the current Cursor dispatch its own actions.
+ Cursor old = bv->cursor();
+ bv->cursor().dispatch(cmd);
+
+ // notify insets we just left
+ // FIXME: move this code to Cursor::dispatch
+ if (bv->cursor() != old) {
+ old.beginUndoGroup();
+ old.fixIfBroken();
+ bool badcursor = notifyCursorLeavesOrEnters(old, bv->cursor());
+ if (badcursor) {
+ bv->cursor().fixIfBroken();
+ bv->fixInlineCompletionPos();
+ }
+ old.endUndoGroup();
+ }
+
+ // update completion. We do it here and not in
+ // processKeySym to avoid another redraw just for a
+ // changed inline completion
+ if (cmd.origin() == FuncRequest::KEYBOARD) {
+ if (cmd.action() == LFUN_SELF_INSERT
+ || (cmd.action() == LFUN_ERT_INSERT && bv->cursor().inMathed()))
+ current_view_->updateCompletion(bv->cursor(), true, true);
+ else if (cmd.action() == LFUN_CHAR_DELETE_BACKWARD)
+ current_view_->updateCompletion(bv->cursor(), false, true);
+ else
+ current_view_->updateCompletion(bv->cursor(), false, false);
+ }
+
+ dr = bv->cursor().result();