From 3be4752a64c39558046ddd5e8b5ab9895b35ceb0 Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 5 Dec 2024 11:16:47 +0100 Subject: [PATCH] Fixed space drawing --- src/source.cpp | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/source.cpp b/src/source.cpp index 90263a2..261c5cc 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -460,20 +460,38 @@ void Source::View::configure() { { #if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 24)) namespace qi = boost::spirit::qi; - qi::symbols location_options; - qi::symbols type_options; - location_options.add("leading", GTK_SOURCE_SPACE_LOCATION_LEADING)("text", GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT)("trailing", GTK_SOURCE_SPACE_LOCATION_TRAILING)("all", GTK_SOURCE_SPACE_LOCATION_ALL); - type_options.add("space", GTK_SOURCE_SPACE_TYPE_SPACE)("tab", GTK_SOURCE_SPACE_TYPE_TAB)("newline", GTK_SOURCE_SPACE_TYPE_NEWLINE)("nbsp", GTK_SOURCE_SPACE_TYPE_NBSP)("all", GTK_SOURCE_SPACE_TYPE_ALL); - std::set location_out; - std::set type_out; - qi::phrase_parse(Config::get().source.show_whitespace_characters.begin(), Config::get().source.show_whitespace_characters.end(), location_options % ',', qi::space, location_out); - qi::phrase_parse(Config::get().source.show_whitespace_characters.begin(), Config::get().source.show_whitespace_characters.end(), type_options % ',', qi::space, type_out); + std::set out; + qi::phrase_parse(Config::get().source.show_whitespace_characters.begin(), Config::get().source.show_whitespace_characters.end(), (+(~qi::char_(','))) % ',', qi::space, out); auto space_drawer = gtk_source_view_get_space_drawer(gobj()); - auto locations = location_out.count(GTK_SOURCE_SPACE_LOCATION_ALL) > 0 ? GTK_SOURCE_SPACE_LOCATION_ALL : static_cast(std::accumulate(location_out.begin(), location_out.end(), 0)); - auto types = type_out.count(GTK_SOURCE_SPACE_TYPE_ALL) > 0 ? GTK_SOURCE_SPACE_TYPE_ALL : static_cast(std::accumulate(type_out.begin(), type_out.end(), 0)); + int locations = GTK_SOURCE_SPACE_LOCATION_NONE; + if(out.count("leading") > 0) + locations |= GTK_SOURCE_SPACE_LOCATION_LEADING; + if(out.count("text") > 0) + locations |= GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT; + if(out.count("trailing") > 0) + locations |= GTK_SOURCE_SPACE_LOCATION_TRAILING; + if(out.count("all") > 0) + locations |= GTK_SOURCE_SPACE_LOCATION_ALL; + int types = GTK_SOURCE_SPACE_TYPE_NONE; + if(out.count("space") > 0) + types |= GTK_SOURCE_SPACE_TYPE_SPACE; + if(out.count("tab") > 0) + types |= GTK_SOURCE_SPACE_TYPE_TAB; + if(out.count("newline") > 0) + types |= GTK_SOURCE_SPACE_TYPE_NEWLINE; + if(out.count("nbsp") > 0) + types |= GTK_SOURCE_SPACE_TYPE_NBSP; + if(out.count("all") > 0) + types |= GTK_SOURCE_SPACE_TYPE_ALL; + if(locations != GTK_SOURCE_SPACE_LOCATION_NONE || types != GTK_SOURCE_SPACE_TYPE_NONE) { - gtk_source_space_drawer_set_types_for_locations(space_drawer, locations, types); + if(locations == GTK_SOURCE_SPACE_LOCATION_NONE) + locations = GTK_SOURCE_SPACE_LOCATION_ALL; + if(types == GTK_SOURCE_SPACE_TYPE_NONE) + types = GTK_SOURCE_SPACE_TYPE_ALL; + gtk_source_space_drawer_set_matrix(space_drawer, nullptr); + gtk_source_space_drawer_set_types_for_locations(space_drawer, static_cast(locations), static_cast(types)); gtk_source_space_drawer_set_enable_matrix(space_drawer, true); } else