#include "insets/InsetRef.h"
#include "insets/InsetText.h"
+#include "mathed/InsetMath.h"
#include "mathed/MathData.h"
+#include "mathed/MathRow.h"
#include "frontends/alert.h"
+#include "frontends/CaretGeometry.h"
#include "frontends/Delegates.h"
#include "frontends/FontMetrics.h"
#include "frontends/NullPainter.h"
#include "frontends/Painter.h"
#include "frontends/Selection.h"
+#include "frontends/Clipboard.h"
#include "support/convert.h"
#include "support/debug.h"
*/
frontend::GuiBufferViewDelegate * gui_;
- /// Cache for Find Next
- FuncRequest search_request_cache_;
-
///
map<string, Inset *> edited_insets_;
CursorSlice current_row_slice_;
/// are we hovering something that we can click
bool clickable_inset_;
+ /// shape of the caret
+ frontend::CaretGeometry caret_geometry_;
};
int BufferView::topMargin() const
{
- // original value was 20px, which is 0.2in at 100dpi
- return zoomedPixels(20);
+ // Original value was 20px at 100dpi. For internal buffers like in
+ // advanced search and replace, a value of 5px is enough.
+ return zoomedPixels(buffer().isInternal() ? 5 : 20);
}
int BufferView::bottomMargin() const
{
- // original value was 20px, which is 0.2in at 100dpi
- return zoomedPixels(20);
+ return topMargin();
}
}
+docstring const & BufferView::searchRequestCache() const
+{
+ return theClipboard().getFindBuffer();
+}
+
+
+void BufferView::setSearchRequestCache(docstring const & text)
+{
+ bool casesensitive;
+ bool matchword;
+ bool forward;
+ bool wrap;
+ bool instant;
+ bool onlysel;
+ docstring const search = string2find(text, casesensitive, matchword,
+ forward, wrap, instant, onlysel);
+ theClipboard().setFindBuffer(search);
+}
+
+
bool BufferView::needsFitCursor() const
{
if (cursorStatus(d->cursor_) == CUR_INSIDE) {
void BufferView::saveBookmark(unsigned int idx)
{
+ if (buffer().isInternal())
+ return;
+
// 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.
- if (!buffer_.isInternal()) {
- theSession().bookmarks().save(
- buffer_.fileName(),
- d->cursor_.bottom().pit(),
- d->cursor_.bottom().pos(),
- d->cursor_.paragraph().id(),
- d->cursor_.pos(),
- idx
- );
- if (idx)
- // emit message signal.
- message(_("Save bookmark"));
- }
+ theSession().bookmarks().save(
+ buffer_.fileName(),
+ d->cursor_.bottom().pit(),
+ d->cursor_.bottom().pos(),
+ d->cursor_.paragraph().id(),
+ d->cursor_.pos(),
+ idx
+ );
+ if (idx)
+ // emit message signal.
+ message(_("Save bookmark"));
}
void BufferView::makeDocumentClass()
{
DocumentClassConstPtr olddc = buffer_.params().documentClassPtr();
- buffer_.params().makeDocumentClass();
+ buffer_.params().makeDocumentClass(buffer_.isClone(), buffer_.isInternal());
updateDocumentClass(olddc);
}
case LFUN_MARK_OFF:
case LFUN_MARK_ON:
case LFUN_MARK_TOGGLE:
+ case LFUN_SEARCH_STRING_SET:
case LFUN_SCREEN_RECENTER:
case LFUN_SCREEN_SHOW_CURSOR:
case LFUN_BIBTEX_DATABASE_ADD:
break;
}
+ case LFUN_COPY:
+ flag.setEnabled(cur.selection());
+ break;
+
default:
return false;
}
break;
case LFUN_BOOKMARK_SAVE:
+ dr.screenUpdate(Update::Force);
saveBookmark(convert<unsigned int>(to_utf8(cmd.argument())));
break;
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;
if (!cmd.argument().empty()) {
- last_search = cmd.argument();
+ setSearchRequestCache(cmd.argument());
searched_string = cmd.argument();
} else {
- searched_string = last_search;
+ searched_string = searchRequestCache();
}
if (searched_string.empty())
break;
- bool const fw = act == LFUN_WORD_FIND_FORWARD;
docstring const data =
- find2string(searched_string, true, false, fw);
+ find2string(searched_string, false, false,
+ act == LFUN_WORD_FIND_FORWARD, false, false, false);
bool found = lyxfind(this, FuncRequest(LFUN_WORD_FIND, data));
if (found)
dr.screenUpdate(Update::Force | Update::FitCursor);
+ else
+ dr.setMessage(_("Search string not found!"));
break;
}
case LFUN_WORD_FIND: {
- FuncRequest req = cmd;
- if (cmd.argument().empty() && !d->search_request_cache_.argument().empty())
- req = d->search_request_cache_;
- if (req.argument().empty()) {
+ docstring arg = cmd.argument();
+ if (arg.empty())
+ arg = searchRequestCache();
+ if (arg.empty()) {
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
break;
}
- if (lyxfind(this, req))
+ if (lyxfind(this, FuncRequest(act, arg)))
dr.screenUpdate(Update::Force | Update::FitCursor);
+ else
+ dr.setMessage(_("Search string not found!"));
- d->search_request_cache_ = req;
+ setSearchRequestCache(arg);
break;
}
- case LFUN_WORD_REPLACE: {
- bool has_deleted = false;
- if (cur.selection()) {
- DocIterator beg = cur.selectionBegin();
- DocIterator end = cur.selectionEnd();
- if (beg.pit() == end.pit()) {
- for (pos_type p = beg.pos() ; p < end.pos() ; ++p) {
- if (!cur.inMathed() && cur.paragraph().isDeleted(p)) {
- has_deleted = true;
- break;
- }
- }
- }
+ case LFUN_SEARCH_STRING_SET: {
+ docstring pattern = cmd.argument();
+ if (!pattern.empty()) {
+ setSearchRequestCache(pattern);
+ break;
+ }
+ if (cur.selection())
+ pattern = cur.selectionAsString(false);
+ else {
+ pos_type spos = cur.pos();
+ cur.innerText()->selectWord(cur, WHOLE_WORD);
+ pattern = cur.selectionAsString(false);
+ cur.selection(false);
+ cur.pos() = spos;
}
- if (lyxreplace(this, cmd, has_deleted)) {
+ setSearchRequestCache(pattern);
+ break;
+ }
+
+ case LFUN_WORD_REPLACE: {
+ if (lyxreplace(this, cmd)) {
dr.forceBufferUpdate();
dr.screenUpdate(Update::Force | Update::FitCursor);
}
+ else
+ dr.setMessage(_("Search string not found!"));
break;
}
cur.setCursor(doc_iterator_begin(cur.buffer()));
cur.selHandle(false);
// Force an immediate computation of metrics because we need it below
- processUpdateFlags(Update::Force);
+ updateMetrics();
d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_,
true, act == LFUN_SCREEN_UP);
break;
}
+ case LFUN_COPY:
+ cap::copySelection(cur);
+ cur.message(_("Copy"));
+ break;
+
default:
// OK, so try the Buffer itself...
buffer_.dispatch(cmd, dr);
// Do we have a selection?
theSelection().haveSelection(cursor().selection());
- if (cur.needBufferUpdate()) {
+ if (cur.needBufferUpdate() || buffer().needUpdate()) {
cur.clearBufferUpdate();
buffer().updateBuffer();
}
buf.changeLanguage(buf.language(), d->cursor_.getFont().language());
buffer_.undo().recordUndo(d->cursor_);
cap::pasteParagraphList(d->cursor_, pars,
- buf.params().documentClassPtr(), el);
+ buf.params().documentClassPtr(),
+ buf.params().authors(), el);
res = _("Document %1$s inserted.");
} else {
res = _("Could not insert document %1$s");
p = getPos(cur);
// center fat carets horizontally
p.x_ -= dim.wid / 2;
+ // p is top-left
p.y_ -= dim.asc;
}
+void BufferView::buildCaretGeometry(bool complet)
+{
+ Point p;
+ Dimension dim;
+ caretPosAndDim(p, dim);
+
+ Cursor const & cur = d->cursor_;
+ Font const & realfont = cur.real_current_font;
+ frontend::FontMetrics const & fm = theFontMetrics(realfont.fontInfo());
+ bool const isrtl = realfont.isVisibleRightToLeft();
+ int const dir = isrtl ? -1 : 1;
+
+ frontend::CaretGeometry & cg = d->caret_geometry_;
+ cg.shapes.clear();
+
+ // The caret itself, slanted for italics in text edit mode except
+ // for selections because the selection rect does not slant
+ bool const slant = fm.italic() && cur.inTexted() && !cur.selection();
+ double const slope = slant ? fm.italicSlope() : 0;
+ cg.shapes.push_back(
+ {{iround(p.x_ + dim.asc * slope), p.y_},
+ {iround(p.x_ - dim.des * slope), p.y_ + dim.height()},
+ {iround(p.x_ + dir * dim.wid - dim.des * slope), p.y_ + dim.height()},
+ {iround(p.x_ + dir * dim.wid + dim.asc * slope), p.y_}}
+ );
+
+ // The language indicator _| (if needed)
+ Language const * doclang = buffer().params().language;
+ if (!((realfont.language() == doclang && isrtl == doclang->rightToLeft())
+ || realfont.language() == latex_language)) {
+ int const lx = dim.height() / 3;
+ int const xx = iround(p.x_ - dim.des * slope);
+ int const yy = p.y_ + dim.height();
+ cg.shapes.push_back(
+ {{xx, yy - dim.wid},
+ {xx + dir * (dim.wid + lx - 1), yy - dim.wid},
+ {xx + dir * (dim.wid + lx - 1), yy},
+ {xx, yy}}
+ );
+ }
+
+ // The completion triangle |> (if needed)
+ if (complet) {
+ int const m = p.y_ + dim.height() / 2;
+ int const d = dim.height() / 8;
+ // offset for slanted carret
+ int const sx = iround((dim.asc - (dim.height() / 2 - d)) * slope);
+ // starting position x
+ int const xx = p.x_ + dir * dim.wid + sx;
+ cg.shapes.push_back(
+ {{xx, m - d},
+ {xx + dir * d, m},
+ {xx, m + d},
+ {xx, m + d - dim.wid},
+ {xx + dir * d - dim.wid, m},
+ {xx, m - d + dim.wid}}
+ );
+ }
+
+ // compute extremal x values
+ cg.left = 1000000;
+ cg.right = -1000000;
+ cg.top = 1000000;
+ cg.bottom = -1000000;
+ for (auto const & shape : cg.shapes)
+ for (Point const & p : shape) {
+ cg.left = min(cg.left, p.x_);
+ cg.right = max(cg.right, p.x_);
+ cg.top = min(cg.top, p.y_);
+ cg.bottom = max(cg.bottom, p.y_);
+ }
+}
+
+
+frontend::CaretGeometry const & BufferView::caretGeometry() const
+{
+ return d->caret_geometry_;
+}
+
+
bool BufferView::caretInView() const
{
if (!paragraphVisible(cursor()))
* move at all
*/
if (paint_caret) {
- Row const & caret_row = d->cursor_.textRow();
- caret_row.changed(true);
+ Cursor cur(d->cursor_);
+ while (cur.depth() > 1) {
+ if (!cur.inTexted())
+ break;
+ TextMetrics const & tm = textMetrics(cur.text());
+ if (d->caret_geometry_.left >= tm.origin().x_
+ && d->caret_geometry_.right <= tm.origin().x_ + tm.dim().width())
+ break;
+ cur.pop();
+ }
+ cur.textRow().changed(true);
}
}