After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 760984 - View not re-drawn when enabling/disabling syntax highlighting
View not re-drawn when enabling/disabling syntax highlighting
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: General
unspecified
Other Linux
: Normal normal
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks:
 
 
Reported: 2016-01-22 12:22 UTC by Andre Miranda
Modified: 2016-06-19 18:23 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Andre Miranda 2016-01-22 12:22:39 UTC
We are having troubles with Mousepad in order to disable highlighting. Calling gtk_source_buffer_set_style_scheme(NULL) results in:
(mousepad:16351): GtkSourceView-CRITICAL **: _gtk_source_style_scheme_apply: assertion 'GTK_SOURCE_IS_STYLE_SCHEME (scheme)' failed

We thought as a workaround to create a none.xml style and load it, but it's too kludgy IMHO. It seems the behavior regarding NULL scheme has changed(I'm not sure), so I'd like to know if this change was intentional and if there is another way to disable highlighting.

More details on the downstream bug: https://bugzilla.xfce.org/show_bug.cgi?id=11663
Comment 1 Paolo Borelli 2016-01-22 13:33:54 UTC
To disable syntax highlighting you can simply set the highlight-syntax property of GtkSourceBuffer, for instance with 

gtk_source_buffer_set_highlight_syntax(buffer, FALSE)
Comment 2 Andre Miranda 2016-01-22 15:18:59 UTC
Hi Paolo, thanks for the tip.
This was attempt:

if (g_strcmp0 (scheme_id, "none") == 0)
  gtk_source_buffer_set_highlight_syntax(buffer, FALSE);
else
  {
    gtk_source_buffer_set_highlight_syntax(buffer, TRUE);
    gtk_source_buffer_set_style_scheme (buffer, scheme);
  }

I kinda works, but for themes with colored background(e.g. Cobalt and Oblivion), the background color is kept after gtk_source_buffer_set_highlight_syntax(buffer, FALSE);
Comment 3 Paolo Borelli 2016-01-22 16:15:36 UTC
I am a bit lost on the what are you trying to do (sorry, I could not read the whole linked bug, it is pretty long...)

Seems strange to set the highlighting on or off depending on the style scheme... they are two orthogonal things. Anyway, you could special case "none" to set back the "classic" scheme (which takes the bg color from gtk) and set the highlighting off
Comment 4 Andre Miranda 2016-01-22 16:46:04 UTC
Mousepad has a default scheme called "None" which disables highlighting.
This style scheme is not a XML file, just an entry on menu.
The current code just does this: gtk_source_buffer_set_style_scheme(NULL).
Apparently it used to work fine, but now leads to errors, so we're trying to avoid those errors and keep that option untouched.

What you proposed seems to do the trick and is a much better(simpler) approach than my previous workaround.

Closing this bug as NOTABUG, thanks.
Comment 5 Andre Miranda 2016-01-22 17:24:05 UTC
Unfortunately there's a minor drawback.
If the option None was selected(highlight = off, scheme = classic) and immediately selecting the Classic scheme, the scheme won't really change, only highlight is turned on, so the text Buffer is not updated, the text is mostly black on white, only after scrolling or text selection it gets highlighted.
Taking a look at the source, this is due gtk_source_buffer_set_style_scheme returning when the scheme hasn't changed, which is the case.

Any thoughts?
Comment 6 Paolo Borelli 2016-01-22 17:29:41 UTC
try to first set the classic them and *then* turn on highlighting. If turning on highlighting does not refresh the visible text it is a bug
Comment 7 Andre Miranda 2016-01-22 18:38:44 UTC
Nope, it didn't fix the problem.

Here's my fork:
https://github.com/andreldm/mousepad

And here's the commit:
https://github.com/andreldm/mousepad/commit/5a2ed7504f0f491e1f858ee2f262e4b5a6122d1f

I'm using gtksourceview 3.18.1-1.
Comment 8 Paolo Borelli 2016-01-22 18:45:26 UTC
I guess a hack would be to try to gtk_widget_queue_draw on the view.

If that works, we should probably do that in gtksourceview itself: connect to buffer::notify:highligh-syntax and refresh the view. Obviously if all this works, a patch would be very much welcome :)

I am reopening for now
Comment 9 Andre Miranda 2016-01-22 19:35:24 UTC
I have used "gtk_widget_queue_draw (GTK_WIDGET (view));" (where view is an instance of MousepadView, subclass of GtkSourceView), but it didn't fix the problem either.
Comment 10 Paolo Borelli 2016-01-23 09:03:24 UTC
I just tested with gtksourceview test-widget (you can find it in the tests subdir of gtksourceview) and toggling the "Highlight Syntax" checkbutton redraws the current view even if the theme stays "classic".

Can you try too? maybe it is something different in gtk

If it works also for you, we need to understand what is different from your code
Comment 11 Andre Miranda 2016-01-23 14:24:19 UTC
There were some glitches with test-widget too. Here's a video:
https://www.youtube.com/watch?v=hejhwXej7sw

