#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;
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()) {
- 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);
+ 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;
+ 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;
}
// 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;
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
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)
*/
void pasteParagraph(BufferParams const &);
- /// used to remove the error messages
- int autoDeleteInsets();
-
/// returns -1 if inset not found
int getPositionOfInset(Inset const * inset) const;
}
///
Inset * operator*() { return it->inset; }
+ ///
+ Inset * operator->() { return it->inset; }
+
///
lyx::pos_type getPos() const { return it->pos; }
///
// 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 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;
}
}
-void LyXText::setCursor(BufferView *bview, LyXCursor & cur, 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);
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();
else if (pos > last && !boundary)