#include "counters.h"
#include "CutAndPaste.h"
#include "debug.h"
+#include "dispatchresult.h"
#include "errorlist.h"
#include "Floating.h"
#include "FloatList.h"
LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
ParagraphList & paragraphs)
- : height(0), width(0), anchor_y_(0),
+ : height(0), width(0),
inset_owner(inset), the_locking_inset(0), bv_owner(bv),
- in_inset_(ininset), paragraphs_(¶graphs)
+ in_inset_(ininset), paragraphs_(¶graphs),
+ cache_pos_(-1)
{
}
width = 0;
height = 0;
-
- anchor_y_ = 0;
+ cache_pos_ = -1;
current_font = getFont(beg, 0);
void LyXText::cursorEnd()
{
ParagraphList::iterator cpit = cursorPar();
- setCursor(cpit, cpit->getRow(cursor.pos())->endpos() - 1);
+ pos_type end = cpit->getRow(cursor.pos())->endpos();
+ /* if not on the last row of the par, put the cursor before
+ the final space */
+ setCursor(cpit, end == cpit->size() ? end : end - 1);
}
// If there is a change in the language the implicit word selection
// is disabled.
LyXCursor resetCursor = cursor;
- bool implicitSelection = (font.language() == ignore_language
- && font.number() == LyXFont::IGNORE)
- ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
+ bool implicitSelection =
+ font.language() == ignore_language
+ && font.number() == LyXFont::IGNORE
+ && selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT);
// Set font
setFont(font, toggleall);
// they do not duplicate themself and you cannnot make dirty things with
// them!
-void LyXText::setParagraph(bool line_top, bool line_bottom,
- bool pagebreak_top, bool pagebreak_bottom,
+void LyXText::setParagraph(
VSpace const & space_top,
VSpace const & space_bottom,
Spacing const & spacing,
ParagraphList::iterator const pit = cursorPar();
ParagraphParameters & params = pit->params();
-
- params.lineTop(line_top);
- params.lineBottom(line_bottom);
- params.pagebreakTop(pagebreak_top);
- params.pagebreakBottom(pagebreak_bottom);
params.spaceTop(space_top);
params.spaceBottom(space_bottom);
params.spacing(spacing);
+
// does the layout allow the new alignment?
LyXLayout_ptr const & layout = pit->layout();
// y is now the cursor baseline
cur.y(y);
- pos_type last = lastPos(*pit, row);
+ pos_type const end = row.endpos();
// None of these should happen, but we're scaredy-cats
- if (pos > pit->size()) {
+ if (pos < 0) {
+ lyxerr << "dont like -1" << endl;
+ pos = 0;
+ cur.pos(0);
+ BOOST_ASSERT(false);
+ } else if (pos > pit->size()) {
lyxerr << "dont like 1, pos: " << pos
<< " size: " << pit->size()
<< " row.pos():" << row.pos()
pos = 0;
cur.pos(0);
BOOST_ASSERT(false);
- } else if (pos > last + 1) {
+ } else if (pos > end) {
lyxerr << "dont like 2 please report" << endl;
// This shouldn't happen.
- pos = last + 1;
+ pos = end;
cur.pos(pos);
BOOST_ASSERT(false);
} else if (pos < row.pos()) {
cur.pos(pos);
BOOST_ASSERT(false);
}
-
// now get the cursors x position
- float x = getCursorX(pit, row, pos, last, boundary);
- cur.x(int(x));
- cur.x_fix(cur.x());
+ cur.x(int(getCursorX(pit, row, pos, boundary)));
+ bv()->x_target(cur.x());
}
float LyXText::getCursorX(ParagraphList::iterator pit, Row const & row,
- pos_type pos, pos_type last, bool boundary) const
+ pos_type pos, bool boundary) const
{
pos_type cursor_vpos = 0;
double x = row.x();
double fill_hfill = row.fill_hfill();
double fill_label_hfill = row.fill_label_hfill();
pos_type const row_pos = row.pos();
+ pos_type const end = row.endpos();
- if (last < row_pos)
+ if (end <= row_pos)
cursor_vpos = row_pos;
- else if (pos > last && !boundary)
+ else if (pos >= end && !boundary)
cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
- ? row_pos : last + 1;
- else if (pos > row_pos && (pos > last || boundary))
+ ? row_pos : end;
+ else if (pos > row_pos && (pos >= end || boundary))
// Place cursor after char at (logical) position pos - 1
cursor_vpos = (bidi.level(pos - 1) % 2 == 0)
? bidi.log2vis(pos - 1) + 1 : bidi.log2vis(pos - 1);
pos_type body_pos = pit->beginningOfBody();
if (body_pos > 0 &&
- (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
+ (body_pos > end || !pit->isLineSeparator(body_pos - 1)))
body_pos = 0;
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) {
- x += fill_label_hfill +
- font_metrics::width(
- pit->layout()->labelsep, getLabelFont(pit));
+ x += fill_label_hfill
+ + font_metrics::width(pit->layout()->labelsep,
+ getLabelFont(pit));
if (pit->isLineSeparator(body_pos - 1))
x -= singleWidth(pit, body_pos - 1);
}
double fill_label_hfill = row.fill_label_hfill();
pos_type vc = row.pos();
- pos_type last = lastPos(*pit, row);
+ pos_type end = row.endpos();
pos_type c = 0;
LyXLayout_ptr const & layout = pit->layout();
double last_tmpx = tmpx;
if (body_pos > 0 &&
- (body_pos - 1 > last ||
+ (body_pos > end ||
!pit->isLineSeparator(body_pos - 1)))
body_pos = 0;
// check for empty row
- if (!pit->size()) {
+ if (vc == end) {
x = int(tmpx);
return 0;
}
- while (vc <= last && tmpx <= x) {
+ while (vc < end && tmpx <= x) {
c = bidi.vis2log(vc);
last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) {
left_side = true;
}
- if (vc > last + 1) // This shouldn't happen.
- vc = last + 1;
+ BOOST_ASSERT(vc <= end); // This shouldn't happen.
boundary = false;
// This (rtl_support test) is not needed, but gives
: false;
if (lastrow &&
((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
- (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
- c = last + 1;
+ (!rtl && !left_side && vc == end && x > tmpx + 5)))
+ c = end;
else if (vc == row.pos()) {
c = bidi.vis2log(vc);
if (bidi.level(c) % 2 == 1)
}
}
- if (row.pos() <= last && c > last && pit->isNewline(last)) {
- if (bidi.level(last) % 2 == 0)
- tmpx -= singleWidth(pit, last);
+ if (row.pos() < end && c >= end && pit->isNewline(end - 1)) {
+ if (bidi.level(end -1) % 2 == 0)
+ tmpx -= singleWidth(pit, end - 1);
else
- tmpx += singleWidth(pit, last);
- c = last;
+ tmpx += singleWidth(pit, end - 1);
+ c = end - 1;
}
c -= row.pos();
ParagraphList::iterator cpit = cursorPar();
Row const & crow = *cpit->getRow(cursor.pos());
#if 1
- int x = cursor.x_fix();
+ int x = bv()->x_target();
int y = cursor.y() - crow.baseline() - 1;
setCursorFromCoordinates(x, y);
if (!selecting) {
#else
lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
crow.baseline() << endl;
- setCursorFromCoordinates(cursor.x_fix(),
+ setCursorFromCoordinates(bv()->x_target(),
cursor.y() - crow.baseline() - 1);
#endif
}
ParagraphList::iterator cpit = cursorPar();
Row const & crow = *cpit->getRow(cursor.pos());
#if 1
- int x = cursor.x_fix();
+ int x = bv()->x_target();
int y = cursor.y() - crow.baseline() + crow.height() + 1;
setCursorFromCoordinates(x, y);
if (!selecting) {
}
}
#else
- setCursorFromCoordinates(cursor.x_fix(),
+ setCursorFromCoordinates(bv()->x_target(),
cursor.y() - crow.baseline() + crow.height() + 1);
#endif
}
// we can't possibly have deleted a paragraph before this point
bool deleted = false;
- if (old_pit->empty() ||
- (old_pit->size() == 1 && old_pit->isLineSeparator(0))) {
+ if (old_pit->empty()
+ || (old_pit->size() == 1 && old_pit->isLineSeparator(0))) {
// ok, we will delete something
LyXCursor tmpcursor;
selection.cursor = cursor;
}
}
- if (!deleted) {
- if (old_pit->stripLeadingSpaces()) {
- redoParagraph(old_pit);
- // correct cursor y
- setCursorIntern(cursor.par(), cursor.pos());
- selection.cursor = cursor;
- }
+
+ if (deleted)
+ return true;
+
+ if (old_pit->stripLeadingSpaces()) {
+ redoParagraph(old_pit);
+ // correct cursor y
+ setCursorIntern(cursor.par(), cursor.pos());
+ selection.cursor = cursor;
}
- return deleted;
+ return false;
}
int defaultRowHeight()
{
LyXFont const font(LyXFont::ALL_SANE);
- return int(font_metrics::maxAscent(font)
- + font_metrics::maxDescent(font) * 1.5);
+ return int(font_metrics::maxHeight(font) * 1.2);
}