[LyX/master] Fix bug #10646.

Richard Kimberly Heck rikiheck at lyx.org
Wed Feb 10 21:01:24 UTC 2021


commit 28743844149ad59a4641cb174cd2091348807660
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date:   Wed Feb 10 16:04:25 2021 -0500

    Fix bug #10646.
---
 src/insets/InsetCitation.cpp |   28 ++++++++++++++++------------
 src/insets/InsetCitation.h   |    2 ++
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index 1cc145a..0deb024 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -50,6 +50,7 @@ InsetCitation::InsetCitation(Buffer * buf, InsetCommandParams const & p)
 	: InsetCommand(buf, p)
 {
 	buffer().removeBiblioTempFiles();
+	cleanKeys();
 }
 
 
@@ -167,6 +168,8 @@ void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
 	// fall through
 	default:
 		InsetCommand::doDispatch(cur, cmd);
+		if (cmd.action() == LFUN_INSET_MODIFY)
+			cleanKeys();
 	}
 }
 
@@ -283,7 +286,7 @@ bool InsetCitation::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 bool InsetCitation::addKey(string const & key)
 {
-	docstring const ukey = from_utf8(key);
+	docstring const ukey = from_utf8(trim(key));
 	docstring const & curkeys = getParam("key");
 	if (curkeys.empty()) {
 		setParam("key", ukey);
@@ -292,10 +295,8 @@ bool InsetCitation::addKey(string const & key)
 	}
 
 	vector<docstring> keys = getVectorFromString(curkeys);
-	vector<docstring>::const_iterator it = keys.begin();
-	vector<docstring>::const_iterator en = keys.end();
-	for (; it != en; ++it) {
-		if (*it == ukey) {
+	for (auto const & k : keys) {
+		if (k == ukey) {
 			LYXERR0("Key " << key << " already present.");
 			return false;
 		}
@@ -602,22 +603,25 @@ int InsetCitation::plaintext(odocstringstream & os,
 
 static docstring const cleanupWhitespace(docstring const & citelist)
 {
-	docstring::const_iterator it  = citelist.begin();
-	docstring::const_iterator end = citelist.end();
 	// Paranoia check: make sure that there is no whitespace in here
 	// -- at least not behind commas or at the beginning
 	docstring result;
 	char_type last = ',';
-	for (; it != end; ++it) {
-		if (*it != ' ')
-			last = *it;
-		if (*it != ' ' || last != ',')
-			result += *it;
+	for (char_type c : citelist) {
+		if (c != ' ')
+			last = c;
+		if (c != ' ' || last != ',')
+			result += c;
 	}
 	return result;
 }
 
 
+void InsetCitation::cleanKeys() {
+	docstring cleankeys = cleanupWhitespace(getParam("key"));
+	setParam("key", cleankeys);
+}
+
 void InsetCitation::docbook(XMLStream & xs, OutputParams const &) const
 {
 	if (getCmdName() == "nocite")
diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h
index f41ef54..0adf0d4 100644
--- a/src/insets/InsetCitation.h
+++ b/src/insets/InsetCitation.h
@@ -111,6 +111,8 @@ private:
 	docstring complexLabel(bool for_xhtml = false) const;
 	/// makes a very basic label, in case we can't make a pretty one
 	docstring basicLabel(bool for_xhtml = false) const;
+	/// trims the keys
+	void cleanKeys();
 
 	/// \name Private functions inherited from Inset class
 	//@{


More information about the lyx-cvs mailing list