3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "textcursor.h"
15 void TextCursor::setSelection()
17 if (!selection.set()) {
18 selection.start = selection.cursor;
19 selection.end = selection.cursor;
24 // and now the whole selection
25 if (selection.cursor.par() == cursor.par())
26 if (selection.cursor.pos() < cursor.pos()) {
27 selection.end = cursor;
28 selection.start = selection.cursor;
30 selection.end = selection.cursor;
31 selection.start = cursor;
33 else if (selection.cursor.y() < cursor.y() ||
34 (selection.cursor.y() == cursor.y()
35 && selection.cursor.x() < cursor.x())) {
36 selection.end = cursor;
37 selection.start = selection.cursor;
40 selection.end = selection.cursor;
41 selection.start = cursor;
44 // a selection with no contents is not a selection
45 if (selection.start.par() == selection.end.par() &&
46 selection.start.pos() == selection.end.pos())
53 void TextCursor::clearSelection()
56 selection.mark(false);
57 selection.end = cursor;
58 selection.start = cursor;
59 selection.cursor = cursor;
63 string const TextCursor::selectionAsString(Buffer const * buffer,
69 // should be const ...
70 ParagraphList::iterator startpit = selection.start.par();
71 ParagraphList::iterator endpit = selection.end.par();
72 size_t const startpos = selection.start.pos();
73 size_t const endpos = selection.end.pos();
75 if (startpit == endpit)
76 return startpit->asString(buffer, startpos, endpos, label);
78 // First paragraph in selection
80 startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
82 // The paragraphs in between (if any)
83 ParagraphList::iterator pit = startpit;
84 for (++pit; pit != endpit; ++pit)
85 result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
87 // Last paragraph in selection
88 result += endpit->asString(buffer, 0, endpos, label);