3 #include "textcursor.h"
5 bool TextCursor::setSelection()
7 bool const lsel = selection.set();
9 if (!selection.set()) {
10 last_sel_cursor = selection.cursor;
11 selection.start = selection.cursor;
12 selection.end = selection.cursor;
17 last_sel_cursor = cursor;
19 // and now the whole selection
21 if (selection.cursor.par() == cursor.par())
22 if (selection.cursor.pos() < cursor.pos()) {
23 selection.end = cursor;
24 selection.start = selection.cursor;
26 selection.end = selection.cursor;
27 selection.start = cursor;
29 else if (selection.cursor.y() < cursor.y() ||
30 (selection.cursor.y() == cursor.y()
31 && selection.cursor.x() < cursor.x())) {
32 selection.end = cursor;
33 selection.start = selection.cursor;
36 selection.end = selection.cursor;
37 selection.start = cursor;
40 // a selection with no contents is not a selection
41 if (selection.start.par() == selection.end.par() &&
42 selection.start.pos() == selection.end.pos())
49 void TextCursor::clearSelection()
52 selection.mark(false);
53 last_sel_cursor = selection.end = selection.start = selection.cursor = cursor;
57 string const TextCursor::selectionAsString(Buffer const * buffer,
63 // should be const ...
64 ParagraphList::iterator startpit = selection.start.par();
65 ParagraphList::iterator endpit = selection.end.par();
66 size_t const startpos = selection.start.pos();
67 size_t const endpos = selection.end.pos();
69 if (startpit == endpit)
70 return startpit->asString(buffer, startpos, endpos, label);
72 // First paragraph in selection
74 startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
76 // The paragraphs in between (if any)
77 ParagraphList::iterator pit = startpit;
78 for (++pit; pit != endpit; ++pit)
79 result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
81 // Last paragraph in selection
82 result += endpit->asString(buffer, 0, endpos, label);