+
+
+void BufferView::setSelection()
+{
+ selection().set(true);
+ // a selection with no contents is not a selection
+ if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
+ selection().set(false);
+}
+
+
+void BufferView::clearSelection()
+{
+ selection().set(false);
+ selection().mark(false);
+ resetAnchor();
+ unsetXSel();
+}
+
+
+
+/*
+if the fitCursor call refers to some point in never-explored-land, then we
+don't have y information in insets there, then we cannot even do an update
+to get it (because we need the y infomation for setting top_y first). So
+this is solved in put_selection_at with:
+
+- setting top_y to the y of the outerPar (that has good info)
+- calling update
+- calling cursor().updatePos()
+- then call fitCursor()
+
+Ab.
+*/
+
+void BufferView::putSelectionAt(PosIterator const & cur,
+ int length, bool backwards)
+{
+ ParIterator par(cur);
+
+ clearSelection();
+
+ LyXText * text = par.text(*buffer());
+ par.lockPath(this);
+ // hack for the chicken and egg problem
+ if (par.inset())
+ top_y(par.outerPar()->y);
+ update();
+ text->setCursor(cur.pit(), cur.pos());
+ fullCursor().updatePos();
+
+ if (length) {
+ text->setSelectionRange(length);
+ setSelection();
+ if (backwards)
+ std::swap(cursor(), anchor());
+ }
+
+ fitCursor();
+ update();
+}
+