lyx_mirror/src/textcursor.C
André Pönitz dcd8fb0428 replace ParagraphList::iterator by lyx::paroffset_type to prevent cursor
invalidation if the paragraphlist is changed.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7883 a592a061-630c-0410-9148-cb99ea01b6c8
2003-10-09 10:52:12 +00:00

69 lines
1.4 KiB
C

/**
* \file textcursor.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "textcursor.h"
#include "paragraph.h"
#include "ParagraphList_fwd.h"
#include <string>
using std::string;
void TextCursor::setSelection()
{
if (!selection.set()) {
selection.start = selection.cursor;
selection.end = selection.cursor;
}
selection.set(true);
// and now the whole selection
if (selection.cursor.par() == cursor.par())
if (selection.cursor.pos() < cursor.pos()) {
selection.end = cursor;
selection.start = selection.cursor;
} else {
selection.end = selection.cursor;
selection.start = cursor;
}
else if (selection.cursor.y() < cursor.y() ||
(selection.cursor.y() == cursor.y()
&& selection.cursor.x() < cursor.x())) {
selection.end = cursor;
selection.start = selection.cursor;
}
else {
selection.end = selection.cursor;
selection.start = cursor;
}
// a selection with no contents is not a selection
if (selection.start.par() == selection.end.par() &&
selection.start.pos() == selection.end.pos())
{
selection.set(false);
}
}
void TextCursor::clearSelection()
{
selection.set(false);
selection.mark(false);
selection.end = cursor;
selection.start = cursor;
selection.cursor = cursor;
}