#include "lyxtext.h"
#include "LString.h"
#include "paragraph.h"
-#include "layout.h"
+#include "lyxtextclasslist.h"
#include "LyXView.h"
#include "undo_funcs.h"
#include "buffer.h"
if (!tmprow->previous()) {
// a trick/hack for UNDO
// This is needed because in an UNDO/REDO we could have changed
- // the firstParagrah() so the paragraph inside the row is NOT
+ // the ownerParagrah() so the paragraph inside the row is NOT
// my really first par anymore. Got it Lars ;) (Jug 20011206)
- first_phys_par = firstParagraph();
+ first_phys_par = ownerParagraph();
} else {
first_phys_par = tmprow->par();
while (tmprow->previous()
{
if (!cursor.par()->insetAllowed(inset->lyxCode()))
return;
- setUndo(bview, Undo::INSERT,
- cursor.par(), cursor.par()->next());
+ // I don't know if this is necessary here (Jug 20020102)
+ setUndo(bview, Undo::INSERT, cursor.par(), cursor.par()->next());
cursor.par()->insertInset(cursor.pos(), inset);
// Just to rebreak and refresh correctly.
// The character will not be inserted a second time
void LyXText::copySelection(BufferView * bview)
{
- // Stuff what we got on the clipboard. Even if there is no selection.
-
- // There is a problem with having the stuffing here in that the
- // larger the selection the slower LyX will get. This can be
- // solved by running the line below only when the selection has
- // finished. The solution used currently just works, to make it
- // faster we need to be more clever and probably also have more
- // calls to stuffClipboard. (Lgb)
+ // stuff the selection onto the X clipboard, from an explicit copy request
bview->stuffClipboard(selectionAsString(bview->buffer(), true));
// this doesnt make sense, if there is no selection
}
-// returns a pointer to the very first Paragraph
-Paragraph * LyXText::firstParagraph() const
-{
- return ownerParagraph();
-}
-
-
// sets the selection over the number of characters of string, no check!!
void LyXText::setSelectionOverString(BufferView * bview, string const & str)
{
// check every paragraph
- Paragraph * par = firstParagraph();
+ Paragraph * par = ownerParagraph();
do {
pos = par->getPositionOfInset(inset);
if (pos != -1) {
}
-void LyXText::setCursor(BufferView * bview, Paragraph * par,
+bool LyXText::setCursor(BufferView * bview, Paragraph * par,
pos_type pos,
bool setfont, bool boundary) const
{
LyXCursor old_cursor = cursor;
setCursorIntern(bview, par, pos, setfont, boundary);
- deleteEmptyParagraphMechanism(bview, old_cursor);
+ return deleteEmptyParagraphMechanism(bview, old_cursor);
}
-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);
float fill_hfill;
float fill_label_hfill;
prepareToPrint(bview, row, x, fill_separator, fill_hfill,
- fill_label_hfill);
+ fill_label_hfill);
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)
}
-void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
+bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
LyXCursor const & old_cursor) const
{
// Would be wrong to delete anything if we have a selection.
- if (selection.set()) return;
+ if (selection.set()) return false;
// We allow all kinds of "mumbo-jumbo" when freespacing.
if (textclasslist.Style(bview->buffer()->params.textclass,
old_cursor.par()->getLayout()).free_spacing
|| old_cursor.par()->isFreeSpacing())
{
- return;
+ return false;
}
-
- bool deleted = false;
/* Ok I'll put some comments here about what is missing.
I have fixed BackSpace (and thus Delete) to not delete
fixCursorAfterDelete(bview, toggle_cursor, old_cursor);
fixCursorAfterDelete(bview, toggle_end_cursor,
old_cursor);
- return;
+ return false;
}
}
// don't delete anything if this is the ONLY paragraph!
if (!old_cursor.par()->next() && !old_cursor.par()->previous())
- return;
+ return false;
// Do not delete empty paragraphs with keepempty set.
if ((textclasslist.Style(bview->buffer()->params.textclass,
old_cursor.par()->getLayout())).keepempty)
- return;
+ return false;
// only do our magic if we changed paragraph
if (old_cursor.par() == cursor.par())
- return;
+ return false;
+ // record if we have deleted a paragraph
+ // we can't possibly have deleted a paragraph before this point
+ bool deleted = false;
+
if ((old_cursor.par()->size() == 0
|| (old_cursor.par()->size() == 1
&& old_cursor.par()->isLineSeparator(0)))) {
if (ownerParagraph() == old_cursor.par()) {
ownerParagraph(ownerParagraph()->next());
}
- // delete old par
+ // delete old par
delete old_cursor.par();
/* Breakagain the next par. Needed because of
setCursorIntern(bview, cursor.par(), cursor.pos());
if (selection.cursor.par() == old_cursor.par()
- && selection.cursor.pos() == selection.cursor.pos()) {
+ && selection.cursor.pos() == old_cursor.pos()) {
// correct selection
selection.cursor = cursor;
}
selection.cursor = cursor;
}
}
+ return deleted;
}
bool start = !par->params().startOfAppendix();
// ensure that we have only one start_of_appendix in this document
- Paragraph * tmp = firstParagraph();
+ Paragraph * tmp = ownerParagraph();
for (; tmp; tmp = tmp->next()) {
tmp->params().startOfAppendix(false);
}