Am Tue, 19 Jul 2022 12:35:46 +0200
schrieb Kornel Benko <kor...@lyx.org>:

> Am Tue, 19 Jul 2022 12:20:59 +0200
> schrieb Jean-Marc Lasgouttes <lasgout...@lyx.org>:
> 
> > Le 19/07/2022 à 11:11, Kornel Benko a écrit :
> > > The only drawback I see is when there are more than one binding to a key. 
> > >  
> > 
> > Ahh. Good point.
> > 
> > Then we can add special handling for function "*", which means all 
> > bindings to this sequence.
> 
> Good idea.
> 
> > JMarc
> 
>       Kornel
> 

Use this in user.bind
        \unbind "Tab" "message *"
(for the proposed '\unbind "Tab" "*"' is more to do)

This seems to work. But the shortcut-dialog still shows the original
setting.

        Kornel
diff --git a/src/KeyMap.cpp b/src/KeyMap.cpp
index f469da5c44..5d463670bb 100644
--- a/src/KeyMap.cpp
+++ b/src/KeyMap.cpp
@@ -30,10 +30,11 @@
 #include "frontends/alert.h"
 
 #include <fstream>
 #include <sstream>
 #include <utility>
+#include <regex>
 
 using namespace std;
 using namespace lyx::support;
 
 namespace lyx {
@@ -156,22 +157,32 @@ void KeyMap::unbind(KeySequence * seq, FuncRequest const & func, unsigned int r)
 	if (!code.isOK())
 		return;
 
 	KeyModifier const mod1 = seq->modifiers[r].first;
 	KeyModifier const mod2 = seq->modifiers[r].second;
+	bool remove_all = false;
+	static std::regex special("^\\s*\\*\\s*$");
+	smatch sub;
+	if (func.action() == lyx::LFUN_MESSAGE) {
+		string cmd = func.getArg(0);
+		if (regex_match(cmd, sub, special))
+			remove_all = true;
+	}
 
 	// check if key is already there
 	Table::iterator end = table.end();
 	Table::iterator remove = end;
+	vector <Table::iterator> removes = vector <Table::iterator>();
 	for (Table::iterator it = table.begin(); it != end; ++it) {
 		if (code == it->code
 		    && mod1 == it->mod.first
 		    && mod2 == it->mod.second) {
 			// remove
 			if (r + 1 == seq->length()) {
-				if (it->func == func) {
-					remove = it;
+				if (it->func == func || remove_all) {
+					//remove = it;
+					removes.push_back(it);
 					if (it->prefixes)
 						it->prefixes.reset();
 				}
 			} else if (it->prefixes) {
 				it->prefixes->unbind(seq, func, r + 1);
@@ -179,12 +190,16 @@ void KeyMap::unbind(KeySequence * seq, FuncRequest const & func, unsigned int r)
 					remove = it;
 				return;
 			}
 		}
 	}
+	for (unsigned i = removes.size(); i > 0; --i)
+		table.erase(removes[i-1]);
+	/*
 	if (remove != end)
 		table.erase(remove);
+	*/
 }
 
 
 FuncRequest KeyMap::getBinding(KeySequence const & seq, unsigned int r)
 {

Attachment: pgpu3VrNjbV4X.pgp
Description: Digitale Signatur von OpenPGP

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to