more IU as advertised

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8431 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-02-13 13:51:12 +00:00
parent 2288d17247
commit 7a0b5603e5
25 changed files with 207 additions and 239 deletions

View File

@ -474,13 +474,14 @@ void BufferView::Pimpl::scrollDocView(int value)
int const first = top_y() + height;
int const last = top_y() + workarea().workHeight() - height;
bv_->cursor().reset();
LyXText * text = bv_->text();
CursorSlice & cur = bv_->cursor().cursor_.front();
int y = text->cursorY(cur);
if (y < first)
text->setCursorFromCoordinates(cur, 0, first);
text->setCursorFromCoordinates(bv_->cursor(), 0, first);
else if (y > last)
text->setCursorFromCoordinates(cur, 0, last);
text->setCursorFromCoordinates(bv_->cursor(), 0, last);
owner_->updateLayoutChoice();
}
@ -922,18 +923,12 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
// surrounding LyXText will handle this event.
// built temporary path to inset
LyXText * text = bv_->text();
InsetBase * const inset_hit = text->checkInsetHit(cmd.x, cmd.y);
if (inset_hit)
inset_hit->edit(cur, cmd.x, cmd.y);
else
text->setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y);
lyxerr << "hit inset at tip: " << inset << endl;
lyxerr << "created temp cursor: " << cur << endl;
// Try to dispatch to an non-editable inset near this position
DispatchResult res;
InsetBase * inset = cur.nextInset();
lyxerr << "next inset: " << inset << endl;
if (inset)
res = inset->dispatch(cur, cmd);
@ -1027,7 +1022,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
case LFUN_INSERT_LABEL: {
// Try and generate a valid label
string const contents = cmd.argument.empty() ?
getPossibleLabel(*bv_) : cmd.argument;
cur.getPossibleLabel() : cmd.argument;
InsetCommandParams icp("label", contents);
string data = InsetCommandMailer::params2string("label", icp);
owner_->getDialogs().show("label", data, 0);

View File

@ -1810,13 +1810,6 @@ void LCursor::handleFont(string const & font)
}
void LCursor::releaseMathCursor()
{
if (inMathed())
formula()->insetUnlock(bv());
}
bool LCursor::inMathed() const
{
return formula();
@ -1937,3 +1930,9 @@ void LCursor::update()
{
bv().update();
}
string LCursor::getPossibleLabel()
{
return inMathed() ? "eq:" : text()->getPossibleLabel(*this);
}

View File

@ -426,7 +426,6 @@ public:
/// split font inset etc
void handleFont(std::string const & font);
void releaseMathCursor();
/// are we in mathed?
bool inMathed() const;
/// are we in texted?
@ -436,6 +435,8 @@ public:
void message(std::string const & msg) const;
/// display an error message
void errorMessage(std::string const & msg) const;
///
std::string getPossibleLabel();
private:
/// moves cursor index one cell to the left

View File

@ -120,7 +120,7 @@ public:
///
friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
public:
/// pointer to an inset
/// pointer to 'owning' inset
InsetBase * inset_;
/// cell index of a position in this inset
idx_type idx_;

View File

@ -35,6 +35,7 @@ DispatchResult InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd)
DispatchResult InsetBase::priv_dispatch(LCursor &, FuncRequest const &)
{
lyxerr << "InsetBase::priv_dispatch" << std::endl;
return DispatchResult(false);
}
@ -45,10 +46,10 @@ void InsetBase::edit(LCursor &, bool)
}
void InsetBase::edit(LCursor & cur, int, int)
InsetBase * InsetBase::editXY(LCursor & cur, int, int)
{
lyxerr << "InsetBase: edit xy" << std::endl;
edit(cur, true);
return this;
}

View File

@ -73,7 +73,7 @@ public:
/// cursor enters
virtual void edit(LCursor & cur, bool left);
/// cursor enters
virtual void edit(LCursor & cur, int x, int y);
virtual InsetBase * editXY(LCursor & cur, int x, int y);
/// compute the size of the object returned in dim
virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;

View File

