void LyXText::cursorHome(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
- setCursor(cur, cur.pit(), cur.textRow().pos());
+ Row const & row = cur.paragraph().getRow(cur.pos(),cur.boundary());
+
+ setCursor(cur, cur.pit(), row.pos());
}
{
BOOST_ASSERT(this == cur.text());
// if not on the last row of the par, put the cursor before
- // the final space
-// FIXME: does this final space exist?
- pos_type const end = cur.textRow().endpos();
- setCursor(cur, cur.pit(), end == cur.lastpos() ? end : end - 1);
+ // the final space exept if I have a spanning inset or one string
+ // is so long that we force a break.
+ pos_type end = cur.textRow().endpos();
+ if (end == 0)
+ // empty text, end-1 is no valid position
+ return;
+ bool boundary = false;
+ if (end != cur.lastpos()) {
+ if (!cur.paragraph().isLineSeparator(end-1)
+ && !cur.paragraph().isNewline(end-1))
+ boundary = true;
+ else
+ --end;
+ }
+ setCursor(cur, cur.pit(), end, true, boundary);
}
// needed to insert the selection
void LyXText::insertStringAsLines(LCursor & cur, string const & str)
{
- pit_type pit = cur.pit();
- pos_type pos = cur.pos();
- recordUndo(cur);
-
- // only to be sure, should not be neccessary
- cur.clearSelection();
- cur.buffer().insertStringAsLines(pars_, pit, pos, current_font, str,
- autoBreakRows_);
-
- cur.resetAnchor();
- setCursor(cur, cur.pit(), pos);
- cur.setSelection();
+ cur.buffer().insertStringAsLines(pars_, cur.pit(), cur.pos(),
+ current_font, str, autoBreakRows_);
}
BOOST_ASSERT(par != int(paragraphs().size()));
cur.pit() = par;
cur.pos() = pos;
- cur.boundary() = boundary;
// now some strict checking
Paragraph & para = getPar(par);
void LyXText::setCursorIntern(LCursor & cur,
pit_type par, pos_type pos, bool setfont, bool boundary)
{
+ cur.boundary(boundary);
setCursor(cur.top(), par, pos, boundary);
cur.setTargetX();
if (setfont)
}
}
+// I believe this code is not needed anymore (Jug 20050717)
+#if 0
// The following code is necessary because the cursor position past
// the last char in a row is logically equivalent to that before
// the first char in the next row. That's why insets causing row
tmpx += singleWidth(par, end - 1);
c = end - 1;
}
+
// Air gap above display inset:
if (row.pos() < end && c >= end && end < par.size()
&& par.isInset(end) && par.getInset(end)->display()) {
&& par.getInset(end - 1)->display()) {
c = end - 1;
}
+#endif
x = int(tmpx) + xo;
+ pos_type const col = c - row.pos();
- if (end == par.size())
- return c - row.pos();
+ if (!c || end == par.size())
+ return col;
- return min(c - row.pos(), end - 1 - row.pos());
+ if (c==end && !par.isLineSeparator(c-1) && !par.isNewline(c-1)) {
+ boundary = true;
+ return col;
+ }
+
+ return min(col, end - 1 - row.pos());
}
pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
cur.pit() = pit;
cur.pos() = pos;
- cur.boundary() = bound;
+ cur.boundary(bound);
cur.x_target() = x;
// try to descend into nested insets
bool LyXText::cursorLeft(LCursor & cur)
{
+ if (!cur.boundary() && cur.pos() > 0 &&
+ cur.textRow().pos() == cur.pos() &&
+ !cur.paragraph().isLineSeparator(cur.pos()-1) &&
+ !cur.paragraph().isNewline(cur.pos()-1))
+ {
+ return setCursor(cur, cur.pit(), cur.pos(), true, true);
+ }
if (cur.pos() != 0) {
bool boundary = cur.boundary();
bool updateNeeded = setCursor(cur, cur.pit(), cur.pos() - 1, true, false);
bool LyXText::cursorRight(LCursor & cur)
{
- if (false && cur.boundary()) {
+ if (cur.boundary()) {
return setCursor(cur, cur.pit(), cur.pos(), true, false);
}
if (cur.pos() != cur.lastpos()) {
bool updateNeeded = false;
if (!checkAndActivateInset(cur, true)) {
- updateNeeded |= setCursor(cur, cur.pit(), cur.pos() + 1, true, false);
+ if (cur.textRow().endpos() == cur.pos() + 1 &&
+ cur.textRow().endpos() != cur.lastpos() &&
+ !cur.paragraph().isLineSeparator(cur.pos()) &&
+ !cur.paragraph().isNewline(cur.pos()))
+ {
+ cur.boundary(true);
+ }
+ updateNeeded |= setCursor(cur, cur.pit(), cur.pos() + 1, true, cur.boundary());
if (false && bidi.isBoundary(cur.buffer(), cur.paragraph(),
cur.pos()))
updateNeeded |= setCursor(cur, cur.pit(), cur.pos(), true, true);
bool LyXText::cursorUp(LCursor & cur)
{
Paragraph const & par = cur.paragraph();
- int const row = par.pos2row(cur.pos());
+ int row;
int const x = cur.targetX();
+ if (cur.pos() && cur.boundary())
+ row = par.pos2row(cur.pos()-1);
+ else
+ row = par.pos2row(cur.pos());
+
if (!cur.selection()) {
- int const y = bv_funcs::getPos(cur).y_;
+ int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
LCursor old = cur;
editXY(cur, x, y - par.rows()[row].ascent() - 1);
} else if (cur.pit() > 0) {
--cur.pit();
//cannot use 'par' now
- updateNeeded |= setCursor(cur, cur.pit(), x2pos(cur.pit(), cur.paragraph().rows().size() - 1, x));
+ updateNeeded |= setCursor(cur, cur.pit(),
+ x2pos(cur.pit(), cur.paragraph().rows().size() - 1, x));
}
cur.x_target() = x;
bool LyXText::cursorDown(LCursor & cur)
{
Paragraph const & par = cur.paragraph();
- int const row = par.pos2row(cur.pos());
+ int row;
int const x = cur.targetX();
+ if (cur.pos() && cur.boundary())
+ row = par.pos2row(cur.pos()-1);
+ else
+ row = par.pos2row(cur.pos());
+
if (!cur.selection()) {
- int const y = bv_funcs::getPos(cur).y_;
+ int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
LCursor old = cur;
editXY(cur, x, y + par.rows()[row].descent() + 1);
if (old.pos() > 0
&& old.pos() < oldpar.size()
&& oldpar.isLineSeparator(old.pos())
- && oldpar.isLineSeparator(old.pos() - 1)) {
+ && oldpar.isLineSeparator(old.pos() - 1)
+ && oldpar.lookupChange(old.pos() - 1) != Change::DELETED) {
// We need to set the text to Change::INSERTED to
// get it erased properly
pars_[old.pit()].setChange(old.pos() -1,
}
}
- if (deleted)
+ if (deleted) {
+ updateCounters(cur.buffer());
return true;
+ }
if (pars_[old.pit()].stripLeadingSpaces())
cur.resetAnchor();
}
-ParagraphList & LyXText::paragraphs() const
-{
- return const_cast<ParagraphList &>(pars_);
-}
-
-
void LyXText::recUndo(pit_type first, pit_type last) const
{
recordUndo(bv()->cursor(), Undo::ATOMIC, first, last);