geany-plugins icon indicating copy to clipboard operation
geany-plugins copied to clipboard

addons: automatic enclose takes over when undesired (e.g. when VTE has the focus)

Open 3-14152898 opened this issue 1 year ago • 4 comments

Hi.

I've been using Geany for a couple decades. I also use the virtual terminal (VTE) a lot with my projects. So do I use addons' "automatically enclose text without requiring shortcuts" option a lot, too.

The trouble is the said addon module takes over even when the VTE is active and, for instance, when I type single or double quotes or even parentheses in the VTE, they are intercepted by the addon to enclose any selected text in the window that is currently visible. If any selection exists in the window, the character is swallowed and the selection is enclosed with that character. Consequently it is not echoed in the VTE.

This situation happens frequently, especially when I need to select something in a window and middle-click inside the VTE to paste it. I tried to pick the habit to also left-click once in the VTE to cancel the selection but it doesn't work (read: I forget most of the time). I tried coping with the bug but it doesn't work either; instead it has become extremely annoying. I've tried multiple times to inspect the source code and fix it myself in order to submit a patch and avoid bothering the developers but I have to confess I'm completely lost and have no idea what to do and how.

Is it possible to disable the enclosing features (both options, with and without shortcuts) at least when the VTE is active? See the picture below as to the options I'm referring to, with the one I use highlighted by me, which is the most critical: image

I have Geany version 2.0-1 on Manjaro Linux x86_64, built on 23rd Oct. 2023.

3-14152898 avatar Aug 17 '24 11:08 3-14152898

FTR this is linked to issue #1181

I'll have to bump this as it is extremely annoying. The addon is also extremely useful and I'm doubly annoyed by such contradicting effects. I've tried to inspect the code, I really tried however I can't find my way and am lost at determining where to fix, what and how :( . I'm afraid the task is too complicated for me. I'm really desperate on this one.

EDIT: more precisely, I guess where is in geany-plugins/addons/src/ao_wrapwords.c around line 96 and would resolve to something like if (!<window of the current document has the focus>) return FALSE;. Only trouble is I have absolutely zero idea how to implement that test. The hierarchy is too dense for me to understand what I'm reading. This is not a judgement, I seem to have my limitations, which is already hard to swallow when you're a programming nerd...

3-14152898 avatar Aug 20 '25 09:08 3-14152898

Finally I changed my mind and used another technique for determining if/how Geany keeps track of focus. I've investigated further and came up with the following fix:

Bug fix for #1370

Description: automatic enclose takes over when undesired (e.g. when
the VTE has the focus)

In its former state, the addon doesn't verify the document window has
the focus and happens to "steal" keystrokes when it shouldn't. This
patch addresses the issue. It has been tested with Geany 2.0 on an
Arch-based distribution aka Manjaro.

```diff
--- old/addons/src/ao_wrapwords.c	2025-08-22 16:05:28.887085295 +0200
+++ new/addons/src/ao_wrapwords.c	2025-08-22 16:33:33.008914259 +0200
@@ -90,10 +90,13 @@
 	if (!auto_enabled)
 		return FALSE;
 
-	if (document_get_current () == NULL)
+	sci_obj = document_get_current ()->editor->sci;
+	if (sci_obj == NULL)
 		return FALSE;
 
-	sci_obj = document_get_current ()->editor->sci;
+	// Prevent the addon from highjacking key strokes when not in focus
+	if (!gtk_widget_has_focus(GTK_WIDGET(sci_obj)))
+		return FALSE;
 
 	if (sci_get_selected_text_length (sci_obj) < 2)
 		return FALSE;```

I've tested it against Geany 2.0 on my machine and the fix is indeed effective: selection is only enclosed iif the document window has the focus, not otherwise. It was simpler than I anticipated in the end. I hope this is done the right way though and I missed nothing critical.

Have a nice day/week-end.

π

3-14152898 avatar Aug 22 '25 14:08 3-14152898

Please post your changes as plain text here or better open a PR instead of attaching ZIP archives.

eht16 avatar Aug 24 '25 14:08 eht16

Done.

3-14152898 avatar Aug 27 '25 09:08 3-14152898