The test-widget was compiled from gtksourceview-3.18.2 source tarball.
Comment 12 Paolo Borelli 2016-01-24 08:28:49 UTC
the same thing seems to work on my machine... I wonder if it is a problem in gtk (I am trying with gtk from git master)
Comment 13 Sébastien Wilmet 2016-06-12 12:57:18 UTC
Should be fixed with commit 93c3ecccda75af011de6f9465902f91f3b6b0728 (on git master).

Setting a NULL StyleScheme is totally allowed. Disabling only syntax highlighting still uses the StyleScheme (if non-NULL) for other things, which may or may not be what you want to do in Mousepad.
Comment 14 Sébastien Wilmet 2016-06-12 16:40:45 UTC
Filed bug #767565, related to this one.
Comment 15 Sébastien Wilmet 2016-06-15 12:04:41 UTC
There is actually 3 possible things to do:

gtk_source_buffer_set_language (buffer, NULL);
gtk_source_buffer_set_style_scheme (buffer, NULL);
gtk_source_buffer_set_highlight_syntax (buffer, FALSE);

Setting a NULL language disables syntax highlighting, but also remove context classes (no-spell-check etc).

Setting a NULL style scheme also disables syntax highlighting, but disables other GtkSourceView features like the background grid pattern. For current line highlighting and whitespace drawing, when a NULL style scheme is set it takes fallback colors, but it's not ideal and it's better to set the classic or tango style scheme to have better styling.

Setting highlight-syntax to FALSE just disables syntax highlighting.

In Mousepad setting the color scheme to None should be done with setting the highlight-syntax property to FALSE and setting the style scheme to classic or tango.

In gedit, setting the "Highlight Mode" to "Plain Text" sets a NULL language.

The doc in GtkSourceBuffer should be improved, because it's not evident.

Anyway, I'm not sure it makes much sense to have all those possibilities. Disabling syntax highlighting is not very useful to my eyes.
Comment 16 Andre Miranda 2016-06-17 01:35:08 UTC
Hi Sébastien, great job, thanks!
I've tested against git and seems your fixes have solved the problem.

As you mentioned, just setting a NULL style scheme causes the current line highlighting retaining the last scheme color, so I'm following your advice(highlight=FALSE and scheme=classic). I took the chance to simplify the code a bit:
https://github.com/andreldm/mousepad/commit/63ccbaaaefeb7ea1814c72b12b58e2f2239ebd27

I have to admit, disabling the highlight doesn't make much sense to me, but it's a feature that some users might complain if we remove.

Off-topic: I wasn't able to find instructions to build gtksourceview, so I had to google a bit about configure.ac errors(again, since I changed my machine since my last time I had to build gtksourceview), basically I had to install gnome-common, gobject-introspection and vala(Arch Linux here). Maybe this kind of info could be provided on Wiki, README or create a INSTALL file.
Comment 17 Matthew Brush 2016-06-17 02:00:59 UTC
(In reply to Sébastien Wilmet from comment #15)
> Should be fixed with commit [...]

Thanks!

> Anyway, I'm not sure it makes much sense to have all those possibilities.

Just a single "don't apply any colours on the text in the view" seems sufficient.

> Disabling syntax highlighting is not very useful to my eyes.

Some people find syntax highlighting (colouring keywords, comments, etc.) to be distracting (not me, I find it extremely useful).
Comment 18 Sébastien Wilmet 2016-06-17 11:05:58 UTC
(In reply to André Miranda from comment #16)
> Off-topic: I wasn't able to find instructions to build gtksourceview, so I
> had to google a bit about configure.ac errors(again, since I changed my
> machine since my last time I had to build gtksourceview), basically I had to
> install gnome-common, gobject-introspection and vala(Arch Linux here). Maybe
> this kind of info could be provided on Wiki, README or create a INSTALL file.

We use Jhbuild:
https://wiki.gnome.org/Projects/Jhbuild

This should be documented in the README or HACKING. The INSTALL file is generated from the Autotools and is present only in tarballs, not in git.

(In reply to Matthew Brush from comment #17)
> > Disabling syntax highlighting is not very useful to my eyes.
> 
> Some people find syntax highlighting (colouring keywords, comments, etc.) to
> be distracting (not me, I find it extremely useful).

It can be useful to disable syntax highlighting if it is buggy or too colorful.
Comment 19 Andre Miranda 2016-06-17 22:34:51 UTC
(In reply to Sébastien Wilmet from comment #18)
> We use Jhbuild:
> https://wiki.gnome.org/Projects/Jhbuild
> 
> This should be documented in the README or HACKING. The INSTALL file is
> generated from the Autotools and is present only in tarballs, not in git.

Yes, you're right, this information is in README, I should have read it more carefully ^^
Comment 20 Sébastien Wilmet 2016-06-19 18:23:14 UTC
(In reply to André Miranda from comment #19)
> Yes, you're right, this information is in README, I should have read it more
> carefully ^^

You cannot miss it ;) :
https://git.gnome.org/browse/gtksourceview/tree/README#n29

I have now improved the docs, and fixed some remaining issues when setting a NULL StyleScheme. So this bug is now fully fixed normally.