mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 13:48:59 +00:00
more privacy for CursorSlice members
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8505 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
7892c861f9
commit
bddfd8ff66
26
src/cursor.C
26
src/cursor.C
@ -67,12 +67,12 @@ void region(CursorSlice const & i1, CursorSlice const & i2,
|
|||||||
LCursor::col_type & c1, LCursor::col_type & c2)
|
LCursor::col_type & c1, LCursor::col_type & c2)
|
||||||
{
|
{
|
||||||
InsetBase & p = i1.inset();
|
InsetBase & p = i1.inset();
|
||||||
c1 = p.col(i1.idx_);
|
c1 = p.col(i1.idx());
|
||||||
c2 = p.col(i2.idx_);
|
c2 = p.col(i2.idx());
|
||||||
if (c1 > c2)
|
if (c1 > c2)
|
||||||
swap(c1, c2);
|
swap(c1, c2);
|
||||||
r1 = p.row(i1.idx_);
|
r1 = p.row(i1.idx());
|
||||||
r2 = p.row(i2.idx_);
|
r2 = p.row(i2.idx());
|
||||||
if (r1 > r2)
|
if (r1 > r2)
|
||||||
swap(r1, r2);
|
swap(r1, r2);
|
||||||
}
|
}
|
||||||
@ -418,10 +418,10 @@ string LCursor::grabSelection()
|
|||||||
CursorSlice i1 = selBegin();
|
CursorSlice i1 = selBegin();
|
||||||
CursorSlice i2 = selEnd();
|
CursorSlice i2 = selEnd();
|
||||||
|
|
||||||
if (i1.idx_ == i2.idx_) {
|
if (i1.idx() == i2.idx()) {
|
||||||
if (i1.inset().asMathInset()) {
|
if (i1.inset().asMathInset()) {
|
||||||
MathArray::const_iterator it = i1.cell().begin();
|
MathArray::const_iterator it = i1.cell().begin();
|
||||||
return asString(MathArray(it + i1.pos_, it + i2.pos_));
|
return asString(MathArray(it + i1.pos(), it + i2.pos()));
|
||||||
} else {
|
} else {
|
||||||
return "unknown selection 1";
|
return "unknown selection 1";
|
||||||
}
|
}
|
||||||
@ -456,8 +456,8 @@ void LCursor::eraseSelection()
|
|||||||
CursorSlice const & i2 = selEnd();
|
CursorSlice const & i2 = selEnd();
|
||||||
#warning FIXME
|
#warning FIXME
|
||||||
if (i1.inset().asMathInset()) {
|
if (i1.inset().asMathInset()) {
|
||||||
if (i1.idx_ == i2.idx_) {
|
if (i1.idx() == i2.idx()) {
|
||||||
i1.cell().erase(i1.pos_, i2.pos_);
|
i1.cell().erase(i1.pos(), i2.pos());
|
||||||
} else {
|
} else {
|
||||||
MathInset * p = i1.asMathInset();
|
MathInset * p = i1.asMathInset();
|
||||||
row_type r1, r2;
|
row_type r1, r2;
|
||||||
@ -895,8 +895,8 @@ void LCursor::adjust(pos_type from, int diff)
|
|||||||
{
|
{
|
||||||
if (pos() > from)
|
if (pos() > from)
|
||||||
pos() += diff;
|
pos() += diff;
|
||||||
if (anchor().pos_ > from)
|
if (anchor().pos() > from)
|
||||||
anchor().pos_ += diff;
|
anchor().pos() += diff;
|
||||||
// just to be on the safe side
|
// just to be on the safe side
|
||||||
// theoretically unecessary
|
// theoretically unecessary
|
||||||
normalize();
|
normalize();
|
||||||
@ -932,7 +932,7 @@ MathGridInset * LCursor::enclosingGrid(idx_type & idx) const
|
|||||||
return 0;
|
return 0;
|
||||||
MathGridInset * p = m->asGridInset();
|
MathGridInset * p = m->asGridInset();
|
||||||
if (p) {
|
if (p) {
|
||||||
idx = operator[](i).idx_;
|
idx = operator[](i).idx();
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1100,7 +1100,7 @@ bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
|
|||||||
BOOST_ASSERT(text);
|
BOOST_ASSERT(text);
|
||||||
getParsInRange(text->paragraphs(), ylow, yhigh, beg, end);
|
getParsInRange(text->paragraphs(), ylow, yhigh, beg, end);
|
||||||
|
|
||||||
DocumentIterator it = insetBegin(bv().buffer()->inset());
|
DocumentIterator it(bv().buffer()->inset());
|
||||||
DocumentIterator et;
|
DocumentIterator et;
|
||||||
lyxerr << "x: " << x << " y: " << y << endl;
|
lyxerr << "x: " << x << " y: " << y << endl;
|
||||||
lyxerr << "xlow: " << xlow << " ylow: " << ylow << endl;
|
lyxerr << "xlow: " << xlow << " ylow: " << ylow << endl;
|
||||||
@ -1146,7 +1146,7 @@ void LCursor::bruteFind2(int x, int y)
|
|||||||
DocumentIterator it = *this;
|
DocumentIterator it = *this;
|
||||||
it.back().pos() = 0;
|
it.back().pos() = 0;
|
||||||
DocumentIterator et = *this;
|
DocumentIterator et = *this;
|
||||||
et.back().pos() = et.back().asMathInset()->cell(et.back().idx_).size();
|
et.back().pos() = et.back().asMathInset()->cell(et.back().idx()).size();
|
||||||
for (int i = 0; ; ++i) {
|
for (int i = 0; ; ++i) {
|
||||||
int xo, yo;
|
int xo, yo;
|
||||||
CursorSlice & cur = it.back();
|
CursorSlice & cur = it.back();
|
||||||
|
@ -37,7 +37,7 @@ CursorSlice::CursorSlice()
|
|||||||
CursorSlice::CursorSlice(InsetBase & p)
|
CursorSlice::CursorSlice(InsetBase & p)
|
||||||
: inset_(&p), idx_(0), par_(0), pos_(0), boundary_(false)
|
: inset_(&p), idx_(0), par_(0), pos_(0), boundary_(false)
|
||||||
{
|
{
|
||||||
///BOOST_ASSERT(inset_);
|
BOOST_ASSERT(inset_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -177,34 +177,34 @@ Paragraph const & CursorSlice::paragraph() const
|
|||||||
|
|
||||||
bool operator==(CursorSlice const & p, CursorSlice const & q)
|
bool operator==(CursorSlice const & p, CursorSlice const & q)
|
||||||
{
|
{
|
||||||
return p.inset_ == q.inset_
|
return &p.inset() == &q.inset()
|
||||||
&& p.idx_ == q.idx_
|
&& p.idx() == q.idx()
|
||||||
&& p.par_ == q.par_
|
&& p.par() == q.par()
|
||||||
&& p.pos_ == q.pos_;
|
&& p.pos() == q.pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool operator!=(CursorSlice const & p, CursorSlice const & q)
|
bool operator!=(CursorSlice const & p, CursorSlice const & q)
|
||||||
{
|
{
|
||||||
return p.inset_ != q.inset_
|
return &p.inset() != &q.inset()
|
||||||
|| p.idx_ != q.idx_
|
|| p.idx() != q.idx()
|
||||||
|| p.par_ != q.par_
|
|| p.par() != q.par()
|
||||||
|| p.pos_ != q.pos_;
|
|| p.pos() != q.pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool operator<(CursorSlice const & p, CursorSlice const & q)
|
bool operator<(CursorSlice const & p, CursorSlice const & q)
|
||||||
{
|
{
|
||||||
if (p.inset_ != q.inset_) {
|
if (&p.inset() != &q.inset()) {
|
||||||
lyxerr << "can't compare cursor and anchor in different insets\n"
|
lyxerr << "can't compare cursor and anchor in different insets\n"
|
||||||
<< "p: " << p << '\n' << "q: " << q << endl;
|
<< "p: " << p << '\n' << "q: " << q << endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (p.idx_ != q.idx_)
|
if (p.idx() != q.idx())
|
||||||
return p.idx_ < q.idx_;
|
return p.idx() < q.idx();
|
||||||
if (p.par_ != q.par_)
|
if (p.par() != q.par())
|
||||||
return p.par_ < q.par_;
|
return p.par() < q.par();
|
||||||
return p.pos_ < q.pos_;
|
return p.pos() < q.pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -217,12 +217,12 @@ bool operator>(CursorSlice const & p, CursorSlice const & q)
|
|||||||
std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
|
std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
|
||||||
{
|
{
|
||||||
return os
|
return os
|
||||||
<< "inset: " << item.inset_
|
<< "inset: " << &item.inset()
|
||||||
// << " text: " << item.text()
|
// << " text: " << item.text()
|
||||||
<< " idx: " << item.idx_
|
<< " idx: " << item.idx()
|
||||||
<< " par: " << item.par_
|
<< " par: " << item.par()
|
||||||
<< " pos: " << item.pos_
|
<< " pos: " << item.pos()
|
||||||
// << " x: " << item.inset_->x()
|
// << " x: " << item.inset().x()
|
||||||
// << " y: " << item.inset_->y()
|
// << " y: " << item.inset().y()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,13 @@
|
|||||||
#ifndef CURSORSLICE_H
|
#ifndef CURSORSLICE_H
|
||||||
#define CURSORSLICE_H
|
#define CURSORSLICE_H
|
||||||
|
|
||||||
#include <cstddef>
|
#include "ParagraphList_fwd.h"
|
||||||
#include <iosfwd>
|
|
||||||
|
|
||||||
#include "support/types.h"
|
#include "support/types.h"
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <iosfwd>
|
||||||
|
|
||||||
class BufferView;
|
class BufferView;
|
||||||
class InsetBase;
|
class InsetBase;
|
||||||
class MathInset;
|
class MathInset;
|
||||||
@ -66,8 +68,12 @@ public:
|
|||||||
idx_type lastidx() const { return nargs() - 1; }
|
idx_type lastidx() const { return nargs() - 1; }
|
||||||
/// return the paragraph this cursor is in
|
/// return the paragraph this cursor is in
|
||||||
par_type par() const;
|
par_type par() const;
|
||||||
/// return the paragraph this cursor is in
|
/// set the paragraph this cursor is in
|
||||||
par_type & par();
|
par_type & par();
|
||||||
|
/// increments the paragraph this cursor is in
|
||||||
|
void incrementPar();
|
||||||
|
/// increments the paragraph this cursor is in
|
||||||
|
void decrementPar();
|
||||||
/// return the position within the paragraph
|
/// return the position within the paragraph
|
||||||
pos_type pos() const;
|
pos_type pos() const;
|
||||||
/// return the position within the paragraph
|
/// return the position within the paragraph
|
||||||
@ -112,12 +118,15 @@ public:
|
|||||||
///
|
///
|
||||||
friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
|
friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
|
||||||
public:
|
public:
|
||||||
/// pointer to 'owning' inset
|
/// pointer to 'owning' inset. This is some kind of cache.
|
||||||
InsetBase * inset_;
|
InsetBase * inset_;
|
||||||
|
private:
|
||||||
/// cell index of a position in this inset
|
/// cell index of a position in this inset
|
||||||
idx_type idx_;
|
idx_type idx_;
|
||||||
/// paragraph in this cell (used by texted)
|
/// paragraph in this cell (used by texted)
|
||||||
par_type par_;
|
par_type par_;
|
||||||
|
/// true of 'pit' was properly initialized
|
||||||
|
bool pit_valid_;
|
||||||
/// position in this cell
|
/// position in this cell
|
||||||
pos_type pos_;
|
pos_type pos_;
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +12,16 @@
|
|||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
DocumentIterator::DocumentIterator()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
DocumentIterator::DocumentIterator(InsetBase & inset)
|
||||||
|
{
|
||||||
|
push_back(CursorSlice(inset));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
InsetBase * DocumentIterator::nextInset()
|
InsetBase * DocumentIterator::nextInset()
|
||||||
{
|
{
|
||||||
if (pos() == lastpos())
|
if (pos() == lastpos())
|
||||||
@ -270,7 +280,7 @@ void DocumentIterator::forwardPos()
|
|||||||
pop_back();
|
pop_back();
|
||||||
// 'top' is invalid now...
|
// 'top' is invalid now...
|
||||||
if (size())
|
if (size())
|
||||||
++back().pos_;
|
++back().pos();
|
||||||
//else
|
//else
|
||||||
// lyxerr << "... no slice left" << std::endl;
|
// lyxerr << "... no slice left" << std::endl;
|
||||||
}
|
}
|
||||||
@ -332,21 +342,7 @@ void DocumentIterator::forwardPar()
|
|||||||
pop_back();
|
pop_back();
|
||||||
// 'top' is invalid now...
|
// 'top' is invalid now...
|
||||||
if (size())
|
if (size())
|
||||||
++back().pos_;
|
++back().pos();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DocumentIterator insetBegin(InsetBase & inset)
|
|
||||||
{
|
|
||||||
DocumentIterator it;
|
|
||||||
it.push_back(CursorSlice(inset));
|
|
||||||
return it;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DocumentIterator insetEnd()
|
|
||||||
{
|
|
||||||
return DocumentIterator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,6 +49,11 @@ public:
|
|||||||
typedef CursorSlice::col_type col_type;
|
typedef CursorSlice::col_type col_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
///
|
||||||
|
DocumentIterator();
|
||||||
|
///
|
||||||
|
explicit DocumentIterator(InsetBase & inset);
|
||||||
|
|
||||||
//
|
//
|
||||||
// access to slice at tip
|
// access to slice at tip
|
||||||
//
|
//
|
||||||
@ -164,12 +169,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
///
|
|
||||||
DocumentIterator insetBegin(InsetBase & inset);
|
|
||||||
///
|
|
||||||
DocumentIterator insetEnd();
|
|
||||||
|
|
||||||
|
|
||||||
// The difference to a ('non stable') DocumentIterator is the removed
|
// The difference to a ('non stable') DocumentIterator is the removed
|
||||||
// (overwritte by 0...) part of the CursorSlice data items. So this thing
|
// (overwritte by 0...) part of the CursorSlice data items. So this thing
|
||||||
// is suitable for external storage, but not for iteration as such.
|
// is suitable for external storage, but not for iteration as such.
|
||||||
|
@ -695,6 +695,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_QUIT:
|
case LFUN_QUIT:
|
||||||
|
#if 0
|
||||||
|
// test speed of DocumentIterator
|
||||||
|
lyxerr << "start" << endl;
|
||||||
|
for (DocumentIterator it(owner->buffer()->inset()), end;
|
||||||
|
it != end; it.forwardPos())
|
||||||
|
;
|
||||||
|
lyxerr << "end" << endl;
|
||||||
|
#endif
|
||||||
QuitLyX();
|
QuitLyX();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
45
src/undo.C
45
src/undo.C
@ -32,9 +32,6 @@ using lyx::paroffset_type;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// Whether actions are not added to the undo stacks.
|
|
||||||
bool undo_frozen;
|
|
||||||
|
|
||||||
/// The flag used by finishUndo().
|
/// The flag used by finishUndo().
|
||||||
bool undo_finished;
|
bool undo_finished;
|
||||||
|
|
||||||
@ -153,32 +150,28 @@ bool textUndoOrRedo(BufferView & bv,
|
|||||||
finishUndo();
|
finishUndo();
|
||||||
|
|
||||||
// this implements redo
|
// this implements redo
|
||||||
if (!undo_frozen) {
|
otherstack.push(undo);
|
||||||
otherstack.push(undo);
|
DocumentIterator dit =
|
||||||
DocumentIterator dit =
|
undo.cursor.asDocumentIterator(&bv.buffer()->inset());
|
||||||
undo.cursor.asDocumentIterator(&bv.buffer()->inset());
|
if (dit.inMathed()) {
|
||||||
if (dit.inMathed()) {
|
// not much to be done
|
||||||
// not much to be done
|
} else {
|
||||||
} else {
|
otherstack.top().pars.clear();
|
||||||
otherstack.top().pars.clear();
|
LyXText * text = dit.text();
|
||||||
LyXText * text = dit.text();
|
BOOST_ASSERT(text);
|
||||||
BOOST_ASSERT(text);
|
ParagraphList & plist = text->paragraphs();
|
||||||
ParagraphList & plist = text->paragraphs();
|
if (undo.from + undo.end <= int(plist.size())) {
|
||||||
if (undo.from + undo.end <= int(plist.size())) {
|
ParagraphList::iterator first = plist.begin();
|
||||||
ParagraphList::iterator first = plist.begin();
|
advance(first, undo.from);
|
||||||
advance(first, undo.from);
|
ParagraphList::iterator last = plist.begin();
|
||||||
ParagraphList::iterator last = plist.begin();
|
advance(last, plist.size() - undo.end);
|
||||||
advance(last, plist.size() - undo.end);
|
otherstack.top().pars.insert(otherstack.top().pars.begin(), first, last);
|
||||||
otherstack.top().pars.insert(otherstack.top().pars.begin(), first, last);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
otherstack.top().cursor = bv.cursor();
|
|
||||||
//lyxerr << " undo other: " << otherstack.top() << std::endl;
|
|
||||||
}
|
}
|
||||||
|
otherstack.top().cursor = bv.cursor();
|
||||||
|
//lyxerr << " undo other: " << otherstack.top() << std::endl;
|
||||||
|
|
||||||
undo_frozen = true;
|
|
||||||
performUndoOrRedo(bv, undo);
|
performUndoOrRedo(bv, undo);
|
||||||
undo_frozen = false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,8 +202,6 @@ bool textRedo(BufferView & bv)
|
|||||||
void recordUndo(Undo::undo_kind kind,
|
void recordUndo(Undo::undo_kind kind,
|
||||||
LCursor & cur, paroffset_type first, paroffset_type last)
|
LCursor & cur, paroffset_type first, paroffset_type last)
|
||||||
{
|
{
|
||||||
if (undo_frozen)
|
|
||||||
return;
|
|
||||||
Buffer * buf = cur.bv().buffer();
|
Buffer * buf = cur.bv().buffer();
|
||||||
recordUndo(kind, cur, first, last, buf->undostack());
|
recordUndo(kind, cur, first, last, buf->undostack());
|
||||||
buf->redostack().clear();
|
buf->redostack().clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user