@ -299,7 +299,7 @@ void InsetCollapsable::edit(LCursor & cur, bool left)
}
void InsetCollapsable::edit(LCursor & cur, int x, int y)
InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y)
{
cur.push(this);
//lyxerr << "InsetCollapsable: edit xy" << endl;
@ -309,14 +309,14 @@ void InsetCollapsable::edit(LCursor & cur, int x, int y)
#warning look here
//we are not calling edit(x,y) because there are no coordinates in the
//inset yet. I personally think it's ok. (ab)
} else {
// if (y <= yo() + inset.ascent() + button_dim.y2)
// y = yo();
// else
// y += inset.ascent() - height_collapsed();
inset.edit(cur, x, y);
return this;
}
//if (y <= yo() + inset.ascent() + button_dim.y2)
// y = yo();
//else
// y += inset.ascent() - height_collapsed();
return inset.editXY(cur, x, y);
}

View File

@ -137,7 +137,7 @@ protected:
///
void edit(LCursor & cur, bool left);
///
void edit(LCursor & cur, int x, int y);
InsetBase * editXY(LCursor & cur, int x, int y);
private:
///

View File

@ -142,11 +142,12 @@ public:
///
InsetExternalParams const & params() const;
///
void setParams(InsetExternalParams const &, Buffer const &);
///
void addPreview(lyx::graphics::PreviewLoader &) const;
///
void edit(LCursor & cur, bool);
void edit(LCursor & cur, bool left);
protected:
///

View File

@ -78,12 +78,10 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
void edit(LCursor & cur, bool);
void edit(LCursor & cur, bool left);
protected:
///
virtual
DispatchResult
priv_dispatch(LCursor & cur, FuncRequest const & cmd);
DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
friend class InsetGraphicsMailer;

View File

