- // 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 (!selection.set())
- return;
-
- // ok we have a selection. This is always between selection.start
- // and sel_end cursor
-
- // copy behind a space if there is one
- while (selection.start.par()->size() > selection.start.pos()
- && selection.start.par()->isLineSeparator(selection.start.pos())
- && (selection.start.par() != selection.end.par()
- || selection.start.pos() < selection.end.pos()))
- selection.start.pos(selection.start.pos() + 1);
-
- CutAndPaste::copySelection(selection.start.par(),
- selection.end.par(),
- selection.start.pos(), selection.end.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;
-
- recordUndo(bv(), Undo::INSERT, cursor.par());
-
- ParagraphList::iterator endpit;
- PitPosPair ppp;
-
- ErrorList el;
-
- boost::tie(ppp, endpit) =
- CutAndPaste::pasteSelection(*bv()->buffer(),
- ownerParagraphs(),
- cursor.par(), cursor.pos(),
- bv()->buffer()->params().textclass,
- sel_index, el);
- bufferErrors(*bv()->buffer(), el);
- bv()->showErrorList(_("Paste"));
-
- redoParagraphs(cursor.par(), endpit);
-
- setCursor(cursor.par(), cursor.pos());
- clearSelection();
-
- selection.cursor = cursor;
- setCursor(ppp.first, ppp.second);
- setSelection();
- updateCounters();
-}
-
-
-void LyXText::setSelectionRange(lyx::pos_type length)
-{
- if (!length)
- return;
-
- selection.cursor = cursor;
- while (length--)
- cursorRight(bv());
- setSelection();
-}
-
-
-// simple replacing. The font of the first selected character is used
-void LyXText::replaceSelectionWithString(string const & str)
-{
- recordUndo(bv(), Undo::ATOMIC);
- freezeUndo();
-
- if (!selection.set()) { // create a dummy selection
- selection.end = cursor;
- selection.start = cursor;
- }
-
- // Get font setting before we cut
- pos_type pos = selection.end.pos();
- LyXFont const font = selection.start.par()
- ->getFontSettings(bv()->buffer()->params(),
- selection.start.pos());
-
- // Insert the new string
- string::const_iterator cit = str.begin();
- string::const_iterator end = str.end();
- for (; cit != end; ++cit) {
- selection.end.par()->insertChar(pos, (*cit), font);
- ++pos;
- }
-
- // Cut the selection
- cutSelection(true, false);
-
- unFreezeUndo();