[geany/geany] b361b8: Colourise only the visible area when highlighting typenames

Jiří Techet git-noreply at xxxxx
Wed Feb 17 17:52:35 UTC 2016


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Sat, 12 Dec 2015 14:07:22 UTC
Commit:      b361b83276816633ac5a0d6d391b6f6e8ebe6cf1
             https://github.com/geany/geany/commit/b361b83276816633ac5a0d6d391b6f6e8ebe6cf1

Log Message:
-----------
Colourise only the visible area when highlighting typenames

Colorizing the whole document is rather expensive and unnecessary as
Scintilla colorizes the visible part of the document when scrolling
happens. Instead, colorize only the visible area when highlighting
typenames.


Modified Paths:
--------------
    src/document.c
    src/documentprivate.h
    src/editor.c

Modified: src/document.c
12 lines changed, 8 insertions(+), 4 deletions(-)
===================================================================
@@ -509,8 +509,12 @@ static gint document_get_new_idx(void)
 }
 
 
-static void queue_colourise(GeanyDocument *doc)
+static void queue_colourise(GeanyDocument *doc, gboolean full_colourise)
 {
+	/* make sure we don't override previously set full_colourise=TRUE by FALSE */
+	if (!doc->priv->colourise_needed || !doc->priv->full_colourise)
+		doc->priv->full_colourise = full_colourise;
+
 	/* Colourise the editor before it is next drawn */
 	doc->priv->colourise_needed = TRUE;
 
@@ -1393,7 +1397,7 @@ GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename
 		/* add the text to the ScintillaObject */
 		sci_set_readonly(doc->editor->sci, FALSE);	/* to allow replacing text */
 		sci_set_text(doc->editor->sci, filedata.data);	/* NULL terminated data */
-		queue_colourise(doc);	/* Ensure the document gets colourised. */
+		queue_colourise(doc, TRUE);	/* Ensure the document gets colourised. */
 
 		/* detect & set line endings */
 		editor_mode = utils_get_line_endings(filedata.data, filedata.len);
@@ -2749,7 +2753,7 @@ void document_highlight_tags(GeanyDocument *doc)
 		keywords = g_string_free(keywords_str, FALSE);
 		sci_set_keywords(doc->editor->sci, keyword_idx, keywords);
 		g_free(keywords);
-		queue_colourise(doc); /* force re-highlighting the entire document */
+		queue_colourise(doc, FALSE); /* re-highlight the visible area */
 	}
 }
 
@@ -2810,7 +2814,7 @@ static void document_load_config(GeanyDocument *doc, GeanyFiletype *type,
 		highlighting_set_styles(doc->editor->sci, type);
 		editor_set_indentation_guides(doc->editor);
 		build_menu_update(doc);
-		queue_colourise(doc);
+		queue_colourise(doc, TRUE);
 		doc->priv->symbol_list_sort_mode = type->priv->symbol_list_sort_mode;
 	}
 


Modified: src/documentprivate.h
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -90,6 +90,7 @@ typedef struct GeanyDocumentPrivate
 	/* Used so Undo/Redo works for encoding changes. */
 	FileEncoding	 saved_encoding;
 	gboolean		 colourise_needed;	/* use document.c:queue_colourise() instead */
+	gboolean		 full_colourise;
 	gint			 line_count;		/* Number of lines in the document. */
 	gint			 symbol_list_sort_mode;
 	/* indicates whether a file is on a remote filesystem, works only with GIO/GVfs */


Modified: src/editor.c
26 lines changed, 21 insertions(+), 5 deletions(-)
===================================================================
@@ -4687,12 +4687,28 @@ static gboolean editor_check_colourise(GeanyEditor *editor)
 		return FALSE;
 
 	doc->priv->colourise_needed = FALSE;
-	sci_colourise(editor->sci, 0, -1);
 
-	/* now that the current document is colourised, fold points are now accurate,
-	 * so force an update of the current function/tag. */
-	symbols_get_current_function(NULL, NULL);
-	ui_update_statusbar(NULL, -1);
+	if (doc->priv->full_colourise)
+	{
+		sci_colourise(editor->sci, 0, -1);
+
+		/* now that the current document is colourised, fold points are now accurate,
+		 * so force an update of the current function/tag. */
+		symbols_get_current_function(NULL, NULL);
+		ui_update_statusbar(NULL, -1);
+	}
+	else
+	{
+		gint start_line, end_line, start, end;
+
+		start_line = SSM(doc->editor->sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
+		end_line = start_line + SSM(editor->sci, SCI_LINESONSCREEN, 0, 0);
+		start_line = SSM(editor->sci, SCI_DOCLINEFROMVISIBLE, start_line, 0);
+		end_line = SSM(editor->sci, SCI_DOCLINEFROMVISIBLE, end_line, 0);
+		start = sci_get_position_from_line(editor->sci, start_line);
+		end = sci_get_line_end_position(editor->sci, end_line);
+		sci_colourise(editor->sci, start, end);
+	}
 
 	return TRUE;
 }



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list