@ -461,19 +461,18 @@ void InsetTabular::edit(LCursor & cur, bool left)
}
void InsetTabular::edit(LCursor & cur, int x, int y)
InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y)
{
lyxerr << "InsetTabular::edit: " << this << " first cell "
<< &tabular.cell_info[0][0].inset << endl;
finishUndo();
setPos(cur, x, y);
clearSelection();
finishUndo();
//int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
cur.push(this);
setPos(cur, x, y);
//int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
//if (x > xx)
// activateCellInset(bv, cell, x - xx, y - cursory_);
#warning wrong!
return this;
}
@ -977,7 +976,7 @@ void InsetTabular::setPos(LCursor & cur, int x, int y) const
//lyxerr << "# InsetTabular::setPos() cursor: " << cur << endl;
int const cell = getCell(x + xo_, y + yo_);
InsetText const & inset = tabular.getCellInset(cell);
inset.text_.setCursorFromCoordinates(cur.current(), x, y);
inset.text_.setCursorFromCoordinates(cur, x, y);
cursory_ = 0;
int actcell = 0;
int actrow = 0;
@ -1023,7 +1022,7 @@ int InsetTabular::getCellXPos(int cell) const
void InsetTabular::resetPos(LCursor & cur) const
{
#if 0
#if 1
#ifdef WITH_WARNINGS
#warning This should be fixed in the right manner (20011128 Jug)
#endif
@ -1033,7 +1032,7 @@ void InsetTabular::resetPos(LCursor & cur) const
BufferView & bv = cur.bv();
int cell = 0;
int actcell = cur.cell();
int actcell = cur.idx();
int actcol = tabular.column_of_cell(actcell);
int actrow = 0;
cursory_ = 0;
@ -1054,24 +1053,24 @@ void InsetTabular::resetPos(LCursor & cur) const
cursorx_ = new_x;
// cursor.x(getCellXPos(actcell) + offset);
if (actcol < tabular.columns() - 1 && scroll(false) &&
tabular.getWidthOfTabular() < bv->workWidth()-20)
tabular.getWidthOfTabular() < bv.workWidth()-20)
{
scroll(bv, 0.0F);
updateLocal(cur);
} else if (cursorx_ - offset > 20 &&
cursorx_ - offset + tabular.getWidthOfColumn(actcell)
> bv.workWidth() - 20) {
scroll(&bv, - tabular.getWidthOfColumn(actcell) - 20);
scroll(bv, - tabular.getWidthOfColumn(actcell) - 20);
updateLocal(cur);
} else if (cursorx_ - offset < 20) {
scroll(&bv, 20 - cursorx_ + offset);
scroll(bv, 20 - cursorx_ + offset);
updateLocal(cur);
} else if (scroll() && xo_ > 20 &&
xo_ + tabular.getWidthOfTabular() > bv->workWidth() - 20) {
scroll(&bv, old_x - cursorx_);
xo_ + tabular.getWidthOfTabular() > bv.workWidth() - 20) {
scroll(bv, old_x - cursorx_);
updateLocal(cur);
}
InsetTabularMailer(*this).updateDialog(bv);
InsetTabularMailer(*this).updateDialog(&bv);
in_reset_pos = 0;
#endif
}
@ -1595,16 +1594,16 @@ void InsetTabular::tabularFeatures(LCursor & cur,
void InsetTabular::activateCellInset(LCursor & cur, int cell, int x, int y)
{
tabular.getCellInset(cell).edit(cur, x, y);
cur.idx() = cell;
tabular.getCellInset(cell).editXY(cur, x, y);
updateLocal(cur);
}
void InsetTabular::activateCellInset(LCursor & cur, int cell, bool behind)
{
tabular.getCellInset(cell).edit(cur, behind);
cur.idx() = cell;
tabular.getCellInset(cell).edit(cur, behind);
updateLocal(cur);
}

View File

@ -147,9 +147,9 @@ public:
/// set the owning buffer
void buffer(Buffer * buf);
/// lock cell with given index
void edit(LCursor & cur, bool);
void edit(LCursor & cur, bool left);
///
void edit(LCursor & cur, int, int);
InsetBase * editXY(LCursor & cur, int x, int y);
/// can we go further down on mouse click?
bool descendable() const { return true; }
@ -160,9 +160,7 @@ public:
protected:
///
virtual
DispatchResult
priv_dispatch(LCursor & cur, FuncRequest const & cmd);
DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
void lfunMousePress(LCursor & cur, FuncRequest const & cmd);

View File

@ -298,11 +298,11 @@ void InsetText::edit(LCursor & cur, bool left)
}
void InsetText::edit(LCursor & cur, int x, int y)
InsetBase * InsetText::editXY(LCursor & cur, int x, int y)
{
lyxerr << "InsetText::edit xy" << endl;
old_par = -1;
text_.edit(cur, x, y);
return text_.editXY(cur, x, y);
//sanitizeEmptyText(cur.bv());
//updateLocal(cur);
//dispatch(cur, FuncRequest(LFUN_PARAGRAPH_UPDATE));

View File

@ -148,7 +148,7 @@ public:
///
void edit(LCursor & cur, bool left);
///
void edit(LCursor & cur, int x, int y);
InsetBase * editXY(LCursor & cur, int x, int y);
///
int numParagraphs() const { return 1; }

View File

@ -432,49 +432,6 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap
}
string const getPossibleLabel(BufferView const & bv)
{
ParagraphList::iterator pit = bv.getLyXText()->cursorPar();
ParagraphList & plist = bv.getLyXText()->paragraphs();
LyXLayout_ptr layout = pit->layout();
if (layout->latextype == LATEX_PARAGRAPH && pit != plist.begin()) {
ParagraphList::iterator pit2 = boost::prior(pit);
LyXLayout_ptr const & layout2 = pit2->layout();
if (layout2->latextype != LATEX_PARAGRAPH) {
pit = pit2;
layout = layout2;
}
}
string text = layout->latexname().substr(0, 3);
if (layout->latexname() == "theorem")
text = "thm"; // Create a correct prefix for prettyref
text += ':';
if (layout->latextype == LATEX_PARAGRAPH ||
lyxrc.label_init_length < 0)
text.erase();
string par_text = pit->asString(*bv.buffer(), false);
for (int i = 0; i < lyxrc.label_init_length; ++i) {
if (par_text.empty())
break;
string head;
par_text = split(par_text, head, ' ');
// Is it legal to use spaces in labels ?
if (i > 0)
text += '-';
text += head;
}
return text;
}
// This function runs "configure" and then rereads lyx.defaults to
// reconfigure the automatic settings.
void Reconfigure(BufferView * bv)

