if (!findNextInset(tmpdit, codes, contents)) {
if (dit.depth() != 1 || dit.pit() != 0 || dit.pos() != 0) {
- tmpdit = doc_iterator_begin(tmpdit.bottom().inset());
+ Inset * inset = &tmpdit.bottom().inset();
+ tmpdit = doc_iterator_begin(&inset->buffer(), inset);
if (!findNextInset(tmpdit, codes, contents))
return false;
- } else
+ } else {
return false;
+ }
}
dit = tmpdit;
Private(BufferView & bv): wh_(0), cursor_(bv),
anchor_pit_(0), anchor_ypos_(0),
inlineCompletionUniqueChars_(0),
- last_inset_(0), gui_(0)
+ last_inset_(0), bookmark_edit_position_(0), gui_(0)
{}
///
*/
Inset * last_inset_;
+ // cache for id of the paragraph which was edited the last time
+ int bookmark_edit_position_;
+
mutable TextMetricsCache text_metrics_;
/// Whom to notify.
BufferView::BufferView(Buffer & buf)
- : width_(0), height_(0), full_screen_(false), buffer_(buf), d(new Private(*this))
+ : width_(0), height_(0), full_screen_(false), buffer_(buf),
+ d(new Private(*this))
{
d->xsel_cache_.set = false;
d->intl_.initKeyMapper(lyxrc.use_kbmap);
+ d->cursor_.setBuffer(&buf);
d->cursor_.push(buffer_.inset());
d->cursor_.resetAnchor();
d->cursor_.setCurrentFont();
// cut off at the top
if (value <= d->scrollbarParameters_.min) {
- DocIterator dit = doc_iterator_begin(buffer_.inset());
+ DocIterator dit = doc_iterator_begin(&buffer_);
showCursor(dit);
LYXERR(Debug::SCROLLING, "scroll to top");
return;
// cut off at the bottom
if (value >= d->scrollbarParameters_.max) {
- DocIterator dit = doc_iterator_end(buffer_.inset());
+ DocIterator dit = doc_iterator_end(&buffer_);
dit.backwardPos();
showCursor(dit);
LYXERR(Debug::SCROLLING, "scroll to bottom");
return;
}
- DocIterator dit = doc_iterator_begin(buffer_.inset());
+ DocIterator dit = doc_iterator_begin(&buffer_);
dit.pit() = i;
LYXERR(Debug::SCROLLING, "value = " << value << " -> scroll to pit " << i);
showCursor(dit);
}
+void BufferView::bookmarkEditPosition()
+{
+ // Don't eat cpu time for each keystroke
+ if (d->cursor_.paragraph().id() == d->bookmark_edit_position_)
+ return;
+ saveBookmark(0);
+ d->bookmark_edit_position_ = d->cursor_.paragraph().id();
+}
+
+
void BufferView::saveBookmark(unsigned int idx)
{
- // tenatively save bookmark, id and pos will be used to
+ // tentatively save bookmark, id and pos will be used to
// acturately locate a bookmark in a 'live' lyx session.
// pit and pos will be updated with bottom level pit/pos
// when lyx exits.
// it will be restored to the left of the outmost inset that contains
// the bookmark.
if (bottom_pit < int(buffer_.paragraphs().size())) {
- dit = doc_iterator_begin(buffer_.inset());
+ dit = doc_iterator_begin(&buffer_);
dit.pit() = bottom_pit;
dit.pos() = min(bottom_pos, dit.paragraph().size());
if (ypos - row_dim.ascent() < 0)
scrolled = scrollUp(- ypos + row_dim.ascent());
else if (ypos + row_dim.descent() > height_)
- scrolled = scrollDown(ypos - height_ + row_dim.descent());
+ scrolled = scrollDown(ypos - height_ + defaultRowHeight() );
+
// else, nothing to do, the cursor is already visible so we just return.
if (scrolled != 0) {
updateMetrics();
d->anchor_ypos_ = offset + pm.ascent();
else if (d->anchor_pit_ == max_pit)
d->anchor_ypos_ = height_ - offset - row_dim.descent();
+ else if (offset > height_)
+ d->anchor_ypos_ = height_ - offset - defaultRowHeight();
else
- d->anchor_ypos_ = defaultRowHeight() * 2 - offset - row_dim.descent();
+ d->anchor_ypos_ = defaultRowHeight() * 2;
updateMetrics();
buffer_.changed();
case LFUN_COPY_LABEL_AS_REF: {
// if there is an inset at cursor, see whether it
- // handles the lfun, other start from scratch
+ // handles the lfun
Inset * inset = cur.nextInset();
if (!inset || !inset->getStatus(cur, cmd, flag))
- flag = lyx::getStatus(cmd);
+ flag.setEnabled(false);
break;
}
case WRAP_CODE:
case NOTE_CODE:
case BRANCH_CODE:
+ case PHANTOM_CODE:
case BOX_CODE:
case LISTINGS_CODE:
enable = (cmd.argument().empty() ||
docstring label = cmd.argument();
if (label.empty()) {
InsetRef * inset =
- getInsetByCode<InsetRef>(d->cursor_,
- REF_CODE);
+ getInsetByCode<InsetRef>(d->cursor_, REF_CODE);
if (inset) {
label = inset->getParam("reference");
// persistent=false: use temp_bookmark
saveBookmark(0);
}
}
-
- if (!label.empty())
+ if (!label.empty())
gotoLabel(label);
break;
}
buffer_.params().outputChanges = !buffer_.params().outputChanges;
if (buffer_.params().outputChanges) {
bool dvipost = LaTeXFeatures::isAvailable("dvipost");
- bool xcolorsoul = LaTeXFeatures::isAvailable("soul") &&
+ bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
LaTeXFeatures::isAvailable("xcolor");
- if (!dvipost && !xcolorsoul) {
+ if (!dvipost && !xcolorulem) {
Alert::warning(_("Changes not shown in LaTeX output"),
_("Changes will not be highlighted in LaTeX output, "
- "because neither dvipost nor xcolor/soul are installed.\n"
+ "because neither dvipost nor xcolor/ulem are installed.\n"
"Please install these packages or redefine "
"\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
- } else if (!xcolorsoul) {
+ } else if (!xcolorulem) {
Alert::warning(_("Changes not shown in LaTeX output"),
_("Changes will not be highlighted in LaTeX output "
- "when using pdflatex, because xcolor and soul are not installed.\n"
+ "when using pdflatex, because xcolor and ulem are not installed.\n"
"Please install both packages or redefine "
"\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
}
from = cur.selectionBegin();
to = cur.selectionEnd();
} else {
- from = doc_iterator_begin(buffer_.inset());
- to = doc_iterator_end(buffer_.inset());
+ from = doc_iterator_begin(&buffer_);
+ to = doc_iterator_end(&buffer_);
}
int const words = countWords(from, to);
int const chars = countChars(from, to, false);
// if there is an inset at cursor, see whether it
// can be modified.
Inset * inset = cur.nextInset();
- if (inset)
+ if (inset) {
+ cur.recordUndo();
inset->dispatch(cur, tmpcmd);
+ }
// if it did not work, try the underlying inset.
- if (!inset || !cur.result().dispatched())
+ if (!inset || !cur.result().dispatched()) {
+ cur.recordUndo();
cur.dispatch(tmpcmd);
+ }
if (!cur.result().dispatched())
// It did not work too; no action needed.
FuncRequest fr(LFUN_INSET_TOGGLE, action);
- Inset & inset = cur.buffer().inset();
+ Inset & inset = cur.buffer()->inset();
InsetIterator it = inset_iterator_begin(inset);
InsetIterator const end = inset_iterator_end(inset);
for (; it != end; ++it) {
void BufferView::gotoLabel(docstring const & label)
{
- Toc & toc = buffer().tocBackend().toc("label");
- TocIterator toc_it = toc.begin();
- TocIterator end = toc.end();
- for (; toc_it != end; ++toc_it) {
- if (label == toc_it->str())
- dispatch(toc_it->action());
+ std::vector<Buffer const *> bufs = buffer().allRelatives();
+ std::vector<Buffer const *>::iterator it = bufs.begin();
+ for (; it != bufs.end(); ++it) {
+ Buffer const * buf = *it;
+
+ // find label
+ Toc & toc = buf->tocBackend().toc("label");
+ TocIterator toc_it = toc.begin();
+ TocIterator end = toc.end();
+ for (; toc_it != end; ++toc_it) {
+ if (label == toc_it->str()) {
+ dispatch(toc_it->action());
+ return;
+ }
+ }
}
- //FIXME: We could do a bit more searching thanks to this:
- //InsetLabel const * inset = buffer_.insetLabel(label);
}
Point BufferView::getPos(DocIterator const & dit, bool boundary) const
{
+ if (!paragraphVisible(dit))
+ return Point(-1, -1);
+
CursorSlice const & bot = dit.bottom();
TextMetrics const & tm = textMetrics(bot.text());
- if (!tm.contains(bot.pit()))
- return Point(-1, -1);
Point p = coordOffset(dit, boundary); // offset from outer paragraph
p.y_ += tm.parMetrics(bot.pit()).position();
}
+bool BufferView::paragraphVisible(DocIterator const & dit) const
+{
+ CursorSlice const & bot = dit.bottom();
+ TextMetrics const & tm = textMetrics(bot.text());
+
+ return tm.contains(bot.pit());
+}
+
+
void BufferView::draw(frontend::Painter & pain)
{
if (height_ == 0 || width_ == 0)
return true;
if (a.empty() || b.empty())
return false;
+ if (a.depth() != b.depth())
+ return false;
return &a.innerParagraph() == &b.innerParagraph();
}