X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBufferView.cpp;h=43420209cceab24a9d4101b4855c72ad797a437e;hb=1d6573a330791fb34541f4092cd49e4559972489;hp=e1ff3897199eb1fc92ecc7435a829bdc09816b3b;hpb=8b2aab9b3d176d125afdba3038703f98901391da;p=lyx.git diff --git a/src/BufferView.cpp b/src/BufferView.cpp index e1ff389719..43420209cc 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -54,6 +54,7 @@ #include "WordLangTuple.h" #include "insets/InsetBibtex.h" +#include "insets/InsetCitation.h" #include "insets/InsetCommand.h" // ChangeRefs #include "insets/InsetExternal.h" #include "insets/InsetGraphics.h" @@ -105,6 +106,7 @@ T * getInsetByCode(Cursor const & cur, InsetCode code) return 0; } + /// Note that comparing contents can only be used for InsetCommand bool findNextInset(DocIterator & dit, vector const & codes, docstring const & contents) @@ -1188,8 +1190,13 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag) // handle their dispatch here, for reasons explained there, so we'll // handle this here, too, for consistency. case LFUN_BRANCH_ACTIVATE: - case LFUN_BRANCH_DEACTIVATE: { - BranchList const & branchList = buffer().params().branchlist(); + case LFUN_BRANCH_DEACTIVATE: + case LFUN_BRANCH_MASTER_ACTIVATE: + case LFUN_BRANCH_MASTER_DEACTIVATE: { + bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE + || cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE); + BranchList const & branchList = master ? buffer().masterBuffer()->params().branchlist() + : buffer().params().branchlist(); docstring const branchName = cmd.argument(); flag.setEnabled(!branchName.empty() && branchList.find(branchName)); break; @@ -1218,14 +1225,7 @@ void BufferView::editInset(string const & name, Inset * inset) void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) { - //lyxerr << [ cmd = " << cmd << "]" << endl; - - // Make sure that the cached BufferView is correct. - LYXERR(Debug::ACTION, " action[" << cmd.action() << ']' - << " arg[" << to_utf8(cmd.argument()) << ']' - << " x[" << cmd.x() << ']' - << " y[" << cmd.y() << ']' - << " button[" << cmd.button() << ']'); + LYXERR(Debug::ACTION, "BufferView::dispatch: cmd: " << cmd); string const argument = to_utf8(cmd.argument()); Cursor & cur = d->cursor_; @@ -1275,7 +1275,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) case LFUN_LAYOUT_MODULE_ADD: { BufferParams const & params = buffer_.params(); - if (!params.moduleCanBeAdded(argument)) { + if (!params.layoutModuleCanBeAdded(argument)) { LYXERR0("Module `" << argument << "' cannot be added due to failed requirements or " "conflicts with installed modules."); @@ -1809,7 +1809,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) cur.forwardInset(); cur.beginUndoGroup(); while(cur && iterations < max_iter) { - Inset * ins = cur.nextInset(); + Inset * const ins = cur.nextInset(); if (!ins) break; docstring insname = ins->layoutName(); @@ -1825,7 +1825,9 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) break; insname = insname.substr(0, i); } - cur.forwardInset(); + // if we did not delete the inset, skip it + if (!cur.nextInset() || cur.nextInset() == ins) + cur.forwardInset(); } cur.endUndoGroup(); cur = savecur; @@ -1908,6 +1910,23 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) arg = token(argument, '|', 0); opt1 = token(argument, '|', 1); } + + // if our cursor is direclty in front of or behind a citation inset, + // we will instead add the new key to it. + Inset * inset = cur.nextInset(); + if (!inset || inset->lyxCode() != CITE_CODE) + inset = cur.prevInset(); + if (inset && inset->lyxCode() == CITE_CODE) { + InsetCitation * icite = static_cast(inset); + if (icite->addKey(arg)) { + dr.forceBufferUpdate(); + dr.screenUpdate(Update::FitCursor | Update::SinglePar); + if (!opt1.empty()) + LYXERR0("Discarding optional argument to citation-insert."); + } + dispatched = true; + break; + } InsetCommandParams icp(CITE_CODE); icp["key"] = from_utf8(arg); if (!opt1.empty()) @@ -1976,15 +1995,21 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) // So, if this does get fixed, this code can be moved back to Buffer.cpp, // and the corresponding code in getStatus() should be moved back, too. case LFUN_BRANCH_ACTIVATE: - case LFUN_BRANCH_DEACTIVATE: { - BranchList & branch_list = buffer().params().branchlist(); + case LFUN_BRANCH_DEACTIVATE: + case LFUN_BRANCH_MASTER_ACTIVATE: + case LFUN_BRANCH_MASTER_DEACTIVATE: { + bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE + || cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE); + Buffer * buf = master ? const_cast(buffer().masterBuffer()) + : &buffer(); + docstring const branch_name = cmd.argument(); // the case without a branch name is handled elsewhere if (branch_name.empty()) { dispatched = false; break; } - Branch * branch = branch_list.find(branch_name); + Branch * branch = buf->params().branchlist().find(branch_name); if (!branch) { LYXERR0("Branch " << branch_name << " does not exist."); dr.setError(true); @@ -1993,7 +2018,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) dr.setMessage(msg); break; } - bool activate = cmd.action() == LFUN_BRANCH_ACTIVATE; + bool activate = (cmd.action() == LFUN_BRANCH_ACTIVATE + || cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE); if (branch->isSelected() != activate) { branch->setSelected(activate); cur.recordUndoFullDocument(); @@ -2449,6 +2475,8 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select) cap::saveSelection(cursor()); d->cursor_.macroModeClose(); + // If a macro has been finalized, the cursor might have been broken + cur.fixIfBroken(); // Has the cursor just left the inset? bool const leftinset = (&d->cursor_.inset() != &cur.inset());