]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
* output_plaintext.C: cosmetics in comment: line length cannot be < 0
[lyx.git] / src / text3.C
index 008347710ae4693262898919b6f06265a506eb8c..86c69d0646be73b59307edcc411b1dd33e30883a 100644 (file)
@@ -76,6 +76,7 @@ namespace lyx {
 
 using cap::copySelection;
 using cap::cutSelection;
+using cap::pasteClipboard;
 using cap::pasteSelection;
 using cap::replaceSelection;
 
@@ -121,8 +122,7 @@ namespace {
        {
                if (selecting || cur.mark())
                        cur.setSelection();
-               if (!cur.selection())
-                       theSelection().haveSelection(false);
+               theSelection().haveSelection(cur.selection());
                cur.bv().switchKeyMap();
        }
 
@@ -144,9 +144,11 @@ namespace {
                replaceSelection(cur);
 
                if (sel.empty()) {
-                       //const int old_pos = cur.pos();
+#ifdef ENABLE_ASSERTIONS
+                       const int old_pos = cur.pos();
+#endif
                        cur.insert(new InsetMathHull(hullSimple));
-                       //BOOST_ASSERT(old_pos == cur.pos());
+                       BOOST_ASSERT(old_pos == cur.pos());
                        cur.nextInset()->edit(cur, true);
                        // don't do that also for LFUN_MATH_MODE
                        // unless you want end up with always changing
@@ -552,6 +554,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
        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();
@@ -757,15 +761,15 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                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();
@@ -864,11 +868,15 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
        }
 
        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: {
@@ -959,7 +967,14 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                // 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;
                }
 
@@ -1032,7 +1047,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                // finish selection
                if (cmd.button() == mouse_button::button1) {
                        if (cur.selection())
-                               theSelection().haveSelection(cur.selection());
+                               theSelection().haveSelection(true);
                        needsUpdate = false;
                        cur.noUpdate();
                }
@@ -1054,7 +1069,9 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                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();
@@ -1724,23 +1741,28 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
                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:
@@ -1813,8 +1835,6 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
        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:
@@ -1881,12 +1901,12 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
 
 
 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);