-void LyXText::insertInset(InsetOld * inset)
-{
- if (!cursorPar()->insetAllowed(inset->lyxCode()))
- return;
-
- recUndo(cursor.par());
- freezeUndo();
- cursorPar()->insertInset(cursor.pos(), inset);
- // Just to rebreak and refresh correctly.
- // The character will not be inserted a second time
- insertChar(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(true);
-
- unFreezeUndo();
-}
-
-
-void LyXText::cutSelection(bool doclear, bool realcut)
-{
- // 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(selectionAsString(*bv()->buffer(), true));
-
- // This doesn't make sense, if there is no selection
- if (!selection.set())
- return;
-
- // OK, we have a selection. This is always between selection.start
- // and selection.end
-
- // make sure that the depth behind the selection are restored, too
- ParagraphList::iterator endpit = boost::next(getPar(selection.end.par()));
- ParagraphList::iterator undoendpit = endpit;
- ParagraphList::iterator pars_end = ownerParagraphs().end();
-
- if (endpit != pars_end && endpit->getDepth()) {
- while (endpit != pars_end && endpit->getDepth()) {
- ++endpit;
- undoendpit = endpit;
- }
- } else if (endpit != pars_end) {
- // because of parindents etc.
- ++endpit;
- }
-
- recUndo(selection.start.par(), parOffset(undoendpit) - 1);
-
- endpit = getPar(selection.end.par());
- int endpos = selection.end.pos();
-
- BufferParams const & bufparams = bv()->buffer()->params();
- boost::tie(endpit, endpos) = realcut ?
- CutAndPaste::cutSelection(bufparams,
- ownerParagraphs(),
- getPar(selection.start.par()), endpit,
- selection.start.pos(), endpos,
- bufparams.textclass,
- doclear)
- : CutAndPaste::eraseSelection(bufparams,
- ownerParagraphs(),
- getPar(selection.start.par()), endpit,
- selection.start.pos(), endpos,
- doclear);
- // sometimes necessary
- if (doclear)
- getPar(selection.start.par())->stripLeadingSpaces();
-
- redoParagraphs(getPar(selection.start.par()), boost::next(endpit));
- // cutSelection can invalidate the cursor so we need to set
- // it anew. (Lgb)
- // we prefer the end for when tracking changes
- cursor.pos(endpos);
- cursor.par(parOffset(endpit));
-
- // need a valid cursor. (Lgb)
- clearSelection();
-
- setCursor(cursorPar(), cursor.pos());
- selection.cursor = cursor;
- updateCounters();
-}
-
-
-void LyXText::copySelection()
-{
- // 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 (getPar(selection.start)->size() > selection.start.pos()
- && getPar(selection.start)->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(getPar(selection.start.par()),
- getPar(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;
-
- recUndo(cursor.par());
-
- ParagraphList::iterator endpit;
- PitPosPair ppp;
-
- ErrorList el;
-
- boost::tie(ppp, endpit) =
- CutAndPaste::pasteSelection(*bv()->buffer(),
- ownerParagraphs(),
- cursorPar(), cursor.pos(),
- bv()->buffer()->params().textclass,
- sel_index, el);
- bufferErrors(*bv()->buffer(), el);
- bv()->showErrorList(_("Paste"));
-
- redoParagraphs(cursorPar(), 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(true);
- setSelection();
-}
-
-
-// simple replacing. The font of the first selected character is used
-void LyXText::replaceSelectionWithString(string const & str)