using cap::copySelection;
using cap::cutSelection;
+using cap::pasteClipboard;
using cap::pasteSelection;
using cap::replaceSelection;
{
if (selecting || cur.mark())
cur.setSelection();
- if (!cur.selection())
- theSelection().haveSelection(false);
+ theSelection().haveSelection(cur.selection());
cur.bv().switchKeyMap();
}
case LFUN_BREAK_LINE: {
// Not allowed by LaTeX (labels or empty par)
if (cur.pos() > cur.paragraph().beginOfBody()) {
+ if (!cur.selection())
+ recordUndo(cur);
cap::replaceSelection(cur);
cur.insert(new InsetNewline);
cur.posRight();
cur.message(_("Paste"));
cap::replaceSelection(cur);
if (cmd.argument().empty() && !theClipboard().isInternal())
- pasteString(cur, theClipboard().get(), docstring());
+ pasteClipboard(cur, bv->buffer()->errorList("Paste"));
else {
string const arg(to_utf8(cmd.argument()));
pasteSelection(cur, bv->buffer()->errorList("Paste"),
isStrUnsignedInt(arg) ?
convert<unsigned int>(arg) :
0);
- bv->buffer()->errors("Paste");
}
+ bv->buffer()->errors("Paste");
cur.clearSelection(); // bug 393
bv->switchKeyMap();
finishUndo();
}
case LFUN_CLIPBOARD_PASTE:
- pasteString(cur, theClipboard().get(), cmd.argument());
+ cur.clearSelection();
+ pasteClipboard(cur, bv->buffer()->errorList("Paste"),
+ cmd.argument() == "paragraph");
+ bv->buffer()->errors("Paste");
break;
case LFUN_PRIMARY_SELECTION_PASTE:
- pasteString(cur, theSelection().get(), cmd.argument());
+ pasteString(cur, theSelection().get(),
+ cmd.argument() == "paragraph");
break;
case LFUN_UNICODE_INSERT: {
// we have to check this first
bool paste_internally = false;
if (cmd.button() == mouse_button::button2 && cur.selection()) {
- lyx::dispatch(FuncRequest(LFUN_COPY));
+ // Copy the selection to the clipboard stack. This
+ // is done for two reasons:
+ // - We want it to appear in the "Edit->Paste recent"
+ // menu.
+ // - We can then use the normal copy/paste machinery
+ // instead of theSelection().get() to preserve
+ // formatting of the pasted stuff.
+ cap::copySelectionToStack(cur.bv().cursor());
paste_internally = true;
}
if (lyxrc.auto_region_delete) {
if (cur.selection())
cutSelection(cur, false, false);
- theSelection().haveSelection(false);
+ // cutSelection clears the X selection.
+ else
+ theSelection().haveSelection(false);
}
cur.clearSelection();
break;
case LFUN_PASTE:
- // FIXME: This is not correct, but the correct code below is
- // expensive
- enable = cap::numberOfSelections() > 0 ||
- !theClipboard().isInternal();
-#if 0
if (cmd.argument().empty()) {
if (theClipboard().isInternal())
enable = cap::numberOfSelections() > 0;
else
- enable = !theClipboard().get().empty();
- } else if (isStrUnsignedInt(to_utf8(cmd.argument()))) {
- int n = convert<unsigned int>(to_utf8(cmd.argument()));
- enable = cap::numberOfSelections() > n;
- } else
- // unknown argument
- enable = false;
-#endif
+ enable = !theClipboard().empty();
+ } else {
+ string const arg = to_utf8(cmd.argument());
+ if (isStrUnsignedInt(arg)) {
+ unsigned int n = convert<unsigned int>(arg);
+ enable = cap::numberOfSelections() > n;
+ } else
+ // unknown argument
+ enable = false;
+ }
+ break;
+
+ case LFUN_CLIPBOARD_PASTE:
+ enable = !theClipboard().empty();
+ break;
+
+ case LFUN_PRIMARY_SELECTION_PASTE:
+ enable = cur.selection() || !theSelection().empty();
break;
case LFUN_PARAGRAPH_MOVE_UP:
case LFUN_SERVER_GET_FONT:
case LFUN_SERVER_GET_LAYOUT:
case LFUN_LAYOUT:
- case LFUN_CLIPBOARD_PASTE:
- case LFUN_PRIMARY_SELECTION_PASTE:
case LFUN_DATE_INSERT:
case LFUN_SELF_INSERT:
case LFUN_LINE_INSERT:
void LyXText::pasteString(LCursor & cur, docstring const & clip,
- docstring const & argument)
+ bool asParagraphs)
{
cur.clearSelection();
if (!clip.empty()) {
recordUndo(cur);
- if (argument == "paragraph")
+ if (asParagraphs)
insertStringAsParagraphs(cur, clip);
else
insertStringAsLines(cur, clip);