mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-25 17:44:59 +00:00
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:
parent
a377c00fbe
commit
b56204339c
@ -33,12 +33,15 @@
|
|||||||
#include "support/FileInfo.h"
|
#include "support/FileInfo.h"
|
||||||
#include "support/filetools.h"
|
#include "support/filetools.h"
|
||||||
#include "support/lyxfunctional.h" //equal_1st_in_pair
|
#include "support/lyxfunctional.h" //equal_1st_in_pair
|
||||||
|
#include "support/types.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
extern BufferList bufferlist;
|
extern BufferList bufferlist;
|
||||||
|
|
||||||
|
using lyx::pos_type;
|
||||||
|
|
||||||
using std::pair;
|
using std::pair;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::ifstream;
|
using std::ifstream;
|
||||||
@ -106,34 +109,42 @@ bool BufferView::insertLyXFile(string const & filen)
|
|||||||
bool BufferView::removeAutoInsets()
|
bool BufferView::removeAutoInsets()
|
||||||
{
|
{
|
||||||
LyXCursor tmpcursor = text->cursor;
|
LyXCursor tmpcursor = text->cursor;
|
||||||
LyXCursor cursor;
|
Paragraph * cur_par = tmpcursor.par();
|
||||||
|
pos_type cur_pos = tmpcursor.pos();
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
|
ParIterator it = buffer()->par_iterator_begin();
|
||||||
ParIterator end = buffer()->par_iterator_end();
|
ParIterator end = buffer()->par_iterator_end();
|
||||||
for (ParIterator it = buffer()->par_iterator_begin();
|
for (; it != end; ++it) {
|
||||||
it != end; ++it) {
|
|
||||||
Paragraph * par = *it;
|
Paragraph * par = *it;
|
||||||
// this has to be done before the delete
|
bool removed = false;
|
||||||
if (par->autoDeleteInsets()) {
|
|
||||||
|
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;
|
found = true;
|
||||||
#ifdef WITH_WARNINGS
|
text->redoParagraph(this);
|
||||||
#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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// avoid forbidden cursor positions caused by error removing
|
text->setCursorIntern(this, cur_par, cur_pos);
|
||||||
if (tmpcursor.pos() > tmpcursor.par()->size())
|
|
||||||
tmpcursor.pos(tmpcursor.par()->size());
|
|
||||||
|
|
||||||
text->setCursorIntern(this, tmpcursor.par(), tmpcursor.pos());
|
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
@ -144,9 +155,9 @@ void BufferView::insertErrors(TeXErrors & terr)
|
|||||||
// Save the cursor position
|
// Save the cursor position
|
||||||
LyXCursor cursor = text->cursor;
|
LyXCursor cursor = text->cursor;
|
||||||
|
|
||||||
for (TeXErrors::Errors::const_iterator cit = terr.begin();
|
TeXErrors::Errors::const_iterator cit = terr.begin();
|
||||||
cit != terr.end();
|
TeXErrors::Errors::const_iterator end = terr.end();
|
||||||
++cit) {
|
for (; cit != end; ++cit) {
|
||||||
string const desctext(cit->error_desc);
|
string const desctext(cit->error_desc);
|
||||||
string const errortext(cit->error_text);
|
string const errortext(cit->error_text);
|
||||||
string const msgtxt = desctext + '\n' + errortext;
|
string const msgtxt = desctext + '\n' + errortext;
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
2001-12-28 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
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
|
* Makefile.am: added the new files to sources, removed layout.C
|
||||||
|
|
||||||
* layout.C: removed file
|
* layout.C: removed file
|
||||||
|
@ -1191,22 +1191,6 @@ Paragraph const * Paragraph::outerHook() const
|
|||||||
return depthHook(depth_type(getDepth() - 1));
|
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::inset_iterator
|
||||||
Paragraph::InsetIterator(pos_type pos)
|
Paragraph::InsetIterator(pos_type pos)
|
||||||
|
@ -311,9 +311,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void pasteParagraph(BufferParams const &);
|
void pasteParagraph(BufferParams const &);
|
||||||
|
|
||||||
/// used to remove the error messages
|
|
||||||
int autoDeleteInsets();
|
|
||||||
|
|
||||||
/// returns -1 if inset not found
|
/// returns -1 if inset not found
|
||||||
int getPositionOfInset(Inset const * inset) const;
|
int getPositionOfInset(Inset const * inset) const;
|
||||||
|
|
||||||
@ -370,6 +367,9 @@ public:
|
|||||||
}
|
}
|
||||||
///
|
///
|
||||||
Inset * operator*() { return it->inset; }
|
Inset * operator*() { return it->inset; }
|
||||||
|
///
|
||||||
|
Inset * operator->() { return it->inset; }
|
||||||
|
|
||||||
///
|
///
|
||||||
lyx::pos_type getPos() const { return it->pos; }
|
lyx::pos_type getPos() const { return it->pos; }
|
||||||
///
|
///
|
||||||
|
10
src/text.C
10
src/text.C
@ -245,11 +245,12 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par,
|
|||||||
// Returns the paragraph position of the last character in the specified row
|
// Returns the paragraph position of the last character in the specified row
|
||||||
pos_type LyXText::rowLast(Row const * row) const
|
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;
|
return row->par()->size() - 1;
|
||||||
else
|
} else {
|
||||||
return row->next()->pos() - 1;
|
return row->next()->pos() - 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pos_type LyXText::rowLastPrintable(Row const * row) const
|
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 const last = rowLast(row);
|
||||||
pos_type first = row->pos();
|
pos_type first = row->pos();
|
||||||
|
|
||||||
if (first) { /* hfill *DO* count at the beginning
|
if (first) { /* hfill *DO* count at the beginning
|
||||||
* of paragraphs! */
|
* of paragraphs! */
|
||||||
while (first <= last && row->par()->isHfill(first))
|
while (first <= last && row->par()->isHfill(first)) {
|
||||||
++first;
|
++first;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
first = max(first, beginningOfMainBody(buf, row->par()));
|
first = max(first, beginningOfMainBody(buf, row->par()));
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (pos_type p = first; p <= last; ++p) {
|
for (pos_type p = first; p <= last; ++p) {
|
||||||
// last, because the end is ignored!
|
// last, because the end is ignored!
|
||||||
|
|
||||||
if (row->par()->isHfill(p)) {
|
if (row->par()->isHfill(p)) {
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
|
11
src/text2.C
11
src/text2.C
@ -2103,6 +2103,9 @@ void LyXText::setCursor(BufferView * bview, Paragraph * par,
|
|||||||
void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
|
void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
|
||||||
pos_type pos, bool boundary) const
|
pos_type pos, bool boundary) const
|
||||||
{
|
{
|
||||||
|
lyx::Assert(par);
|
||||||
|
lyx::Assert(bview);
|
||||||
|
|
||||||
cur.par(par);
|
cur.par(par);
|
||||||
cur.pos(pos);
|
cur.pos(pos);
|
||||||
cur.boundary(boundary);
|
cur.boundary(boundary);
|
||||||
@ -2125,10 +2128,14 @@ void LyXText::setCursor(BufferView *bview, LyXCursor & cur, Paragraph * par,
|
|||||||
pos_type cursor_vpos = 0;
|
pos_type cursor_vpos = 0;
|
||||||
pos_type last = rowLastPrintable(row);
|
pos_type last = rowLastPrintable(row);
|
||||||
|
|
||||||
if (pos > last + 1) // This shouldn't happen.
|
if (pos > last + 1) {
|
||||||
|
// This shouldn't happen.
|
||||||
pos = last + 1;
|
pos = last + 1;
|
||||||
else if (pos < row->pos())
|
cur.pos(pos);
|
||||||
|
} else if (pos < row->pos()) {
|
||||||
pos = row->pos();
|
pos = row->pos();
|
||||||
|
cur.pos(pos);
|
||||||
|
}
|
||||||
|
|
||||||
if (last < row->pos())
|
if (last < row->pos())
|
||||||
cursor_vpos = row->pos();
|
cursor_vpos = row->pos();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user