- // Just to rebreak and refresh correctly.
- // The character will not be inserted a second time
- insertChar(cur, Paragraph::META_INSET);
- // If we enter a highly editable inset the cursor should be before
- // the inset. After an undo LyX tries to call inset->edit(...)
- // and fails if the cursor is behind the inset and getInset
- // does not return the inset!
- if (isHighlyEditableInset(inset))
- cursorLeft(cur, true);
- unFreezeUndo();
-}
-
-
-void LyXText::cutSelection(LCursor & cur, bool doclear, bool realcut)
-{
- BOOST_ASSERT(this == cur.text());
- // Stuff what we got on the clipboard. Even if there is no selection.
-
- // There is a problem with having the stuffing here in that the
- // larger the selection the slower LyX will get. This can be
- // solved by running the line below only when the selection has
- // finished. The solution used currently just works, to make it
- // faster we need to be more clever and probably also have more
- // calls to stuffClipboard. (Lgb)
- bv()->stuffClipboard(cur.selectionAsString(true));
-
- // This doesn't make sense, if there is no selection
- if (!cur.selection())
- return;
-
- // OK, we have a selection. This is always between cur.selBegin()
- // and cur.selEnd()
-
- // make sure that the depth behind the selection are restored, too
- recordUndoSelection(cur);
- ParagraphList::iterator begpit = getPar(cur.selBegin().par());
- ParagraphList::iterator endpit = getPar(cur.selEnd().par());
- ParagraphList::iterator undopit = undoSpan(endpit);
-
- int endpos = cur.selEnd().pos();
-
- BufferParams const & bufparams = bv()->buffer()->params();
- boost::tie(endpit, endpos) = realcut ?
- CutAndPaste::cutSelection(bufparams,
- paragraphs(),
- begpit, endpit,
- cur.selBegin().pos(), endpos,
- bufparams.textclass,
- doclear)
- : CutAndPaste::eraseSelection(bufparams,
- paragraphs(),
- begpit, endpit,
- cur.selBegin().pos(), endpos,
- doclear);
- // sometimes necessary
- if (doclear)
- begpit->stripLeadingSpaces();
-
- redoParagraphs(begpit, undopit);
- // cutSelection can invalidate the cursor so we need to set
- // it anew. (Lgb)
- // we prefer the end for when tracking changes
- cur.pos() = endpos;
- cur.par() = parOffset(endpit);
-
- // need a valid cursor. (Lgb)
- cur.clearSelection();
- updateCounters();
-}
-
-
-void LyXText::copySelection(LCursor & cur)
-{
- BOOST_ASSERT(this == cur.text());
- // stuff the selection onto the X clipboard, from an explicit copy request
- bv()->stuffClipboard(cur.selectionAsString(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(LCursor & cur, size_t sel_index)
-{
- // this does not make sense, if there is nothing to paste
- if (!CutAndPaste::checkPastePossible())
- return;
-
- recordUndo(cur);
-
- ParagraphList::iterator endpit;
- PitPosPair ppp;
-
- ErrorList el;
-
- boost::tie(ppp, endpit) =
- CutAndPaste::pasteSelection(*bv()->buffer(),
- paragraphs(),
- getPar(cur.par()), cur.pos(),
- bv()->buffer()->params().textclass,
- sel_index, el);
- bufferErrors(*bv()->buffer(), el);
- bv()->showErrorList(_("Paste"));
-
- redoParagraphs(getPar(cur.par()), endpit);
-
- cur.clearSelection();
- cur.resetAnchor();
- setCursor(cur, parOffset(ppp.first), ppp.second);
- cur.setSelection();
- updateCounters();
-}
-
-
-void LyXText::setSelectionRange(LCursor & cur, lyx::pos_type length)
-{
- if (!length)
- return;
- cur.resetAnchor();
- while (length--)
- cursorRight(cur, true);
- cur.setSelection();
-}
-
-
-// simple replacing. The font of the first selected character is used
-void LyXText::replaceSelectionWithString(LCursor & cur, string const & str)
-{
- recordUndo(cur);
- 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(cur, true, false);
- unFreezeUndo();