Le 21/02/2022 à 15:10, Jean-Marc Lasgouttes a écrit :
Le 21/02/2022 à 03:27, Scott Kostyshak a écrit :
On Sun, Feb 20, 2022 at 07:20:24PM +0100, Jean-Marc Lasgouttes wrote:
I really wonder why this special behavior is by default, since it is only
useful for interactive edition.

I would prefer to have
   char-delete-forward confirm
bound to the <del> key.

That sounds reasonable to me.

Here is what I came up with. Scott, please tell me whether the bit in release notes makes sense.

What is missing here is the prefs2prefs_lfun.py part. I tried it a bit, but python does not like me. Could somebody help for this part?

The interesting functions are (word|char)-delete-(for|back)ward
> * If there is no argument, add argument `confirm'.
* If the argument is `force', remove it.
* If it is another string, remove it too actually (although it should not happen)

I really do not understand how this magic python thing works. I have not been able to make it match any of my regexes.

Ping!

Here is an updated version of the patch. I need help for the prefs2prefs_lfun.py script, along the lines presented above. Can someone do it or at least give directions?

Note that the patch as it stands changes the behavior of LyX: I did not add 'confirm' to the commands in lib/bind/, since I expect that to be done by pref2pref.

Just as a reminder, the goal is to have char-delete-backwards without argument actually delete previous element, without consideration of confirmation that are only relevant to interactive use.

Once sorted out, this would be candidate for 2.4.0.

JMarc
From cb3282d958f5238c4299b500a793a2f93e2131a0 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Mon, 21 Feb 2022 14:00:14 +0100
Subject: [PATCH] Fixup 71623b88: change semantics of "delete" LFUNs again

Instead of specifying "force" to disable the deletion protection
mechanism, invert the default so that "confirm" is needed to activate
it. The idea is to keep the lfun reasonable for scripting and add a
special argument for interactive use.

Document in release notes.
---
 lib/RELEASE-NOTES            | 11 +++++++++++
 src/LyXAction.cpp            | 18 +++++++++---------
 src/Text3.cpp                |  8 ++++----
 src/mathed/InsetMathNest.cpp |  8 ++++----
 4 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES
index bd562bf802..52aa33b46a 100644
--- a/lib/RELEASE-NOTES
+++ b/lib/RELEASE-NOTES
@@ -178,6 +178,17 @@
 
 * branch-sync-all: Open/close all insets of selected branch (depending on its activation status).
 
+* word-delete-forward, word-delete-backward, char-delete-forward,
+  char-delete-backward
+
+  The 2.4 behavior of these functions is almost equivalent to the
+  pre-2.3 behavior: without argument, it just deletes the
+  next/previous element; with the newly added "confirm" argument
+  however, big insets are selected on the first call and deleted only
+  on the second (this behavior was the default for 2.3.x but now
+  requires the "confirm" argument). This new behavior allow scripts to
+  work intuitively and require the argument only for interactive use.
+
 
 !!!The following LyX functions have been removed in 2.4:
 
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index c5708b09e3..96060f80fe 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -1150,8 +1150,8 @@ void LyXAction::init()
 /*!
  * \var lyx::FuncCode lyx::LFUN_CHAR_DELETE_BACKWARD
  * \li Action: Deletes one character in the backward direction (usually the "BackSpace" key).
- * \li Syntax: char-delete-backward [force]
- * \li Params: force: Delete big insets, do not only select them.
+ * \li Syntax: char-delete-backward [confirm]
+ * \li Params: confirm: Select big insets, do not directly delete them.
  * \endvar
  */
 		{ LFUN_CHAR_DELETE_BACKWARD, "char-delete-backward", SingleParUpdate, Edit },
@@ -1159,8 +1159,8 @@ void LyXAction::init()
 /*!
  * \var lyx::FuncCode lyx::LFUN_CHAR_DELETE_FORWARD
  * \li Action: Deletes one character in the backward direction (usually the "Delete" key).
- * \li Syntax: char-delete-forward [force]
- * \li Params: force: Delete big insets, do not only select them.
+ * \li Syntax: char-delete-forward [confirm]
+ * \li Params: confirm: Select big insets, do not directly delete them.
  * \endvar
  */
 		{ LFUN_CHAR_DELETE_FORWARD, "char-delete-forward", SingleParUpdate, Edit },
