/** * \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 #include "textcursor.h" #include "paragraph.h" #include "ParagraphList_fwd.h" #include 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; }