View File

@ -35,7 +35,5 @@ void InsertAsciiFile(BufferView * bv, std::string const & f, bool asParagraph);
///
std::string getContentsOfAsciiFile(BufferView * bv, std::string const & f, bool asParagraph);
///
std::string const getPossibleLabel(BufferView const & bv);
///
void Reconfigure(BufferView * bv);
#endif

View File

@ -19,77 +19,6 @@
using lyx::pos_type;
using std::max;
using std::min;
using std::endl;
int numberOfSeparators(Paragraph const & par, Row const & row)
{
pos_type const first = max(row.pos(), par.beginOfBody());
pos_type const last = row.endpos() - 1;
int n = 0;
for (pos_type p = first; p < last; ++p) {
if (par.isSeparator(p))
++n;
}
return n;
}
// This is called _once_ from LyXText and should at least be moved into
// an anonymous namespace there. (Lgb)
int numberOfHfills(Paragraph const & par, Row const & row)
{
pos_type const last = row.endpos() - 1;
pos_type first = row.pos();
// hfill *DO* count at the beginning of paragraphs!
if (first) {
while (first < last && par.isHfill(first))
++first;
}
first = max(first, par.beginOfBody());
int n = 0;
// last, because the end is ignored!
for (pos_type p = first; p < last; ++p) {
if (par.isHfill(p))
++n;
}
return n;
}
// This is called _once_ from LyXText and should at least be moved into
// an anonymous namespace there. (Lgb)
int numberOfLabelHfills(Paragraph const & par, Row const & row)
{
pos_type last = row.endpos() - 1;
pos_type first = row.pos();
// hfill *DO* count at the beginning of paragraphs!
if (first) {
while (first < last && par.isHfill(first))
++first;
}
last = min(last, par.beginOfBody());
int n = 0;
// last, because the end is ignored
for (pos_type p = first; p < last; ++p) {
if (par.isHfill(p))
++n;
}
return n;
}
bool hfillExpansion(Paragraph const & par, Row const & row, pos_type pos)
{

View File

@ -18,12 +18,6 @@
class Paragraph;
class Row;
int numberOfSeparators(Paragraph const & par, Row const & row);
int numberOfHfills(Paragraph const & par, Row const & row);
int numberOfLabelHfills(Paragraph const & par, Row const & row);
bool hfillExpansion(Paragraph const & par, Row const & row,
lyx::pos_type pos);

View File

@ -187,9 +187,9 @@ public:
///
void recUndo(par_type first) const;
///
void setCursorFromCoordinates(CursorSlice &, int x, int y);
void setCursorFromCoordinates(LCursor & cur, int x, int y);
///
void edit(LCursor & cur, int x, int y);
InsetBase * editXY(LCursor & cur, int x, int y);
///
void cursorUp(LCursor & cur, bool selecting = false);
///
@ -339,7 +339,9 @@ public:
bool isFirstRow(ParagraphList::iterator pit, Row const & row) const;
///
double spacing(Paragraph const &) const;
double spacing(Paragraph const & par) const;
/// make a suggestion for a label
std::string getPossibleLabel(LCursor & cur) const;
///
DispatchResult moveRight(LCursor & cur);
@ -431,7 +433,9 @@ private:
void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
/// delete double space (false) or empty paragraphs (true) around old_cursor
bool deleteEmptyParagraphMechanism(CursorSlice const & old_cursor);
bool deleteEmptyParagraphMechanism(
CursorSlice & cur,
CursorSlice const & old_cursor);
///
void setCounter(Buffer const &, ParagraphList::iterator pit);

View File

@ -993,7 +993,6 @@ void MathHullInset::insetUnlock(BufferView & bv)
if (bv.cursor().inMathed()) {
if (bv.cursor().inMacroMode())
bv.cursor().macroModeClose();
bv.cursor().releaseMathCursor();
}
if (bv.buffer())
generatePreview(*bv.buffer());

View File

@ -744,7 +744,6 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
revealCodes(cur);
cur.bv().stuffClipboard(cur.grabSelection());
} else {
cur.releaseMathCursor();
if (remove_inset)
cur.bv().owner()->dispatch(FuncRequest(LFUN_DELETE));
}
@ -767,7 +766,7 @@ void MathNestInset::edit(LCursor & cur, bool left)
}
void MathNestInset::edit(LCursor & cur, int x, int y)
InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y)
{
int idx_min = 0;
int dist_min = 1000000;
@ -787,8 +786,9 @@ void MathNestInset::edit(LCursor & cur, int x, int y)
// hit inside cell
for (pos_type i = 0, n = ar.size(); i < n; ++i)
if (ar[i]->covers(x, y))
ar[i].nucleus()->edit(cur, x, y);
return ar[i].nucleus()->editXY(cur, x, y);
}
return this;
}

