- LCursor & cur = bv()->cursor();
- // stuff the selection onto the X clipboard, from an explicit copy request
- bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
-
- // this doesnt make sense, if there is no selection
- if (!cur.selection())
- return;
-
- // ok we have a selection. This is always between cur.selBegin()
- // and sel_end cursor
-
- // copy behind a space if there is one
- while (getPar(cur.selBegin())->size() > cur.selBegin().pos()
- && getPar(cur.selBegin())->isLineSeparator(cur.selBegin().pos())
- && (cur.selBegin().par() != cur.selEnd().par()
- || cur.selBegin().pos() < cur.selEnd().pos()))
- cur.selBegin().pos(cur.selBegin().pos() + 1);
-
- CutAndPaste::copySelection(getPar(cur.selBegin().par()),
- getPar(cur.selEnd().par()),
- cur.selBegin().pos(),
- cur.selEnd().pos(),
- bv()->buffer()->params().textclass);
-}
-
-
-void LyXText::pasteSelection(size_t sel_index)
-{
- LCursor & cur = bv()->cursor();
- // this does not make sense, if there is nothing to paste
- if (!CutAndPaste::checkPastePossible())
- return;
-
- recUndo(cursor().par());
-
- ParagraphList::iterator endpit;
- PitPosPair ppp;
-
- ErrorList el;
-
- boost::tie(ppp, endpit) =
- CutAndPaste::pasteSelection(*bv()->buffer(),
- paragraphs(),
- cursorPar(), cursor().pos(),
- bv()->buffer()->params().textclass,
- sel_index, el);
- bufferErrors(*bv()->buffer(), el);
- bv()->showErrorList(_("Paste"));
-
- redoParagraphs(cursorPar(), endpit);
-
- cur.clearSelection();
- cur.resetAnchor();
- setCursor(ppp.first, ppp.second);
- cur.setSelection();
- updateCounters();
-}
-
-
-void LyXText::setSelectionRange(lyx::pos_type length)
-{
- if (!length)
- return;
-
- LCursor & cur = bv()->cursor();
- cur.resetAnchor();
- while (length--)
- cursorRight(true);
- cur.setSelection();
-}
-
-
-// simple replacing. The font of the first selected character is used
-void LyXText::replaceSelectionWithString(string const & str)
-{
- LCursor & cur = bv()->cursor();
- recUndo(cur.par());
- freezeUndo();
-
- // Get font setting before we cut
- pos_type pos = cur.selEnd().pos();
- LyXFont const font = getPar(cur.selBegin())
- ->getFontSettings(bv()->buffer()->params(),
- cur.selBegin().pos());
-
- // Insert the new string
- string::const_iterator cit = str.begin();
- string::const_iterator end = str.end();
- for (; cit != end; ++cit) {
- getPar(cur.selEnd())->insertChar(pos, (*cit), font);
- ++pos;
- }
-
- // Cut the selection
- cutSelection(true, false);
-
- unFreezeUndo();