#include "WordLangTuple.h"
#include "insets/InsetBibtex.h"
+#include "insets/InsetCitation.h"
#include "insets/InsetCommand.h" // ChangeRefs
#include "insets/InsetExternal.h"
#include "insets/InsetGraphics.h"
#include "insets/InsetRef.h"
#include "insets/InsetText.h"
+#include "mathed/MathData.h"
+
#include "frontends/alert.h"
#include "frontends/Application.h"
#include "frontends/Delegates.h"
return Change(Change::UNCHANGED);
DocIterator dit = d->cursor_.selectionBegin();
+ // The selected content might have been changed (see #7685)
+ while (dit.inMathed())
+ // Find enclosing text cursor
+ dit.pop_back();
return dit.paragraph().lookupChange(dit.pos());
}
if (tm.contains(bot_pit)) {
ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
- LASSERT(!pm.rows().empty(), /**/);
+ LBUFERR(!pm.rows().empty());
// FIXME: smooth scrolling doesn't work in mathed.
CursorSlice const & cs = dit.innerTextSlice();
int offset = coordOffset(dit).y_;
case LFUN_BIBTEX_DATABASE_ADD:
case LFUN_BIBTEX_DATABASE_DEL:
case LFUN_STATISTICS:
- case LFUN_BRANCH_ADD_INSERT:
case LFUN_KEYMAP_OFF:
case LFUN_KEYMAP_PRIMARY:
case LFUN_KEYMAP_SECONDARY:
flag.setEnabled(cur.inset().allowParagraphCustomization(cur.idx()));
break;
+ case LFUN_BRANCH_ADD_INSERT:
+ flag.setEnabled(!(cur.inTexted() && cur.paragraph().isPassThru()));
+ break;
+
case LFUN_DIALOG_SHOW_NEW_INSET:
// FIXME: this is wrong, but I do not understand the
// intent (JMarc)
break;
}
- // FIXME We do not really want this here, but at present we need to
- // 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:
- 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;
- }
-
default:
return false;
}
case LFUN_WORD_FIND_FORWARD:
case LFUN_WORD_FIND_BACKWARD: {
+ // FIXME THREAD
+ // Would it maybe be better if this variable were view specific anyway?
static docstring last_search;
docstring searched_string;
docstring const data =
find2string(searched_string, true, false, fw);
bool found = lyxfind(this, FuncRequest(LFUN_WORD_FIND, data));
- if (found)
+ if (found) {
dr.screenUpdate(Update::Force | Update::FitCursor);
+ cur.dispatched();
+ dispatched = true;
+ } else {
+ cur.undispatched();
+ dispatched = false;
+ }
break;
}
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
break;
}
- if (lyxfind(this, req))
+ if (lyxfind(this, req)) {
dr.screenUpdate(Update::Force | Update::FitCursor);
- else
- message(_("String not found!"));
+ cur.dispatched();
+ dispatched = true;
+ } else {
+ cur.undispatched();
+ dispatched = false;
+ }
d->search_request_cache_ = req;
break;
}
if (lyxreplace(this, cmd, has_deleted)) {
dr.forceBufferUpdate();
dr.screenUpdate(Update::Force | Update::FitCursor);
+ cur.dispatched();
+ dispatched = true;
+ } else {
+ cur.undispatched();
+ dispatched = false;
}
break;
}
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();
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;
arg = token(argument, '|', 0);
opt1 = token(argument, '|', 1);
}
+
+ // if our cursor is directly 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<InsetCitation *>(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())
break;
}
- // FIXME We do not really want this here, but it has to be at present
- // because we need a cursor for the recordUndoFullDocument call. What
- // we would really like is a recordUndoBufferParams call that did not
- // need a cursor, but we do not have that yet.
- // 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:
- 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 *>(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 = buf->params().branchlist().find(branch_name);
- if (!branch) {
- LYXERR0("Branch " << branch_name << " does not exist.");
- dr.setError(true);
- docstring const msg =
- bformat(_("Branch \"%1$s\" does not exist."), branch_name);
- dr.setMessage(msg);
- break;
- }
- bool activate = (cmd.action() == LFUN_BRANCH_ACTIVATE
- || cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE);
- if (branch->isSelected() != activate) {
- branch->setSelected(activate);
- cur.recordUndoFullDocument();
- dr.setError(false);
- dr.screenUpdate(Update::Force);
- dr.forceBufferUpdate();
- }
- break;
- }
-
default:
// OK, so try the Buffer itself...
buffer_.dispatch(cmd, dr);
{
if (d->last_inset_ != inset) {
LYXERR0("Wrong last_inset!");
- LASSERT(false, /**/);
+ LATTEST(false);
}
d->last_inset_ = 0;
}
TextMetrics & BufferView::textMetrics(Text const * t)
{
- LASSERT(t, /**/);
+ LBUFERR(t);
TextMetricsCache::iterator tmc_it = d->text_metrics_.find(t);
if (tmc_it == d->text_metrics_.end()) {
tmc_it = d->text_metrics_.insert(
return false;
d->cursor_ = cur;
+
+ // we would rather not do this here, but it needs to be done before
+ // the changed() signal is sent.
+ buffer_.updateBuffer();
- cur.forceBufferUpdate();
- cur.screenUpdateFlags(Update::Force);
+ buffer_.changed(true);
return true;
}
bool BufferView::mouseSetCursor(Cursor & cur, bool select)
{
- LASSERT(&cur.bv() == this, /**/);
+ LASSERT(&cur.bv() == this, return false);
if (!select)
// this event will clear selection so we save selection for
bool BufferView::selectIfEmpty(DocIterator & cur)
{
- if (!cur.paragraph().empty())
+ if ((cur.inTexted() && !cur.paragraph().empty())
+ || (cur.inMathed() && !cur.cell().empty()))
return false;
pit_type const beg_pit = cur.pit();
void BufferView::insertLyXFile(FileName const & fname)
{
- LASSERT(d->cursor_.inTexted(), /**/);
+ LASSERT(d->cursor_.inTexted(), return);
// Get absolute path of file and add ".lyx"
// to the filename if necessary
CursorSlice const & sl = dit[0];
TextMetrics const & tm = textMetrics(sl.text());
ParagraphMetrics const & pm = tm.parMetrics(sl.pit());
- LASSERT(!pm.rows().empty(), /**/);
+
+ LBUFERR(!pm.rows().empty());
y -= pm.rows()[0].ascent();
#if 1
// FIXME: document this mess