[LyX/master] Add option "paste latex|html force" to enforce conversion

Juergen Spitzmueller <[email protected]>
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit 26c904a371a2563b5ea5e5f7cda83cd1196d43f7
Author: Juergen Spitzmueller <[email protected]>
Date:   Thu Aug 13 16:01:36 2026 +0200

    Add option "paste latex|html force" to enforce conversion
    
    even if the string comes from the internal clipboard
    
    So copying the string \LaTeX from the LyX workarea and issuing
    "paste latex force" will input the converted inset
    
    This allows to setup conversion helpers (#6732)
---
 lib/RELEASE-NOTES   | 4 ++++
 src/CutAndPaste.cpp | 4 ++--
 src/CutAndPaste.h   | 3 ++-
 src/LyXAction.cpp   | 4 +++-
 src/Text.cpp        | 7 ++++---
 5 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES
index a6a24e82d3..c5af4f3bb4 100644
--- a/lib/RELEASE-NOTES
+++ b/lib/RELEASE-NOTES
@@ -68,6 +68,10 @@
 - The function copy now accepts an optional argument "latex" which will cause
   LyX to copy the selection in its LaTeX representation to the external clipboard.
   The argument "plain" is equal to the default (copy as plain text string).
+  
+- The function paste now has a second optional argument "force" that will enforce
+  conversion with the first argument "latex" or "html" even if the pasted string
+  comes from the internal clipboard.
 
 !!!The following LyX functions have been removed in 2.6:
 
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index 81d73d6446..e3b197d47a 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -1302,11 +1302,11 @@ bool pasteFromTemp(Cursor & cur, ErrorList & errorList)
 
 
 bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
-                        Clipboard::TextType type)
+                        Clipboard::TextType type, bool const ignore_internal)
 {
 	// Use internal clipboard if it is the most recent one
 	// This overrides asParagraphs and type on purpose!
-	if (theClipboard().isInternal())
+	if (theClipboard().isInternal() && !ignore_internal)
 		return pasteFromStack(cur, errorList, 0);
 
 	// First try LyX format
diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h
index bed6db326d..ba308b8927 100644
--- a/src/CutAndPaste.h
+++ b/src/CutAndPaste.h
@@ -102,7 +102,8 @@ void pasteSelection(Cursor & cur, ErrorList &);
 /// Does handle undo. Does only work in text, not mathed.
 /// \p asParagraphs is only considered if plain text is pasted.
 bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
-	frontend::Clipboard::TextType preferedType = frontend::Clipboard::LyXOrPlainTextType);
+	frontend::Clipboard::TextType preferedType = frontend::Clipboard::LyXOrPlainTextType,
+	bool const ignore_internal = false);
 /// Replace the current selection with the clipboard contents as graphic.
 /// Does handle undo. Does only work in text, not mathed.
 void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList,
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 9bb55913e2..24a5f2b78d 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -3474,9 +3474,11 @@ void LyXAction::init()
 /*!
  * \var lyx::FuncCode lyx::LFUN_PASTE
  * \li Action: Pastes material (text or picture) from the active clipboard.
- * \li Syntax: paste [<TYPE>|<NUM>]
+ * \li Syntax: paste [<TYPE>|<NUM>] [force]
  * \li Params: <TYPE>: emf|pdf|png|jpeg|linkback|wmf|latex|html \n
                <NUM>: number of the selection in the internal clipboard stack to be pasted.
+               force: if this is specified with latex or html, the conversion is enforced
+                      even if the string comes from the internal clipboard.
  * \endvar
  */
 		{ LFUN_PASTE, "paste", Noop, Edit },
diff --git a/src/Text.cpp b/src/Text.cpp
index 38ff2700b0..e6e650697e 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -4922,7 +4922,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		cap::replaceSelection(cur);
 
 		// without argument?
-		string const arg = to_utf8(cmd.argument());
+		string const arg = cmd.getArg(0);
+		bool const ignore_internal = cmd.getArg(1) == "force";
 		if (arg.empty()) {
 			bool tryGraphics = true;
 			if (theClipboard().isInternal())
@@ -4941,7 +4942,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		} else if (arg == "html" || arg == "latex") {
 			Clipboard::TextType type = (arg == "html") ?
 				Clipboard::HtmlTextType : Clipboard::LaTeXTextType;
-			pasteClipboardText(cur, bv->buffer().errorList("Paste"), true, type);
+			pasteClipboardText(cur, bv->buffer().errorList("Paste"), true, type, ignore_internal);
 		} else {
 			Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
 			if (arg == "pdf")
@@ -6842,7 +6843,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
 		}
 
 		// we have an argument
-		string const arg = to_utf8(cmd.argument());
+		string const arg = cmd.getArg(0);
 		if (isStrUnsignedInt(arg)) {
 			// it's a number and therefore means the internal stack
 			unsigned int n = convert<unsigned int>(arg);
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.