redoParagraphs(beg, end);
setCursorIntern(0, 0);
- bv()->resetAnchor();
+ bv()->cursor().resetAnchor();
updateCounters();
}
return;
}
- ParagraphList::iterator start = getPar(bv()->selStart().par());
- ParagraphList::iterator end = boost::next(getPar(bv()->selEnd().par()));
+ ParagraphList::iterator start =
+ getPar(bv()->cursor().selStart().par());
+ ParagraphList::iterator end =
+ boost::next(getPar(bv()->cursor().selEnd().par()));
ParagraphList::iterator endpit = setLayout(start, end, layout);
redoParagraphs(start, endpit);
ParagraphList::iterator & beg,
ParagraphList::iterator & end)
{
- if (!text.bv()->selection().set()) {
+ if (!text.bv()->cursor().selection()) {
beg = text.cursorPar();
end = boost::next(beg);
} else {
- beg = text.getPar(text.bv()->selStart());
- end = boost::next(text.getPar(text.bv()->selEnd()));
+ beg = text.getPar(text.bv()->cursor().selStart());
+ end = boost::next(text.getPar(text.bv()->cursor().selEnd()));
}
}
// set font over selection and make a total rebreak of those paragraphs
void LyXText::setFont(LyXFont const & font, bool toggleall)
{
+ LCursor & cur = bv()->cursor();
// if there is no selection just set the current_font
- if (!bv()->selection().set()) {
+ if (!cur.selection()) {
// Determine basis font
LyXFont layoutfont;
if (cursor().pos() < cursorPar()->beginOfBody())
}
// ok we have a selection.
- recUndo(bv()->selStart().par(), bv()->selEnd().par());
+ recUndo(cur.selStart().par(), cur.selEnd().par());
freezeUndo();
- ParagraphList::iterator beg = getPar(bv()->selStart().par());
- ParagraphList::iterator end = getPar(bv()->selEnd().par());
+ ParagraphList::iterator beg = getPar(cur.selStart().par());
+ ParagraphList::iterator end = getPar(cur.selEnd().par());
- PosIterator pos(¶graphs(), beg, bv()->selStart().pos());
- PosIterator posend(¶graphs(), end, bv()->selEnd().pos());
+ PosIterator pos(¶graphs(), beg, cur.selStart().pos());
+ PosIterator posend(¶graphs(), end, cur.selEnd().pos());
BufferParams const & params = bv()->buffer()->params();
// Implicit selections are cleared afterwards
//and cursor is set to the original position.
if (implicitSelection) {
- bv()->clearSelection();
+ bv()->cursor().clearSelection();
cursor() = resetCursor;
- bv()->resetAnchor();
+ bv()->cursor().resetAnchor();
}
}
string LyXText::getStringToIndex()
{
+ LCursor & cur = bv()->cursor();
// Try implicit word selection
// If there is a change in the language the implicit word selection
// is disabled.
selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
string idxstring;
- if (!bv()->selection().set())
+ if (!cur.selection())
bv()->owner()->message(_("Nothing to index!"));
- else if (bv()->selStart().par() != bv()->selEnd().par())
+ else if (cur.selStart().par() != cur.selEnd().par())
bv()->owner()->message(_("Cannot index more than one paragraph!"));
else
idxstring = selectionAsString(*bv()->buffer(), false);
// Reset cursors to their original position.
cursor() = reset_cursor;
- bv()->resetAnchor();
+ cur.resetAnchor();
// Clear the implicit selection.
if (implicitSelection)
- bv()->clearSelection();
+ cur.clearSelection();
return idxstring;
}
void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
string const & labelwidthstring, bool noindent)
{
+ LCursor & cur = bv()->cursor();
// make sure that the depth behind the selection are restored, too
- ParagraphList::iterator undopit = undoSpan(getPar(bv()->selEnd()));
- recUndo(bv()->selStart().par(), parOffset(undopit) - 1);
+ ParagraphList::iterator undopit = undoSpan(getPar(cur.selEnd()));
+ recUndo(cur.selStart().par(), parOffset(undopit) - 1);
- ParagraphList::reverse_iterator pit(getPar(bv()->selEnd().par()));
- ParagraphList::reverse_iterator beg(getPar(bv()->selStart().par()));
+ ParagraphList::reverse_iterator pit(getPar(cur.selEnd().par()));
+ ParagraphList::reverse_iterator beg(getPar(cur.selStart().par()));
for (--pit; pit != beg; ++pit) {
ParagraphParameters & params = pit->params();
params.noindent(noindent);
}
- redoParagraphs(getPar(bv()->selStart()), undopit);
+ redoParagraphs(getPar(cur.selStart()), undopit);
}
void LyXText::cutSelection(bool doclear, bool realcut)
{
+ LCursor & cur = bv()->cursor();
// Stuff what we got on the clipboard. Even if there is no selection.
// There is a problem with having the stuffing here in that the
bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
// This doesn't make sense, if there is no selection
- if (!bv()->selection().set())
+ if (!cur.selection())
return;
- // OK, we have a selection. This is always between bv()->selStart()
- // and bv()->selEnd()
+ // OK, we have a selection. This is always between cur.selStart()
+ // and cur.selEnd()
// make sure that the depth behind the selection are restored, too
- ParagraphList::iterator begpit = getPar(bv()->selStart().par());
- ParagraphList::iterator endpit = getPar(bv()->selEnd().par());
+ ParagraphList::iterator begpit = getPar(cur.selStart().par());
+ ParagraphList::iterator endpit = getPar(cur.selEnd().par());
ParagraphList::iterator undopit = undoSpan(endpit);
- recUndo(bv()->selStart().par(), parOffset(undopit) - 1);
+ recUndo(cur.selStart().par(), parOffset(undopit) - 1);
- int endpos = bv()->selEnd().pos();
+ int endpos = cur.selEnd().pos();
BufferParams const & bufparams = bv()->buffer()->params();
boost::tie(endpit, endpos) = realcut ?
CutAndPaste::cutSelection(bufparams,
paragraphs(),
begpit , endpit,
- bv()->selStart().pos(), endpos,
+ cur.selStart().pos(), endpos,
bufparams.textclass,
doclear)
: CutAndPaste::eraseSelection(bufparams,
paragraphs(),
begpit, endpit,
- bv()->selStart().pos(), endpos,
+ cur.selStart().pos(), endpos,
doclear);
// sometimes necessary
if (doclear)
cursor().par(parOffset(endpit));
// need a valid cursor. (Lgb)
- bv()->clearSelection();
+ cur.clearSelection();
updateCounters();
}
void LyXText::copySelection()
{
+ LCursor & cur = bv()->cursor();
// stuff the selection onto the X clipboard, from an explicit copy request
bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
// this doesnt make sense, if there is no selection
- if (!bv()->selection().set())
+ if (!cur.selection())
return;
- // ok we have a selection. This is always between bv()->selStart()
+ // ok we have a selection. This is always between cur.selStart()
// and sel_end cursor
// copy behind a space if there is one
- while (getPar(bv()->selStart())->size() > bv()->selStart().pos()
- && getPar(bv()->selStart())->isLineSeparator(bv()->selStart().pos())
- && (bv()->selStart().par() != bv()->selEnd().par()
- || bv()->selStart().pos() < bv()->selEnd().pos()))
- bv()->selStart().pos(bv()->selStart().pos() + 1);
-
- CutAndPaste::copySelection(getPar(bv()->selStart().par()),
- getPar(bv()->selEnd().par()),
- bv()->selStart().pos(),
- bv()->selEnd().pos(),
+ while (getPar(cur.selStart())->size() > cur.selStart().pos()
+ && getPar(cur.selStart())->isLineSeparator(cur.selStart().pos())
+ && (cur.selStart().par() != cur.selEnd().par()
+ || cur.selStart().pos() < cur.selEnd().pos()))
+ cur.selStart().pos(cur.selStart().pos() + 1);
+
+ CutAndPaste::copySelection(getPar(cur.selStart().par()),
+ getPar(cur.selEnd().par()),
+ cur.selStart().pos(),
+ cur.selEnd().pos(),
bv()->buffer()->params().textclass);
}
void LyXText::pasteSelection(size_t sel_index)
{
+ LCursor & cur = bv()->cursor();
// this does not make sense, if there is nothing to paste
if (!CutAndPaste::checkPastePossible())
return;
redoParagraphs(cursorPar(), endpit);
- bv()->clearSelection();
- bv()->resetAnchor();
+ cur.clearSelection();
+ cur.resetAnchor();
setCursor(ppp.first, ppp.second);
- bv()->setSelection();
+ cur.setSelection();
updateCounters();
}
if (!length)
return;
- bv()->resetAnchor();
+ LCursor & cur = bv()->cursor();
+ cur.resetAnchor();
while (length--)
cursorRight(true);
- bv()->setSelection();
+ cur.setSelection();
}
// simple replacing. The font of the first selected character is used
void LyXText::replaceSelectionWithString(string const & str)
{
- recUndo(cursor().par());
+ LCursor & cur = bv()->cursor();
+ recUndo(cur.par());
freezeUndo();
// Get font setting before we cut
- pos_type pos = bv()->selEnd().pos();
- LyXFont const font = getPar(bv()->selStart())
+ pos_type pos = cur.selEnd().pos();
+ LyXFont const font = getPar(cur.selStart())
->getFontSettings(bv()->buffer()->params(),
- bv()->selStart().pos());
+ cur.selStart().pos());
// Insert the new string
string::const_iterator cit = str.begin();
string::const_iterator end = str.end();
for (; cit != end; ++cit) {
- getPar(bv()->selEnd())->insertChar(pos, (*cit), font);
+ getPar(cur.selEnd())->insertChar(pos, (*cit), font);
++pos;
}
// needed to insert the selection
void LyXText::insertStringAsLines(string const & str)
{
+ LCursor & cur = bv()->cursor();
ParagraphList::iterator pit = cursorPar();
pos_type pos = cursor().pos();
ParagraphList::iterator endpit = boost::next(cursorPar());
recUndo(cursor().par());
// only to be sure, should not be neccessary
- bv()->clearSelection();
+ cur.clearSelection();
bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
redoParagraphs(cursorPar(), endpit);
- bv()->resetAnchor();
+ cur.resetAnchor();
setCursor(pit, pos);
- bv()->setSelection();
+ cur.setSelection();
}
return;
// now some strict checking
- ParagraphList::iterator pit = getPar(par);
- Row const & row = *pit->getRow(pos);
+ Paragraph & para = *getPar(par);
+ Row const & row = *para.getRow(pos);
pos_type const end = row.endpos();
// None of these should happen, but we're scaredy-cats
pos = 0;
cur.pos(0);
BOOST_ASSERT(false);
- } else if (pos > pit->size()) {
+ } else if (pos > para.size()) {
lyxerr << "dont like 1, pos: " << pos
- << " size: " << pit->size()
+ << " size: " << para.size()
<< " row.pos():" << row.pos()
<< " paroffset: " << par << endl;
pos = 0;
BOOST_ASSERT(false);
} else if (pos < row.pos()) {
lyxerr << "dont like 3 please report pos:" << pos
- << " size: " << pit->size()
+ << " size: " << para.size()
<< " row.pos():" << row.pos()
<< " paroffset: " << par << endl;
pos = row.pos();
pos_type pos, bool setfont, bool boundary)
{
setCursor(cursor(), par, pos, boundary);
- bv()->x_target(cursorX() + xo_);
+ bv()->cursor().x_target(cursorX() + xo_);
if (setfont)
setCurrentFont();
}
void LyXText::setCurrentFont()
{
- pos_type pos = cursor().pos();
+ LCursor & cur = bv()->cursor();
+ pos_type pos = cur.pos();
ParagraphList::iterator pit = cursorPar();
if (cursor().boundary() && pos > 0)
// If lastrow is false, we don't need to compute
// the value of rtl.
- bool const rtl = (lastrow)
+ bool const rtl = lastrow
? pit->isRightToLeftPar(bv()->buffer()->params())
: false;
if (lastrow &&
InsetOld * inset = cursorPar()->getInset(cursor().pos());
if (!isHighlyEditableInset(inset))
return false;
- inset->edit(bv(), front);
+ inset->edit(bv()->cursor(), front);
return true;
}
return DispatchResult(true, true);
cursorRight(true);
if (!selecting)
- bv()->clearSelection();
+ bv()->cursor().clearSelection();
return DispatchResult(true);
}
return DispatchResult(false, FINISHED);
cursorLeft(true);
if (!selecting)
- bv()->clearSelection();
+ bv()->cursor().clearSelection();
if (activate_inset && checkAndActivateInset(front))
return DispatchResult(true, true);
return DispatchResult(true);
if (cursorPar() == firstPar() && cursorRow() == firstRow())
return DispatchResult(false, FINISHED_UP);
cursorUp(false);
- bv()->clearSelection();
+ bv()->cursor().clearSelection();
return DispatchResult(true);
}
DispatchResult LyXText::moveDown()
{
+ LCursor & cur = bv()->cursor();
if (cursorPar() == lastPar() && cursorRow() == lastRow())
return DispatchResult(false, FINISHED_DOWN);
cursorDown(false);
- bv()->clearSelection();
+ cur.clearSelection();
return DispatchResult(true);
}
bool LyXText::cursorLeft(bool internal)
{
- if (cursor().pos() > 0) {
- bool boundary = cursor().boundary();
- setCursor(cursor().par(), cursor().pos() - 1, true, false);
+ LCursor & cur = bv()->cursor();
+ if (cur.pos() > 0) {
+ bool boundary = cur.boundary();
+ setCursor(cur.par(), cur.pos() - 1, true, false);
if (!internal && !boundary &&
- bidi.isBoundary(*bv()->buffer(), *cursorPar(), cursor().pos() + 1))
- setCursor(cursor().par(), cursor().pos() + 1, true, true);
+ bidi.isBoundary(*bv()->buffer(), cur.paragraph(), cur.pos() + 1))
+ setCursor(cur.par(), cur.pos() + 1, true, true);
return true;
}
- if (cursor().par() != 0) {
+ if (cur.par() != 0) {
// steps into the paragraph above
- setCursor(cursor().par() - 1, boost::prior(cursorPar())->size());
+ setCursor(cur.par() - 1, boost::prior(cursorPar())->size());
return true;
}
bool LyXText::cursorRight(bool internal)
{
- if (!internal && cursor().boundary()) {
- setCursor(cursor().par(), cursor().pos(), true, false);
+ LCursor & cur = bv()->cursor();
+ if (!internal && cur.boundary()) {
+ setCursor(cur.par(), cur.pos(), true, false);
return true;
}
- if (cursor().pos() != cursorPar()->size()) {
- setCursor(cursor().par(), cursor().pos() + 1, true, false);
- if (!internal && bidi.isBoundary(*bv()->buffer(), *cursorPar(),
- cursor().pos()))
- setCursor(cursor().par(), cursor().pos(), true, true);
+ if (cur.pos() != cur.lastpos()) {
+ setCursor(cur.par(), cur.pos() + 1, true, false);
+ if (!internal && bidi.isBoundary(*bv()->buffer(), cur.paragraph(),
+ cur.pos()))
+ setCursor(cur.par(), cur.pos(), true, true);
return true;
}
- if (cursor().par() + 1 != int(paragraphs().size())) {
- setCursor(cursor().par() + 1, 0);
+ if (cur.par() + 1 != int(paragraphs().size())) {
+ setCursor(cur.par() + 1, 0);
return true;
}
void LyXText::cursorUp(bool selecting)
{
+ LCursor & cur = bv()->cursor();
Row const & row = *cursorRow();
- int x = bv()->x_target() - xo_;
+ int x = cur.x_target() - xo_;
int y = cursorY() - row.baseline() - 1;
setCursorFromCoordinates(x, y);
if (!selecting) {
int y_abs = y + yo_ - bv()->top_y();
- InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y_abs);
+ InsetOld * inset_hit = checkInsetHit(cur.x_target(), y_abs);
if (inset_hit && isHighlyEditableInset(inset_hit))
- inset_hit->edit(bv(), bv()->x_target(), y_abs);
+ inset_hit->edit(cur, cur.x_target(), y_abs);
}
}
void LyXText::cursorDown(bool selecting)
{
+ LCursor & cur = bv()->cursor();
Row const & row = *cursorRow();
- int x = bv()->x_target() - xo_;
+ int x = cur.x_target() - xo_;
int y = cursorY() - row.baseline() + row.height() + 1;
setCursorFromCoordinates(x, y);
if (!selecting) {
int y_abs = y + yo_ - bv()->top_y();
- InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y_abs);
+ InsetOld * inset_hit = checkInsetHit(cur.x_target(), y_abs);
if (inset_hit && isHighlyEditableInset(inset_hit))
- inset_hit->edit(bv(), bv()->x_target(), y_abs);
+ inset_hit->edit(cur, cur.x_target(), y_abs);
}
}
// check also if we don't want to set the cursor on a spot behind the
// pagragraph because we erased the last character.
- if (cur.pos() > getPar(cur)->size())
- cur.pos(getPar(cur)->size());
+ if (cur.pos() > cur.lastpos())
+ cur.pos() = cur.lastpos();
}
return false;
// Would be wrong to delete anything if we have a selection.
- if (bv()->selection().set())
+ if (bv()->cursor().selection())
return false;
// Don't do anything if the cursor is invalid
if (old_cursor.par() == -1)
return false;
+#if 0
// We allow all kinds of "mumbo-jumbo" when freespacing.
ParagraphList::iterator const old_pit = getPar(old_cursor);
if (old_pit->isFreeSpacing())
bv()->resetAnchor();
}
return false;
+#endif
}