3 #include "textcursor.h"
5 void TextCursor::setSelection()
7 if (!selection.set()) {
8 selection.start = selection.cursor;
9 selection.end = selection.cursor;
14 // and now the whole selection
15 if (selection.cursor.par() == cursor.par())
16 if (selection.cursor.pos() < cursor.pos()) {
17 selection.end = cursor;
18 selection.start = selection.cursor;
20 selection.end = selection.cursor;
21 selection.start = cursor;
23 else if (selection.cursor.y() < cursor.y() ||
24 (selection.cursor.y() == cursor.y()
25 && selection.cursor.x() < cursor.x())) {
26 selection.end = cursor;
27 selection.start = selection.cursor;
30 selection.end = selection.cursor;
31 selection.start = cursor;
34 // a selection with no contents is not a selection
35 if (selection.start.par() == selection.end.par() &&
36 selection.start.pos() == selection.end.pos())
43 void TextCursor::clearSelection()
46 selection.mark(false);
47 selection.end = cursor;
48 selection.start = cursor;
49 selection.cursor = cursor;
53 string const TextCursor::selectionAsString(Buffer const * buffer,
59 // should be const ...
60 ParagraphList::iterator startpit = selection.start.par();
61 ParagraphList::iterator endpit = selection.end.par();
62 size_t const startpos = selection.start.pos();
63 size_t const endpos = selection.end.pos();
65 if (startpit == endpit)
66 return startpit->asString(buffer, startpos, endpos, label);
68 // First paragraph in selection
70 startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
72 // The paragraphs in between (if any)
73 ParagraphList::iterator pit = startpit;
74 for (++pit; pit != endpit; ++pit)
75 result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
77 // Last paragraph in selection
78 result += endpit->asString(buffer, 0, endpos, label);