#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
+#include "frontends/Selection.h"
#include "insets/insettext.h"
#include "insets/insetbibitem.h"
pars_[next_par].applyLayout(tclass.defaultLayout());
}
- while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
- pars_[next_par].eraseChar(0, cur.buffer().params().trackChanges);
+ while (!pars_[next_par].empty() && pars_[next_par].isNewline(0)) {
+ if (!pars_[next_par].eraseChar(0, cur.buffer().params().trackChanges))
+ break; // the character couldn't be deleted physically due to change tracking
+ }
ParIterator current_it(cur);
ParIterator last_it(cur);
cur.resetAnchor();
setCursor(cur, to.pit(), to.pos());
cur.setSelection();
+ theSelection().haveSelection(cur.selection());
}
for (; pit <= et.pit(); ++pit) {
pos_type left = (pit == it.pit() ? it.pos() : 0);
pos_type right = (pit == et.pit() ? et.pos() : pars_[pit].size());
- pars_[pit].acceptChanges(left, right);
- // merge paragraph if appropriate:
- // if (right >= pars_[pit].size() && pit + 1 < et.pit() &&
- // pars_[pit].isDeleted(pars_[pit].size())) {
- // setCursorIntern(cur, pit + 1, 0);
- // backspacePos0(cur);
- //}
+ // handle imaginary end-of-par character first
+ if (right == pars_[pit].size() && !pars_[pit].isUnchanged(right)) {
+ if (pars_[pit].isInserted(right)) {
+ pars_[pit].setChange(right, Change(Change::UNCHANGED));
+ } else {
+ // if (pit + 1 < et.pit()) {
+ // setCursorIntern(cur, pit + 1, 0);
+ // backspacePos0(cur);
+ // }
+ }
+ }
+
+ pars_[pit].acceptChanges(left, right);
}
finishUndo();
cur.clearSelection();
- setCursorIntern(cur, it.pit(), 0);
+ setCursorIntern(cur, it.pit(), it.pos());
+ cur.updateFlags(Update::Force);
}
for (; pit <= et.pit(); ++pit) {
pos_type left = (pit == it.pit() ? it.pos() : 0);
pos_type right = (pit == et.pit() ? et.pos() : pars_[pit].size());
- pars_[pit].rejectChanges(left, right);
- // merge paragraph if appropriate:
- // if (right >= pars_[pit].size() && pit + 1 < et.pit() &&
- // pars_[pit].isInserted(pars_[pit].size())) {
- // setCursorIntern(cur, pit + 1, 0);
- // backspacePos0(cur);
- //}
+ // handle imaginary end-of-par character first
+ if (right == pars_[pit].size() && !pars_[pit].isUnchanged(right)) {
+ if (pars_[pit].isDeleted(right)) {
+ pars_[pit].setChange(right, Change(Change::UNCHANGED));
+ } else {
+ // if (pit + 1 < et.pit()) {
+ // setCursorIntern(cur, pit + 1, 0);
+ // backspacePos0(cur);
+ // }
+ }
+ }
+
+ pars_[pit].rejectChanges(left, right);
}
finishUndo();
cur.clearSelection();
- setCursorIntern(cur, it.pit(), 0);
+ setCursorIntern(cur, it.pit(), it.pos());
+ cur.updateFlags(Update::Force);
}
odocstringstream os;
if (buf.params().trackChanges)
- os << "[C] ";
+ os << _("[Change Tracking] ");
Change change = par.lookupChange(cur.pos());
}
-//pos_type LyXText::x2pos(pit_type pit, int row, int x) const
-//{
-// int lastx = 0;
-// int currx = 0;
-// Paragraph const & par = pars_[pit];
-// Row const & r = par.rows()[row];
-// int pos = r.pos();
-// for (; currx < x && pos < r.endpos(); ++pos) {
-// lastx = currx;
-// currx += singleWidth(buffer, par, pos);
-// }
-// if (abs(lastx - x) < abs(currx - x) && pos != r.pos())
-// --pos;
-// return pos;
-//}
-
-
-pos_type LyXText::x2pos(BufferView const & bv, pit_type pit, int row,
- int x) const
-{
- TextMetrics const & tm = bv.textMetrics(this);
- ParagraphMetrics const & pm = tm.parMetrics(pit);
- BOOST_ASSERT(!pm.rows().empty());
- BOOST_ASSERT(row < int(pm.rows().size()));
- bool bound = false;
- Row const & r = pm.rows()[row];
- return r.pos() + getColumnNearX(bv, tm.rightMargin(pm), pit, r, x, bound);
-}
-
-
-//int LyXText::pos2x(pit_type pit, pos_type pos) const
-//{
-// Paragraph const & par = pars_[pit];
-// Row const & r = par.rows()[row];
-// int x = 0;
-// pos -= r.pos();
-//}
-
-
void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
{
BOOST_ASSERT(this == cur.text());
bool bound = false;
int xx = x;
- int right_margin = tm.rightMargin(pm);
- pos_type const pos = row.pos() + getColumnNearX(cur.bv(), right_margin,
- pit, row, xx, bound);
+ pos_type const pos = row.pos()
+ + tm.getColumnNearX(pit, row, xx, bound);
lyxerr[Debug::DEBUG]
<< BOOST_CURRENT_FUNCTION
<< endl;
setCursor(cur, pit, pos, true, bound);
- return;
+ // remember new position.
+ cur.setTargetX();
}