Skip to content

Commit

Permalink
Avoid unwanted selection when infobar shows by mouse click in Scintilla
Browse files Browse the repository at this point in the history
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 geany#3906.
  • Loading branch information
techee committed Jun 14, 2024
1 parent 0528657 commit abbe1c9
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}


Expand Down Expand Up @@ -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];
Expand All @@ -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;
}


Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit abbe1c9

Please sign in to comment.