]> git.lyx.org Git - lyx.git/blob - src/textcursor.C
prevent crash in cursorX when row cache is empty
[lyx.git] / src / textcursor.C
1 /**
2  * \file textcursor.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12 #include <algorithm>
13
14 #include "textcursor.h"
15
16
17 LyXCursor const & TextCursor::selStart() const
18 {
19         if (!selection.set())
20                 return cursor;
21         return std::min(selection.cursor, cursor);
22 }
23
24
25 LyXCursor const & TextCursor::selEnd() const
26 {
27         if (!selection.set())
28                 return cursor;
29         return std::max(selection.cursor, cursor);
30 }
31
32
33 LyXCursor & TextCursor::selStart()
34 {
35         TextCursor const & t = *this;
36         return const_cast<LyXCursor &>(t.selStart());
37 }
38
39
40 LyXCursor & TextCursor::selEnd()
41 {
42         TextCursor const & t = *this;
43         return const_cast<LyXCursor &>(t.selEnd());
44 }
45
46
47 void TextCursor::setSelection()
48 {
49         selection.set(true);
50         // a selection with no contents is not a selection
51         if (cursor.par() == selection.cursor.par() &&
52             cursor.pos() == selection.cursor.pos())
53         {
54                 selection.set(false);
55         }
56 }
57
58
59 void TextCursor::clearSelection()
60 {
61         selection.set(false);
62         selection.mark(false);
63         selection.cursor = cursor;
64 }
65