@@ -2190,7 +2190,7 @@ void LyXAction::init()
                matches all note insets, while "Note:Note" only matches LyX
                yellow note insets.
  * \li Sample: Remove all index insets: \n
-                   inset-forall Index char-delete-forward force \n
+                   inset-forall Index char-delete-forward \n
                Close all Notes: \n
                    inset-forall Note inset-toggle close \n
                Open all branch insets of branch "myBranch": \n
@@ -4417,8 +4417,8 @@ void LyXAction::init()
 /*!
  * \var lyx::FuncCode lyx::LFUN_WORD_DELETE_BACKWARD
  * \li Action: Deletes characters to the beginning of the word (usually the "C+BackSpace" key).
- * \li Syntax: word-delete-backward [force]
- * \li Params: force: Delete big insets, do not only select them.
+ * \li Syntax: word-delete-backward [confirm]
+ * \li Params: confirm: Select big insets, do not directly delete them.
  * \endvar
  */
 		{ LFUN_WORD_DELETE_BACKWARD, "word-delete-backward", Noop, Edit },
@@ -4426,8 +4426,8 @@ void LyXAction::init()
 /*!
  * \var lyx::FuncCode lyx::LFUN_WORD_DELETE_FORWARD
  * \li Action: Deletes characters to the end of the word (usually the "C+Delete" key).
- * \li Syntax: word-delete-forward [force]
- * \li Params: force: Delete big insets, do not only select them.
+ * \li Syntax: word-delete-forward [confirm]
+ * \li Params: confirm: Select big insets, do not directly delete them.
  * \endvar
  */
 		{ LFUN_WORD_DELETE_FORWARD, "word-delete-forward", Noop, Edit },
diff --git a/src/Text3.cpp b/src/Text3.cpp
index 8bbac0eee2..d52ee5832d 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -750,7 +750,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		if (cur.selection())
 			cutSelection(cur, false);
 		else
-			deleteWordForward(cur, cmd.getArg(0) == "force");
+			deleteWordForward(cur, cmd.getArg(0) != "confirm");
 		finishChange(cur, false);
 		break;
 
@@ -758,7 +758,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		if (cur.selection())
 			cutSelection(cur, false);
 		else
-			deleteWordBackward(cur, cmd.getArg(0) == "force");
+			deleteWordBackward(cur, cmd.getArg(0) != "confirm");
 		finishChange(cur, false);
 		break;
 
@@ -1225,7 +1225,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 			if (cur.pos() == cur.paragraph().size())
 				// Par boundary, force full-screen update
 				singleParUpdate = false;
-			else if (cmd.getArg(0) != "force" && cur.confirmDeletion()) {
+			else if (cmd.getArg(0) == "confirm" && cur.confirmDeletion()) {
 				cur.resetAnchor();
 				cur.selection(true);
 				cur.posForward();
@@ -1250,7 +1250,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 				// Par boundary, full-screen update
 				if (par_boundary)
 					singleParUpdate = false;
-				else if (cmd.getArg(0) != "force" && cur.confirmDeletion(true)) {
+				else if (cmd.getArg(0) == "confirm" && cur.confirmDeletion(true)) {
 					cur.resetAnchor();
 					cur.selection(true);
 					cur.posBackward();
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 673a62d575..0579640061 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -827,8 +827,8 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
 		else if (!cur.inMacroMode())
 			cur.recordUndoSelection();
 		// if the inset can not be removed from within, delete it
-		if (!cur.backspace(cmd.getArg(0) == "force")) {
-			FuncRequest newcmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD, "force");
+		if (!cur.backspace(cmd.getArg(0) != "confirm")) {
+			FuncRequest newcmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
 			cur.innerText()->dispatch(cur, newcmd);
 		}
 		break;
@@ -841,8 +841,8 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
 		else
 			cur.recordUndoSelection();
 		// if the inset can not be removed from within, delete it
-		if (!cur.erase(cmd.getArg(0) == "force")) {
-			FuncRequest newcmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD, "force");
+		if (!cur.erase(cmd.getArg(0) != "confirm")) {
+			FuncRequest newcmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
 			cur.innerText()->dispatch(cur, newcmd);
 		}
 		break;
-- 
2.25.1

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

Reply via email to