GuiView::dispatchToBufferView(): simplify code and move some to Cursor::dispatch().

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36733 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2010-12-05 00:57:04 +00:00
parent 2a11b8347c
commit ae7bcd3312
2 changed files with 41 additions and 35 deletions

View File

@ -333,6 +333,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
fixIfBroken(); fixIfBroken();
FuncRequest cmd = cmd0; FuncRequest cmd = cmd0;
Cursor safe = *this; Cursor safe = *this;
Cursor old = *this;
disp_ = DispatchResult(); disp_ = DispatchResult();
buffer()->undo().beginUndoGroup(); buffer()->undo().beginUndoGroup();
@ -393,6 +394,18 @@ void Cursor::dispatch(FuncRequest const & cmd0)
beforeDispatchCursor_ = safe.beforeDispatchCursor_; beforeDispatchCursor_ = safe.beforeDispatchCursor_;
} }
buffer()->undo().endUndoGroup(); buffer()->undo().endUndoGroup();
// notify insets we just left
if (*this != old) {
old.beginUndoGroup();
old.fixIfBroken();
bool badcursor = notifyCursorLeavesOrEnters(old, *this);
if (badcursor) {
fixIfBroken();
bv().fixInlineCompletionPos();
}
old.endUndoGroup();
}
} }

View File

@ -3026,53 +3026,46 @@ void GuiView::dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr)
// Let the current BufferView dispatch its own actions. // Let the current BufferView dispatch its own actions.
bv->dispatch(cmd, dr); bv->dispatch(cmd, dr);
if (dr.dispatched())
return;
// Try with the document BufferView dispatch if any. // Try with the document BufferView dispatch if any.
BufferView * doc_bv = documentBufferView(); BufferView * doc_bv = documentBufferView();
if (doc_bv && !dr.dispatched()) if (doc_bv) {
doc_bv->dispatch(cmd, dr); doc_bv->dispatch(cmd, dr);
if (dr.dispatched())
return;
}
// OK, so try the current Buffer itself... // OK, so try the current Buffer itself...
if (!dr.dispatched()) bv->buffer().dispatch(cmd, dr);
bv->buffer().dispatch(cmd, dr); if (dr.dispatched())
return;
// and with the document Buffer. // and with the document Buffer.
if (doc_bv && !dr.dispatched()) if (doc_bv) {
doc_bv->buffer().dispatch(cmd, dr); doc_bv->buffer().dispatch(cmd, dr);
if (dr.dispatched())
return;
}
// Then let the current Cursor dispatch its own actions. // Then let the current Cursor dispatch its own actions.
if (!dr.dispatched()) { bv->cursor().dispatch(cmd);
Cursor old = bv->cursor();
bv->cursor().dispatch(cmd);
// notify insets we just left // update completion. We do it here and not in
// FIXME: move this code to Cursor::dispatch // processKeySym to avoid another redraw just for a
if (bv->cursor() != old) { // changed inline completion
old.beginUndoGroup(); if (cmd.origin() == FuncRequest::KEYBOARD) {
old.fixIfBroken(); if (cmd.action() == LFUN_SELF_INSERT
bool badcursor = notifyCursorLeavesOrEnters(old, bv->cursor()); || (cmd.action() == LFUN_ERT_INSERT && bv->cursor().inMathed()))
if (badcursor) { updateCompletion(bv->cursor(), true, true);
bv->cursor().fixIfBroken(); else if (cmd.action() == LFUN_CHAR_DELETE_BACKWARD)
bv->fixInlineCompletionPos(); updateCompletion(bv->cursor(), false, true);
} else
old.endUndoGroup(); updateCompletion(bv->cursor(), false, false);
}
// 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()))
updateCompletion(bv->cursor(), true, true);
else if (cmd.action() == LFUN_CHAR_DELETE_BACKWARD)
updateCompletion(bv->cursor(), false, true);
else
updateCompletion(bv->cursor(), false, false);
}
dr = bv->cursor().result();
} }
dr = bv->cursor().result();
} }