2001-12-28 Lars Gullik Bj�nnes <larsbj@birdstep.com>

text2.C (setCursor): add a couple of asserts.

paragraph.h (inset_iterator): add -> operator

paragraph.[Ch] (autoDeleteInsets): remove member function

BufferView2.C (removeAutoInsets): rewrite to handle the old
pos correctly and handle inset deletion by itself.
sertErrors): move iterator declaration out of for expression


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3271 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-12-28 21:17:18 +00:00
parent a377c00fbe
commit b56204339c
6 changed files with 67 additions and 49 deletions

View File

@ -33,12 +33,15 @@
#include "support/FileInfo.h"
#include "support/filetools.h"
#include "support/lyxfunctional.h" //equal_1st_in_pair
#include "support/types.h"
#include <fstream>
#include <algorithm>
extern BufferList bufferlist;
using lyx::pos_type;
using std::pair;
using std::endl;
using std::ifstream;
@ -106,34 +109,42 @@ bool BufferView::insertLyXFile(string const & filen)
bool BufferView::removeAutoInsets()
{
LyXCursor tmpcursor = text->cursor;
LyXCursor cursor;
Paragraph * cur_par = tmpcursor.par();
pos_type cur_pos = tmpcursor.pos();
bool found = false;
ParIterator it = buffer()->par_iterator_begin();
ParIterator end = buffer()->par_iterator_end();
for (ParIterator it = buffer()->par_iterator_begin();
it != end; ++it) {
for (; it != end; ++it) {
Paragraph * par = *it;
// this has to be done before the delete
if (par->autoDeleteInsets()) {
bool removed = false;
text->setCursor(this, par, 0);
Paragraph::inset_iterator pit = par->inset_iterator_begin();
Paragraph::inset_iterator pend = par->inset_iterator_end();
while (pit != pend) {
if (pit->autoDelete()) {
removed = true;
pos_type const pos = pit.getPos();
par->erase(pos);
if (cur_par == par) {
if (cur_pos > pos)
--cur_pos;
}
} else {
++pit;
}
}
if (removed) {
found = true;
#ifdef WITH_WARNINGS
#warning FIXME
#endif
// The test it.size()==1 was needed to prevent crashes.
if (it.size() == 1) {
text->setCursor(this, cursor, par, 0);
text->redoParagraphs(this, cursor,
cursor.par()->next());
text->fullRebreak(this);
}
text->redoParagraph(this);
}
}
// avoid forbidden cursor positions caused by error removing
if (tmpcursor.pos() > tmpcursor.par()->size())
tmpcursor.pos(tmpcursor.par()->size());
text->setCursorIntern(this, tmpcursor.par(), tmpcursor.pos());
text->setCursorIntern(this, cur_par, cur_pos);
return found;
}
@ -144,9 +155,9 @@ void BufferView::insertErrors(TeXErrors & terr)
// Save the cursor position
LyXCursor cursor = text->cursor;
for (TeXErrors::Errors::const_iterator cit = terr.begin();
cit != terr.end();
++cit) {
TeXErrors::Errors::const_iterator cit = terr.begin();
TeXErrors::Errors::const_iterator end = terr.end();
for (; cit != end; ++cit) {
string const desctext(cit->error_desc);
string const errortext(cit->error_text);
string const msgtxt = desctext + '\n' + errortext;

View File

@ -1,5 +1,17 @@
2001-12-28 Lars Gullik Bjønnes <larsbj@birdstep.com>
* text2.C (setCursor): add a couple of asserts.
* paragraph.h (inset_iterator): add -> operator
* paragraph.[Ch] (autoDeleteInsets): remove member function
* BufferView2.C (removeAutoInsets): rewrite to handle the old
cursor pos correctly and handle inset deletion by itself.
(insertErrors): move iterator declaration out of for expression
* lyxtextclass.C: add <algorithm>
* Makefile.am: added the new files to sources, removed layout.C
* layout.C: removed file

View File

@ -1191,22 +1191,6 @@ Paragraph const * Paragraph::outerHook() const
return depthHook(depth_type(getDepth() - 1));
}
int Paragraph::autoDeleteInsets()
{
int count = 0;
InsetList::size_type index = 0;
while (index < insetlist.size()) {
if (insetlist[index].inset && insetlist[index].inset->autoDelete()) {
erase(insetlist[index].pos);
// erase() calls to insetlist.erase(&insetlist[index])
// so index shouldn't be increased.
++count;
} else
++index;
}
return count;
}
Paragraph::inset_iterator
Paragraph::InsetIterator(pos_type pos)

View File

@ -311,9 +311,6 @@ public:
*/
void pasteParagraph(BufferParams const &);
/// used to remove the error messages
int autoDeleteInsets();
/// returns -1 if inset not found
int getPositionOfInset(Inset const * inset) const;
@ -370,6 +367,9 @@ public:
}
///
Inset * operator*() { return it->inset; }
///
Inset * operator->() { return it->inset; }
///
lyx::pos_type getPos() const { return it->pos; }
///

View File

@ -245,11 +245,12 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par,
// Returns the paragraph position of the last character in the specified row
pos_type LyXText::rowLast(Row const * row) const
{
if (!row->next() || row->next()->par() != row->par())
if (!row->next() || row->next()->par() != row->par()) {
return row->par()->size() - 1;
else
} else {
return row->next()->pos() - 1;
}
}
pos_type LyXText::rowLastPrintable(Row const * row) const
@ -1134,16 +1135,19 @@ int LyXText::numberOfHfills(Buffer const * buf, Row const * row) const
{
pos_type const last = rowLast(row);
pos_type first = row->pos();
if (first) { /* hfill *DO* count at the beginning
* of paragraphs! */
while (first <= last && row->par()->isHfill(first))
while (first <= last && row->par()->isHfill(first)) {
++first;
}
}
first = max(first, beginningOfMainBody(buf, row->par()));
int n = 0;
for (pos_type p = first; p <= last; ++p) {
// last, because the end is ignored!
if (row->par()->isHfill(p)) {
++n;
}

View File

@ -2103,6 +2103,9 @@ void LyXText::setCursor(BufferView * bview, Paragraph * par,
void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
pos_type pos, bool boundary) const
{
lyx::Assert(par);
lyx::Assert(bview);
cur.par(par);
cur.pos(pos);
cur.boundary(boundary);
@ -2125,10 +2128,14 @@ void LyXText::setCursor(BufferView *bview, LyXCursor & cur, Paragraph * par,
pos_type cursor_vpos = 0;
pos_type last = rowLastPrintable(row);
if (pos > last + 1) // This shouldn't happen.
if (pos > last + 1) {
// This shouldn't happen.
pos = last + 1;
else if (pos < row->pos())
cur.pos(pos);
} else if (pos < row->pos()) {
pos = row->pos();
cur.pos(pos);
}
if (last < row->pos())
cursor_vpos = row->pos();