GNOME Bugzilla – Bug 760984
View not re-drawn when enabling/disabling syntax highlighting
Last modified: 2016-06-19 18:23:14 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
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)
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);
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
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.
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?
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
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.
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
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.
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
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.
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)
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.
Filed bug #767565, related to this one.
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.
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.
(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).
(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.
(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 ^^
(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.