View File

@ -43,7 +43,7 @@ public:
///
void edit(LCursor & cur, bool left);
///
void edit(LCursor & cur, int x, int y);
InsetBase * editXY(LCursor & cur, int x, int y);
/// order of movement through the cells when pressing the left key
bool idxLeft(LCursor &) const;

View File

@ -60,11 +60,13 @@ using lyx::word_location;
using lyx::support::bformat;
using lyx::support::contains;
using lyx::support::lowercase;
using lyx::support::split;
using lyx::support::uppercase;
using std::advance;
using std::distance;
using std::max;
using std::min;
using std::endl;
using std::string;
@ -79,6 +81,19 @@ extern int const RIGHT_MARGIN = 10;
namespace {
int numberOfSeparators(Paragraph const & par, Row const & row)
{
pos_type const first = max(row.pos(), par.beginOfBody());
pos_type const last = row.endpos() - 1;
int n = 0;
for (pos_type p = first; p < last; ++p) {
if (par.isSeparator(p))
++n;
}
return n;
}
unsigned int maxParagraphWidth(ParagraphList const & plist)
{
unsigned int width = 0;
@ -89,6 +104,49 @@ unsigned int maxParagraphWidth(ParagraphList const & plist)
return width;
}
int numberOfLabelHfills(Paragraph const & par, Row const & row)
{
pos_type last = row.endpos() - 1;
pos_type first = row.pos();
// hfill *DO* count at the beginning of paragraphs!
if (first) {
while (first < last && par.isHfill(first))
++first;
}
last = min(last, par.beginOfBody());
int n = 0;
for (pos_type p = first; p < last; ++p) {
if (par.isHfill(p))
++n;
}
return n;
}
int numberOfHfills(Paragraph const & par, Row const & row)
{
pos_type const last = row.endpos() - 1;
pos_type first = row.pos();
// hfill *DO* count at the beginning of paragraphs!
if (first) {
while (first < last && par.isHfill(first))
++first;
}
first = max(first, par.beginOfBody());
int n = 0;
for (pos_type p = first; p < last; ++p) {
if (par.isHfill(p))
++n;
}
return n;
}
} // namespace anon
@ -1955,3 +2013,46 @@ string LyXText::currentState(LCursor & cur)
#endif
return os.str();
}
string LyXText::getPossibleLabel(LCursor & cur) const
{
ParagraphList & plist = paragraphs();
ParagraphList::iterator pit = getPar(cur.par());
LyXLayout_ptr layout = pit->layout();
if (layout->latextype == LATEX_PARAGRAPH && pit != plist.begin()) {
ParagraphList::iterator pit2 = boost::prior(pit);
LyXLayout_ptr const & layout2 = pit2->layout();
if (layout2->latextype != LATEX_PARAGRAPH) {
pit = pit2;
layout = layout2;
}
}
string text = layout->latexname().substr(0, 3);
if (layout->latexname() == "theorem")
text = "thm"; // Create a correct prefix for prettyref
text += ':';
if (layout->latextype == LATEX_PARAGRAPH ||
lyxrc.label_init_length < 0)
text.erase();
string par_text = pit->asString(*cur.bv().buffer(), false);
for (int i = 0; i < lyxrc.label_init_length; ++i) {
if (par_text.empty())
break;
string head;
par_text = split(par_text, head, ' ');
// Is it legal to use spaces in labels ?
if (i > 0)
text += '-';
text += head;
}
return text;
}

