#include "frontends/Painter.h"
#include "frontends/Selection.h"
-#include "graphics/Previews.h"
-
#include "support/convert.h"
#include "support/debug.h"
#include "support/ExceptionMessage.h"
#include "support/filetools.h"
#include "support/gettext.h"
+#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/Package.h"
#include "support/types.h"
/** kept to send setMouseHover(false).
* Not owned, so don't delete.
*/
- Inset * last_inset_;
+ Inset const * last_inset_;
/// are we hovering something that we can click
bool clickable_inset_;
// FIXME: Care about the d->cursor_ flags to redraw if needed
Cursor old = d->cursor_;
mouseSetCursor(cur);
- bool badcursor = notifyCursorLeavesOrEnters(old, d->cursor_);
+ // the DEPM call in mouseSetCursor() might have destroyed the
+ // paragraph the cursor is in.
+ bool badcursor = old.fixIfBroken();
+ badcursor |= notifyCursorLeavesOrEnters(old, d->cursor_);
if (badcursor)
d->cursor_.fixIfBroken();
}
if (cur.inset().lyxCode() == CAPTION_CODE)
return cur.inset().getStatus(cur, cmd, flag);
// FIXME we should consider passthru paragraphs too.
- flag.setEnabled(!cur.inset().getLayout().isPassThru());
+ flag.setEnabled(!(cur.inTexted() && cur.paragraph().isPassThru()));
break;
case LFUN_CITATION_INSERT: {
buffer_.text().cursorBottom(cur);
// accept everything in a single step to support atomic undo
buffer_.text().acceptOrRejectChanges(cur, Text::ACCEPT);
+ cur.resetAnchor();
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
dr.screenUpdate(Update::Force | Update::FitCursor);
dr.forceBufferUpdate();
// 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(cur, Text::REJECT);
+ cur.resetAnchor();
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
dr.screenUpdate(Update::Force | Update::FitCursor);
dr.forceBufferUpdate();
FindAndReplaceOptions opt;
istringstream iss(to_utf8(cmd.argument()));
iss >> opt;
- if (findAdv(this, opt))
+ if (findAdv(this, opt)) {
dr.screenUpdate(Update::Force | Update::FitCursor);
+ cur.dispatched();
+ dispatched = true;
+ } else {
+ cur.undispatched();
+ dispatched = false;
+ }
break;
}
d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_,
true, act == LFUN_SCREEN_UP);
+ cur.resetAnchor();
//FIXME: what to do with cur.x_target()?
bool update = in_texted && cur.bv().checkDepm(cur, old);
cur.finishUndo();
Inset * ins = cur.nextInset();
if (!ins)
break;
- docstring insname = ins->name();
+ docstring insname = ins->layoutName();
while (!insname.empty()) {
if (insname == name || name == from_utf8("*")) {
cur.recordUndo();
}
default:
- dispatched = false;
+ // OK, so try the Buffer itself...
+ buffer_.dispatch(cmd, dr);
+ dispatched = dr.dispatched();
break;
}
buffer_.undo().endUndoGroup();
dr.dispatched(dispatched);
- return;
}
d->last_inset_ = 0;
}
- // const_cast because of setMouseHover().
- Inset * inset = const_cast<Inset *>(covering_inset);
- if (inset && inset->setMouseHover(this, true)) {
+ if (covering_inset && covering_inset->setMouseHover(this, true)) {
need_redraw = true;
// Only the insets that accept the hover state, do
// clear the last_inset_, so only set the last_inset_
// member if the hovered setting is accepted.
- d->last_inset_ = inset;
+ d->last_inset_ = covering_inset;
}
if (need_redraw) {
// Do we have a selection?
theSelection().haveSelection(cursor().selection());
+ if (cur.needBufferUpdate()) {
+ cur.clearBufferUpdate();
+ buffer().updateBuffer();
+ }
+
// If the command has been dispatched,
if (cur.result().dispatched() || cur.result().screenUpdate())
processUpdateFlags(cur.result().screenUpdate());
void BufferView::setCursorFromRow(int row)
{
- int tmpid = -1;
- int tmppos = -1;
+ int tmpid;
+ int tmppos;
+ pit_type newpit = 0;
+ pos_type newpos = 0;
buffer_.texrow().getIdFromRow(row, tmpid, tmppos);
+ bool posvalid = (tmpid != -1);
+ if (posvalid) {
+ // we need to make sure that the row and position
+ // we got back are valid, because the buffer may well
+ // have changed since we last generated the LaTeX.
+ DocIterator const dit = buffer_.getParFromID(tmpid);
+ if (dit == doc_iterator_end(&buffer_))
+ posvalid = false;
+ else {
+ newpit = dit.pit();
+ // now have to check pos.
+ newpos = tmppos;
+ Paragraph const & par = buffer_.text().getPar(newpit);
+ if (newpos > par.size()) {
+ LYXERR0("Requested position no longer valid.");
+ newpos = par.size() - 1;
+ }
+ }
+ }
+ if (!posvalid) {
+ frontend::Alert::error(_("Inverse Search Failed"),
+ _("Invalid position requested by inverse search.\n"
+ "You need to update the viewed document."));
+ return;
+ }
d->cursor_.reset();
- if (tmpid == -1)
- buffer_.text().setCursor(d->cursor_, 0, 0);
- else
- buffer_.text().setCursor(d->cursor_, buffer_.getParFromID(tmpid).pit(), tmppos);
+ buffer_.text().setCursor(d->cursor_, newpit, newpos);
+ d->cursor_.setSelection(false);
+ d->cursor_.resetAnchor();
recenter();
}
TextMetrics & BufferView::textMetrics(Text const * t)
{
+ LASSERT(t, /**/);
TextMetricsCache::iterator tmc_it = d->text_metrics_.find(t);
if (tmc_it == d->text_metrics_.end()) {
tmc_it = d->text_metrics_.insert(
d->cursor_.setCursor(dit);
d->cursor_.setSelection(false);
+ // FIXME
+ // It seems on general grounds as if this is probably needed, but
+ // it is not yet clear.
+ // See bug #7394 and r38388.
+ // d->cursor.resetAnchor();
}
d->cursor_.macroModeClose();
// Has the cursor just left the inset?
- bool leftinset = (&d->cursor_.inset() != &cur.inset());
+ bool const leftinset = (&d->cursor_.inset() != &cur.inset());
if (leftinset)
d->cursor_.fixIfBroken();
// FIXME: shift-mouse selection doesn't work well across insets.
- bool do_selection = select && &d->cursor_.normalAnchor().inset() == &cur.inset();
+ bool const do_selection =
+ select && &d->cursor_.normalAnchor().inset() == &cur.inset();
// do the dEPM magic if needed
// FIXME: (1) move this to InsetText::notifyCursorLeaves?
}
+bool BufferView::selectIfEmpty(DocIterator & cur)
+{
+ if (!cur.paragraph().empty())
+ return false;
+
+ pit_type const beg_pit = cur.pit();
+ if (beg_pit > 0) {
+ // The paragraph associated to this item isn't
+ // the first one, so it can be selected
+ cur.backwardPos();
+ } else {
+ // We have to resort to select the space between the
+ // end of this item and the begin of the next one
+ cur.forwardPos();
+ }
+ if (cur.empty()) {
+ // If it is the only item in the document,
+ // nothing can be selected
+ return false;
+ }
+ pit_type const end_pit = cur.pit();
+ pos_type const end_pos = cur.pos();
+ d->cursor_.clearSelection();
+ d->cursor_.reset();
+ d->cursor_.setCursor(cur);
+ d->cursor_.pit() = beg_pit;
+ d->cursor_.pos() = 0;
+ d->cursor_.setSelection(false);
+ d->cursor_.resetAnchor();
+ d->cursor_.pit() = end_pit;
+ d->cursor_.pos() = end_pos;
+ d->cursor_.setSelection();
+ return true;
+}
+
+
Cursor & BufferView::cursor()
{
return d->cursor_;
message(bformat(_("Inserting document %1$s..."), disp_fn));
docstring res;
- Buffer buf("", false);
- if (buf.loadLyXFile(filename) == Buffer::ReadSuccess) {
+ Buffer buf(filename.absFileName(), false);
+ if (buf.loadLyXFile() == Buffer::ReadSuccess) {
ErrorList & el = buffer_.errorList("Parse");
// Copy the inserted document error list into the current buffer one.
el = buf.errorList("Parse");
}
+void BufferView::resetInlineCompletionPos()
+{
+ d->inlineCompletionPos_ = DocIterator();
+}
+
+
bool samePar(DocIterator const & a, DocIterator const & b)
{
if (a.empty() && b.empty())