Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Fri, 14 Jun 2024 11:22:19 UTC Commit: abbe1c984f6da1f1a1fa89851b9d010e5d3a19ae https://github.com/geany/geany/commit/abbe1c984f6da1f1a1fa89851b9d010e5d3a19...
Log Message: ----------- Avoid unwanted selection when infobar shows by mouse click in Scintilla
Steps to reporduce: 1. Open file A in Geany 2. In a separate window, edit the same file (using e.g. vi) 3. Click to Geany editor so it regains focus 4. An infobar appears. As it appears, several lines in editor are selected
The selection is caused by the fact that as the same time the editor is being clicked, Geany checks if the document was modified and shows the info bar. The info bar makes the Scintilla editor smaller and it scrolls by the amount of lines corresponding to the height of the infobar. All this happens in the click handler and for Scintilla it appears as if the mouse button was presses during the scroll and it makes the selection.
Showing infobars on idle seems to fix the problem.
Fixes #3906.
Modified Paths: -------------- src/document.c
Modified: src/document.c 34 lines changed, 26 insertions(+), 8 deletions(-) =================================================================== @@ -3602,19 +3602,23 @@ static void enable_key_intercept(GeanyDocument *doc, GtkWidget *bar) }
-static void monitor_reload_file(GeanyDocument *doc) +static gboolean monitor_reload_file_idle(gpointer data) { + GeanyDocument *doc = data; + + if (doc != document_get_current()) + return G_SOURCE_REMOVE; + if (! doc->changed && file_prefs.reload_clean_doc_on_file_change) { document_reload_force(doc, doc->encoding); - return; + return G_SOURCE_REMOVE; }
- gchar *base_name = g_path_get_basename(doc->file_name); - /* show this message only once */ if (doc->priv->info_bars[MSG_TYPE_RELOAD] == NULL) { + gchar *base_name = g_path_get_basename(doc->file_name); GtkWidget *bar;
bar = document_show_message(doc, GTK_MESSAGE_QUESTION, on_monitor_reload_file_response, @@ -3628,8 +3632,10 @@ static void monitor_reload_file(GeanyDocument *doc) protect_document(doc); doc->priv->info_bars[MSG_TYPE_RELOAD] = bar; enable_key_intercept(doc, bar); + g_free(base_name); } - g_free(base_name); + + return G_SOURCE_REMOVE; }
@@ -3657,8 +3663,13 @@ static void on_monitor_resave_missing_file_response(GtkWidget *bar, }
-static void monitor_resave_missing_file(GeanyDocument *doc) +static gboolean monitor_resave_missing_file_idle(gpointer data) { + GeanyDocument *doc = data; + + if (doc != document_get_current()) + return G_SOURCE_REMOVE; + if (doc->priv->info_bars[MSG_TYPE_RESAVE] == NULL) { GtkWidget *bar = doc->priv->info_bars[MSG_TYPE_RELOAD]; @@ -3682,6 +3693,8 @@ static void monitor_resave_missing_file(GeanyDocument *doc) doc->priv->info_bars[MSG_TYPE_RESAVE] = bar; enable_key_intercept(doc, bar); } + + return G_SOURCE_REMOVE; }
@@ -3723,15 +3736,20 @@ gboolean document_check_disk_status(GeanyDocument *doc, gboolean force) locale_filename = utils_get_locale_from_utf8(doc->file_name); if (!get_mtime(locale_filename, &mtime)) { - monitor_resave_missing_file(doc); + /* document_check_disk_status() call may be a result of a mouse click + * inside Scintilla by which Geany gains focus and showing the info bar + * during the mouse click leads to text selection as Scintilla scrolls + * because the infobar makes the Scintilla widget smaller. */ + g_idle_add(monitor_resave_missing_file_idle, doc); /* doc may be closed now */ ret = TRUE; } else if (doc->priv->mtime < mtime) { /* make sure the user is not prompted again after he cancelled the "reload file?" message */ doc->priv->mtime = mtime; - monitor_reload_file(doc); + /* see above for the idle call explanation */ + g_idle_add(monitor_reload_file_idle, doc); /* doc may be closed now */ ret = TRUE; }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).