View File

@ -292,7 +292,7 @@ void LyXText::setLayout(LCursor & cur, string const & layout)
bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
InsetBase * inset = new InsetEnvironment(params, layout);
insertInset(cur, inset);
//inset->edit(bv());
//inset->edit(cur, true);
//bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
return;
}
@ -1089,7 +1089,7 @@ bool LyXText::setCursor(LCursor & cur, par_type par, pos_type pos,
{
CursorSlice old_cursor = cur.current();
setCursorIntern(cur, par, pos, setfont, boundary);
return deleteEmptyParagraphMechanism(old_cursor);
return deleteEmptyParagraphMechanism(cur.current(), old_cursor);
}
@ -1298,23 +1298,24 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
// x,y are coordinates relative to this LyXText
void LyXText::setCursorFromCoordinates(CursorSlice & cur, int x, int y)
void LyXText::setCursorFromCoordinates(LCursor & cur, int x, int y)
{
CursorSlice old_cursor = cur;
CursorSlice old_cursor = cur.current();
ParagraphList::iterator pit;
Row const & row = *getRowNearY(y, pit);
lyxerr << "hit row at: " << row.pos() << endl;
bool bound = false;
int xx = x + xo_; // getRowNearX get absolute x coords
pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
cur.par() = parOffset(pit);
cur.pos() = pos;
cur.boundary() = bound;
deleteEmptyParagraphMechanism(old_cursor);
deleteEmptyParagraphMechanism(cur.current(), old_cursor);
}
// x,y are absolute screen coordinates
void LyXText::edit(LCursor & cur, int x, int y)
InsetBase * LyXText::editXY(LCursor & cur, int x, int y)
{
ParagraphList::iterator pit;
Row const & row = *getRowNearY(y - yo_, pit);
@ -1328,17 +1329,18 @@ void LyXText::edit(LCursor & cur, int x, int y)
// try to descend into nested insets
InsetBase * inset = checkInsetHit(x, y);
if (inset) {
// This should be just before or just behind the
// cursor position set above.
BOOST_ASSERT((pos != 0 && inset == pit->getInset(pos - 1))
|| inset == pit->getInset(pos));
// Make sure the cursor points to the position before
// this inset.
if (inset == pit->getInset(pos - 1))
--cur.pos();
inset->edit(cur, x, y);
}
if (!inset)
return 0;
// This should be just before or just behind the
// cursor position set above.
BOOST_ASSERT((pos != 0 && inset == pit->getInset(pos - 1))
|| inset == pit->getInset(pos));
// Make sure the cursor points to the position before
// this inset.
if (inset == pit->getInset(pos - 1))
--cur.pos();
return inset->editXY(cur, x, y);
}
@ -1433,7 +1435,7 @@ bool LyXText::cursorLeft(LCursor & cur, bool internal)
if (cur.par() != 0) {
// steps into the paragraph above
setCursor(cur, cur.par() - 1, boost::prior(cursorPar())->size());
setCursor(cur, cur.par() - 1, getPar(cur.par() - 1)->size());
return true;
}
@ -1470,12 +1472,12 @@ void LyXText::cursorUp(LCursor & cur, bool selecting)
Row const & row = cur.textRow();
int x = cur.x_target();
int y = cursorY(cur.current()) - row.baseline() - 1;
setCursorFromCoordinates(cur.current(), x - xo_, y - yo_);
setCursorFromCoordinates(cur, x - xo_, y - yo_);
if (!selecting) {
InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
if (inset_hit && isHighlyEditableInset(inset_hit))
inset_hit->edit(cur, cur.x_target(), y);
inset_hit->editXY(cur, cur.x_target(), y);
}
}
@ -1485,12 +1487,12 @@ void LyXText::cursorDown(LCursor & cur, bool selecting)
Row const & row = cur.textRow();
int x = cur.x_target();
int y = cursorY(cur.current()) - row.baseline() + row.height() + 1;
setCursorFromCoordinates(cur.current(), x - xo_, y - yo_);
setCursorFromCoordinates(cur, x - xo_, y - yo_);
if (!selecting) {
InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
if (inset_hit && isHighlyEditableInset(inset_hit))
inset_hit->edit(cur, cur.x_target(), y);
inset_hit->editXY(cur, cur.x_target(), y);
}
}
@ -1517,13 +1519,12 @@ void LyXText::cursorDownParagraph(LCursor & cur)
// position. Called by deleteEmptyParagraphMechanism
void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where)
{
// if cursor is not in the paragraph where the delete occured,
// do nothing
// do notheing if cursor is not in the paragraph where the
// deletion occured,
if (cur.par() != where.par())
return;
// if cursor position is after the place where the delete occured,
// update it
// if cursor position is after the deletion place update it
if (cur.pos() > where.pos())
--cur.pos();
@ -1534,22 +1535,19 @@ void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where)
}
bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor)
bool LyXText::deleteEmptyParagraphMechanism(CursorSlice & cur,
CursorSlice const & old_cursor)
{
#warning Disabled as it crashes after the cursor data shift... (Andre)
return false;
// Would be wrong to delete anything if we have a selection.
if (bv()->cursor().selection())
return false;
// Don't do anything if the cursor is invalid
if (old_cursor.par() == -1)
return false;
//if (cur.selection())
// return false;
#if 0
// We allow all kinds of "mumbo-jumbo" when freespacing.
ParagraphList::iterator const old_pit = getPar(old_cursor);
ParagraphList::iterator const old_pit = getPar(old_cursor.par());
if (old_pit->isFreeSpacing())
return false;
@ -1577,8 +1575,7 @@ bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor)
// MISSING
// If the pos around the old_cursor were spaces, delete one of them.
if (old_cursor.par() != cursor().par()
|| old_cursor.pos() != cursor().pos()) {
if (old_cursor.par() != cur.par() || old_cursor.pos() != cur.pos()) {
// Only if the cursor has really moved
if (old_cursor.pos() > 0
@ -1612,7 +1609,7 @@ bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor)
return false;
// only do our magic if we changed paragraph
if (old_cursor.par() == cursor().par())
if (old_cursor.par() == cur.par())
return false;
// record if we have deleted a paragraph
@ -1640,12 +1637,10 @@ bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor)
recUndo(parOffset(old_pit), parOffset(endpit) - 1);
cursor() = tmpcursor;
// cache cursor pit
ParagraphList::iterator tmppit = cursorPar();
// delete old par
paragraphs().erase(old_pit);
// update cursor par offset
cursor().par(parOffset(tmppit));
--cur.par();
redoParagraph();
if (selection_position_was_oldcursor_position) {

View File

@ -293,7 +293,7 @@ void LyXText::cursorPrevious(LCursor & cur)
int x = cur.x_target();
int y = bv()->top_y();
setCursorFromCoordinates(cur.current(), x, y);
setCursorFromCoordinates(cur, x, y);
if (cpar == cur.par() && cpos == cur.pos()) {
// we have a row which is taller than the workarea. The
@ -313,7 +313,7 @@ void LyXText::cursorNext(LCursor & cur)
int x = cur.x_target();
int y = bv()->top_y() + bv()->workHeight();
setCursorFromCoordinates(cur.current(), x, y);
setCursorFromCoordinates(cur, x, y);
if (cpar == cur.par() && cpos == cur.pos()) {
// we have a row which is taller than the workarea. The
@ -910,7 +910,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
lyxerr << "SETXY: Could not parse coordinates in '"
<< cmd.argument << std::endl;
else
setCursorFromCoordinates(cur.current(), x, y);
setCursorFromCoordinates(cur, x, y);
break;
}
@ -1092,7 +1092,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
break;
}
CursorSlice old = cur.current();
setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
setCursorFromCoordinates(cur, cmd.x, cmd.y);
// This is to allow jumping over large insets
// FIXME: shouldn't be top-text-specific
@ -1147,8 +1147,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
// Clear the selection
cur.clearSelection();
setCursorFromCoordinates(cur.current(), cmd.x - xo_,
cmd.y - yo_);
setCursorFromCoordinates(cur, cmd.x - xo_, cmd.y - yo_);
cur.resetAnchor();
finishUndo();
cur.x_target() = cursorX(cur.current());