d->cursor_.setCurrentFont();
if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
- graphics::Previews::get().generateBufferPreviews(buffer_);
+ thePreviews().generateBufferPreviews(buffer_);
}
LastFilePosSection::FilePos fp;
fp.pit = d->cursor_.bottom().pit();
fp.pos = d->cursor_.bottom().pos();
- LyX::ref().session().lastFilePos().save(buffer_.fileName(), fp);
+ theSession().lastFilePos().save(buffer_.fileName(), fp);
delete d;
}
docstring BufferView::contextMenu(int x, int y) const
{
+ //If there is a selection, return the containing inset menu
+ if (d->cursor_.selection())
+ return d->cursor_.inset().contextMenu(*this, x, y);
+
// Get inset under mouse, if there is one.
Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
if (covering_inset)
int const height = 2 * defaultRowHeight();
int const first = height;
int const last = height_ - height;
- Cursor & cur = d->cursor_;
+ int newy = 0;
+ Cursor const & oldcur = d->cursor_;
- switch (cursorStatus(cur)) {
+ switch (cursorStatus(oldcur)) {
case CUR_ABOVE:
- // We reset the cursor because cursorStatus() does not
- // work when the cursor is within mathed.
- cur.reset(buffer_.inset());
- tm.setCursorFromCoordinates(cur, 0, first);
- cur.clearSelection();
+ newy = first;
break;
case CUR_BELOW:
- // We reset the cursor because cursorStatus() does not
- // work when the cursor is within mathed.
- cur.reset(buffer_.inset());
- tm.setCursorFromCoordinates(cur, 0, last);
- cur.clearSelection();
+ newy = last;
break;
case CUR_INSIDE:
- int const y = getPos(cur, cur.boundary()).y_;
- int const newy = min(last, max(y, first));
- if (y != newy) {
- cur.reset(buffer_.inset());
- tm.setCursorFromCoordinates(cur, 0, newy);
- }
+ int const y = getPos(oldcur, oldcur.boundary()).y_;
+ newy = min(last, max(y, first));
+ if (y == newy)
+ return;
}
+ // We reset the cursor because cursorStatus() does not
+ // work when the cursor is within mathed.
+ Cursor cur(*this);
+ cur.reset(buffer_.inset());
+ tm.setCursorFromCoordinates(cur, 0, newy);
+ mouseSetCursor(cur);
}
// acturately locate a bookmark in a 'live' lyx session.
// pit and pos will be updated with bottom level pit/pos
// when lyx exits.
- LyX::ref().session().bookmarks().save(
+ theSession().bookmarks().save(
buffer_.fileName(),
d->cursor_.bottom().pit(),
d->cursor_.bottom().pos(),
if (!inset || !cur.result().dispatched())
cur.dispatch(cmd);
+ // FIXME I'm adding the last break to solve a crash,
+ // but that is obviously not right.
if (!cur.result().dispatched())
// It did not work too; no action needed.
break;
+ break;
}
case LFUN_PARAGRAPH_GOTO: {
buffer_.text().cursorBottom(d->cursor_);
// accept everything in a single step to support atomic undo
buffer_.text().acceptOrRejectChanges(d->cursor_, Text::ACCEPT);
+ // FIXME: Move this LFUN to Buffer so that we don't have to do this:
+ processUpdateFlags(Update::Force | Update::FitCursor);
break;
case LFUN_ALL_CHANGES_REJECT:
// reject everything in a single step to support atomic undo
// Note: reject does not work recursively; the user may have to repeat the operation
buffer_.text().acceptOrRejectChanges(d->cursor_, Text::REJECT);
+ // FIXME: Move this LFUN to Buffer so that we don't have to do this:
+ processUpdateFlags(Update::Force | Update::FitCursor);
break;
case LFUN_WORD_FIND: {
case LFUN_GRAPHICS_GROUPS_UNIFY: {
if (cmd.argument().empty())
break;
- //view()->cursor().recordUndoFullDocument(); let inset-apply do that job
graphics::unifyGraphicsGroups(cur.buffer(), to_utf8(cmd.argument()));
processUpdateFlags(Update::Force | Update::FitCursor);
break;
case LFUN_NOTES_MUTATE: {
if (cmd.argument().empty())
break;
- cur.recordUndoFullDocument();
if (mutateNotes(cur, cmd.getArg(0), cmd.getArg(1))) {
processUpdateFlags(Update::Force);
InsetIterator it = inset_iterator_begin(inset);
InsetIterator const end = inset_iterator_end(inset);
for (; it != end; ++it) {
- if (!it->asInsetMath()
+ if (it->asInsetCollapsable()
&& (inset_code == NO_CODE
|| inset_code == it->lyxCode())) {
Cursor tmpcur = cur;
tmpcur.pushBackward(*it);
- FuncStatus flag;
- it->getStatus(tmpcur, fr, flag);
- if (flag.enabled())
- it->dispatch(tmpcur, fr);
+ it->dispatch(tmpcur, fr);
}
}
processUpdateFlags(Update::Force | Update::FitCursor);
{
Cursor & cur = d->cursor_;
+ LYXERR(Debug::SELECTION, "requestSelection: cur.selection: " << cur.selection());
if (!cur.selection()) {
d->xsel_cache_.set = false;
return docstring();
}
+ LYXERR(Debug::SELECTION, "requestSelection: xsel_cache.set: " << d->xsel_cache_.set);
if (!d->xsel_cache_.set ||
cur.top() != d->xsel_cache_.cursor ||
cur.anchor_.top() != d->xsel_cache_.anchor)
// Put anchor at the same position.
cur.resetAnchor();
+ cur.beginUndoGroup();
+
// 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
if (!inset || !cur.result().dispatched())
cur.dispatch(cmd);
+ cur.endUndoGroup();
+
// Notify left insets
if (cur != old) {
old.fixIfBroken();
}
+bool BufferView::setCursorFromInset(Inset const * inset)
+{
+ // are we already there?
+ if (cursor().nextInset() == inset)
+ return true;
+
+ // Inset is not at cursor position. Find it in the document.
+ Cursor cur(*this);
+ cur.reset(buffer().inset());
+ do
+ cur.forwardInset();
+ while (cur && cur.nextInset() != inset);
+
+ if (cur) {
+ setCursor(cur);
+ return true;
+ }
+ return false;
+}
+
+
void BufferView::gotoLabel(docstring const & label)
{
Toc & toc = buffer().tocBackend().toc("label");