我遇到了与 GtkSourceView4 相关的这个问题,我想了解如何避免它
(litos:4353): GtkSourceView-CRITICAL **: 12:57:09.105: Highlighting a single line took too much time, syntax highlighting will be disabled
当我尝试插入标签时会发生这种情况,<h1>, <h2>
但不插入其他标签,如<p>, <code>
等。这似乎是一个已经提交https://bugzilla.redhat.com/show_bug.cgi?id=1882163没有解决方案的错误。
由于我正在使用使用 GtkSourceView4 的其他程序并且突出显示正常工作,这可能是由于 API 使用不当,特别是 function gtk_source_buffer_set_highlight_syntax
。我正在使用 Gtksourceview4 和 GTK3。这是对突出显示文本感兴趣的代码的一部分
void open_file(struct lit *litos, gboolean template)
{
gboolean read_file_status;
GError *error;
char* contents;
gint page = gtk_notebook_get_current_page(litos->notebook);
char *filename = litos->filename[page];
read_file_status = g_file_get_contents(filename, &contents, NULL, &error);
if (read_file_status == FALSE)
{
g_error("error opening file: %s\n",error && error->message ? error->message : "No Detail");
return;
}
GtkTextBuffer *current_buffer = get_current_buffer(litos);
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(current_buffer), contents, -1);
highlight_buffer(litos);
if (template)
{
litos->filename[page] = NULL;
filename = "Unsaved";
}
gtk_notebook_set_tab_label_text(
litos->notebook,
gtk_notebook_get_nth_page(
litos->notebook,
page
),
filename
);
gtk_notebook_set_menu_label_text(
litos->notebook,
gtk_notebook_get_nth_page(
litos->notebook,
page
),
filename
);
}
void highlight_buffer(struct lit *litos) /* Apply different font styles depending on file extension .html .c, etc */
{
gint page = gtk_notebook_get_current_page(litos->notebook);
GtkSourceLanguageManager *lm = gtk_source_language_manager_get_default();
GtkSourceLanguage *lang = gtk_source_language_manager_guess_language(lm, litos->filename[page], NULL);
gtk_source_buffer_set_language (litos->buffer, lang);
if (lang != NULL)
gtk_source_buffer_set_highlight_syntax (litos->buffer, TRUE);
}
你可以在这里找到完整的程序https://github.com/gioretikto/litos