[gtksourceview] contextengine: fix first-line-only in presense of BOM
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] contextengine: fix first-line-only in presense of BOM
- Date: Tue, 1 Dec 2020 18:43:46 +0000 (UTC)
commit e46d7a6489fffb7131f8a71cba13edba12adb3c2
Author: Christian Hergert <chergert redhat com>
Date: Tue Dec 1 10:40:10 2020 -0800
contextengine: fix first-line-only in presense of BOM
This fixes an issue where we don't correctly highlight the first line with
a shebang if we found a BOM sequence. We need to check against an offset
of zero or one depending on the presense of a BOM (which is always a single
character GtkTextIter in the buffer).
I still see some issues with #168 in that the rest of the file is still
not highlighted until an incremental change comes in, but at least this
ensures the first line gets correctly highlighted.
Related #168
gtksourceview/gtksourcecontextengine.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/gtksourceview/gtksourcecontextengine.c b/gtksourceview/gtksourcecontextengine.c
index 3d739ac8..6ce3a5ad 100644
--- a/gtksourceview/gtksourcecontextengine.c
+++ b/gtksourceview/gtksourcecontextengine.c
@@ -4175,7 +4175,7 @@ ancestor_ends_here (Segment *state,
* @line: analyzed line.
* @line_pos: position inside @line, bytes.
* @new_state: where to store the new state.
- * @hint: child of @state used to optimize tree operations.
+ * @had_bom: if a BOM was found in the buffer
*
* Verifies if a context starts or ends in @line at @line_pos of after it.
* If the contexts starts or ends here @new_state and @line_pos are updated.
@@ -4187,7 +4187,8 @@ next_segment (GtkSourceContextEngine *ce,
Segment *state,
LineInfo *line,
gint *line_pos,
- Segment **new_state)
+ Segment **new_state,
+ gboolean had_bom)
{
gint pos = *line_pos;
@@ -4242,7 +4243,7 @@ next_segment (GtkSourceContextEngine *ce,
if (!HAS_OPTION (child_def->u.definition, EXTEND_PARENT) && context_end_found)
try_this = FALSE;
- if (HAS_OPTION (child_def->u.definition, FIRST_LINE_ONLY) && line->start_at != 0)
+ if (HAS_OPTION (child_def->u.definition, FIRST_LINE_ONLY) && line->start_at !=
had_bom)
try_this = FALSE;
if (HAS_OPTION (child_def->u.definition, ONCE_ONLY))
@@ -4419,7 +4420,7 @@ delete_zero_length_segments (GtkSourceContextEngine *ce,
* @ce: #GtkSourceContextEngine.
* @state: the state at the beginning of line.
* @line: the line.
- * @hint: a child of @state around start of line, to make it faster.
+ * @had_bom: if the buffer had a BOM
*
* Finds contexts at the line and updates the syntax tree on it.
*
@@ -4428,7 +4429,8 @@ delete_zero_length_segments (GtkSourceContextEngine *ce,
static Segment *
analyze_line (GtkSourceContextEngine *ce,
Segment *state,
- LineInfo *line)
+ LineInfo *line,
+ gboolean had_bom)
{
gint line_pos = 0;
GList *end_segments = NULL;
@@ -4447,7 +4449,7 @@ analyze_line (GtkSourceContextEngine *ce,
{
Segment *new_state = NULL;
- if (!next_segment (ce, state, line, &line_pos, &new_state))
+ if (!next_segment (ce, state, line, &line_pos, &new_state, had_bom))
break;
if (g_timer_elapsed (timer, NULL) * 1000 > MAX_TIME_FOR_ONE_LINE)
@@ -5312,6 +5314,7 @@ update_syntax (GtkSourceContextEngine *ce,
gint line_start_offset, line_end_offset;
gint analyzed_end;
gboolean first_line = FALSE;
+ gboolean had_bom = FALSE;
GTimer *timer;
buffer = ce->buffer;
@@ -5371,6 +5374,7 @@ update_syntax (GtkSourceContextEngine *ce,
c = gtk_text_iter_get_char (&start_iter);
if (IS_BOM (c))
{
+ had_bom = TRUE;
gtk_text_iter_forward_char (&start_iter);
start_offset = gtk_text_iter_get_offset (&start_iter);
segment_remove (ce, invalid);
@@ -5442,7 +5446,7 @@ update_syntax (GtkSourceContextEngine *ce,
if (ce->hint2 != NULL && ce->hint2->parent != state)
ce->hint2 = NULL;
- state = analyze_line (ce, state, &line);
+ state = analyze_line (ce, state, &line, had_bom);
/* At this point analyze_line() could have disabled highlighting */
if (ce->disabled)
@@ -5529,7 +5533,7 @@ update_syntax (GtkSourceContextEngine *ce,
line_end_offset = gtk_text_iter_get_offset (&line_end);
}
- first_line = (0 == line_start_offset);
+ first_line = start_offset == line_start_offset;
}
if (analyzed_end == gtk_text_buffer_get_char_count (buffer))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]