- // 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 (!bv()->selection().set())
- return;
-
- // ok we have a selection. This is always between bv()->selStart()
- // and sel_end cursor
-
- // copy behind a space if there is one
- while (getPar(bv()->selStart())->size() > bv()->selStart().pos()
- && getPar(bv()->selStart())->isLineSeparator(bv()->selStart().pos())
- && (bv()->selStart().par() != bv()->selEnd().par()
- || bv()->selStart().pos() < bv()->selEnd().pos()))
- bv()->selStart().pos(bv()->selStart().pos() + 1);
-
- CutAndPaste::copySelection(getPar(bv()->selStart().par()),
- getPar(bv()->selEnd().par()),
- bv()->selStart().pos(),
- bv()->selEnd().pos(),
- bv()->buffer()->params().textclass);
-}
-
-
-void LyXText::pasteSelection(size_t sel_index)
-{
- // 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);
-
- bv()->clearSelection();
- bv()->resetAnchor();
- setCursor(ppp.first, ppp.second);
- bv()->setSelection();
- updateCounters();
-}
-
-
-void LyXText::setSelectionRange(lyx::pos_type length)
-{
- if (!length)
- return;
-
- bv()->resetAnchor();
- while (length--)
- cursorRight(true);
- bv()->setSelection();
-}
-
-
-// simple replacing. The font of the first selected character is used
-void LyXText::replaceSelectionWithString(string const & str)
-{
- recUndo(cursor().par());
- freezeUndo();
-
- // Get font setting before we cut
- pos_type pos = bv()->selEnd().pos();
- LyXFont const font = getPar(bv()->selStart())
- ->getFontSettings(bv()->buffer()->params(),
- bv()->selStart().pos());
-
- // Insert the new string
- string::const_iterator cit = str.begin();
- string::const_iterator end = str.end();
- for (; cit != end; ++cit) {
- getPar(bv()->selEnd())->insertChar(pos, (*cit), font);
- ++pos;
- }
-
- // Cut the selection
- cutSelection(true, false);
-
- unFreezeUndo();