SF.net SVN: geany:[3948] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Fri Jul 10 14:03:17 UTC 2009


Revision: 3948
          http://geany.svn.sourceforge.net/geany/?rev=3948&view=rev
Author:   ntrel
Date:     2009-07-10 14:03:16 +0000 (Fri, 10 Jul 2009)

Log Message:
-----------
Delay highlighting matching braces by 100ms, which speeds up
scrolling with the arrow keys.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/editor.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-07-10 09:00:37 UTC (rev 3947)
+++ trunk/ChangeLog	2009-07-10 14:03:16 UTC (rev 3948)
@@ -1,3 +1,10 @@
+2009-07-10  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/editor.c:
+   Delay highlighting matching braces by 100ms, which speeds up
+   scrolling with the arrow keys.
+
+
 2009-07-09  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
 
  * src/highlighting.c:

Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c	2009-07-10 09:00:37 UTC (rev 3947)
+++ trunk/src/editor.c	2009-07-10 14:03:16 UTC (rev 3948)
@@ -3032,19 +3032,31 @@
 }
 
 
-static void editor_highlight_braces(GeanyEditor *editor, gint cur_pos)
+static gboolean brace_timeout_active = FALSE;
+
+static gboolean delay_match_brace(G_GNUC_UNUSED gpointer user_data)
 {
-	gint brace_pos = cur_pos - 1;
-	gint end_pos;
+	GeanyDocument *doc = document_get_current();
+	GeanyEditor *editor;
+	gint brace_pos = GPOINTER_TO_INT(user_data);
+	gint end_pos, cur_pos;
 
-	if (! utils_isbrace(sci_get_char_at(editor->sci, brace_pos), editor_prefs.brace_match_ltgt))
+	brace_timeout_active = FALSE;
+	if (!doc)
+		return FALSE;
+
+	editor = doc->editor;
+	cur_pos = sci_get_current_position(editor->sci) - 1;
+
+	if (cur_pos != brace_pos)
 	{
-		brace_pos++;
-		if (! utils_isbrace(sci_get_char_at(editor->sci, brace_pos), editor_prefs.brace_match_ltgt))
+		cur_pos++;
+		if (cur_pos != brace_pos)
 		{
-			SSM(editor->sci, SCI_SETHIGHLIGHTGUIDE, 0, 0);
-			SSM(editor->sci, SCI_BRACEBADLIGHT, (uptr_t)-1, 0);
-			return;
+			/* we have moved past the original brace_pos, but after the timeout
+			 * we may now be on a new brace, so check again */
+			editor_highlight_braces(editor, cur_pos);
+			return FALSE;
 		}
 	}
 	end_pos = sci_find_matching_brace(editor->sci, brace_pos);
@@ -3061,9 +3073,33 @@
 		SSM(editor->sci, SCI_SETHIGHLIGHTGUIDE, 0, 0);
 		SSM(editor->sci, SCI_BRACEBADLIGHT, brace_pos, 0);
 	}
+	return FALSE;
 }
 
 
+static void editor_highlight_braces(GeanyEditor *editor, gint cur_pos)
+{
+	gint brace_pos = cur_pos - 1;
+
+	if (! utils_isbrace(sci_get_char_at(editor->sci, brace_pos), editor_prefs.brace_match_ltgt))
+	{
+		brace_pos++;
+		if (! utils_isbrace(sci_get_char_at(editor->sci, brace_pos), editor_prefs.brace_match_ltgt))
+		{
+			SSM(editor->sci, SCI_SETHIGHLIGHTGUIDE, 0, 0);
+			SSM(editor->sci, SCI_BRACEBADLIGHT, (uptr_t)-1, 0);
+			return;
+		}
+	}
+	if (!brace_timeout_active)
+	{
+		brace_timeout_active = TRUE;
+		/* delaying matching makes scrolling faster e.g. holding down arrow keys */
+		g_timeout_add(100, delay_match_brace, GINT_TO_POINTER(brace_pos));
+	}
+}
+
+
 static gboolean in_block_comment(gint lexer, gint style)
 {
 	switch (lexer)


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list