SF.net SVN: geany:[2982] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Mon Sep 22 11:57:15 UTC 2008


Revision: 2982
          http://geany.svn.sourceforge.net/geany/?rev=2982&view=rev
Author:   ntrel
Date:     2008-09-22 11:57:14 +0000 (Mon, 22 Sep 2008)

Log Message:
-----------
Fix HTML table autocompletion when the indent type is 'Tabs &
Spaces' (#2118289).
Add some useful functions count_indent_size(),
string_append_indent_width().

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

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-09-22 11:12:54 UTC (rev 2981)
+++ trunk/ChangeLog	2008-09-22 11:57:14 UTC (rev 2982)
@@ -5,6 +5,11 @@
    auto-indentation for all editors.
    Don't disable the auto-indent document pref when switching back to a
    document with auto-indent turned off.
+ * src/editor.c:
+   Fix HTML table autocompletion when the indent type is 'Tabs &
+   Spaces' (#2118289).
+   Add some useful functions count_indent_size(),
+   string_append_indent_width().
 
 
 2008-09-21  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>

Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c	2008-09-22 11:12:54 UTC (rev 2981)
+++ trunk/src/editor.c	2008-09-22 11:57:14 UTC (rev 2982)
@@ -1897,12 +1897,69 @@
 }
 
 
+static gsize count_indent_size(GeanyEditor *editor, const gchar *base_indent)
+{
+	const gchar *ptr;
+	gsize tab_size = sci_get_tab_width(editor->sci);
+	gsize count = 0;
+
+	g_return_val_if_fail(base_indent, 0);
+
+	for (ptr = base_indent; *ptr != 0; ptr++)
+	{
+		switch (*ptr)
+		{
+			case ' ':
+				count++;
+				break;
+			case '\t':
+				count += tab_size;
+				break;
+		}
+	}
+	return count;
+}
+
+
+static void string_append_indent_width(GString *str, const GeanyIndentPrefs *iprefs,
+		gsize width)
+{
+	gchar *ws = get_whitespace(iprefs, width);
+
+	g_string_append(str, ws);
+	g_free(ws);
+}
+
+
+static gchar *get_table_body(GeanyEditor *editor, const gchar *base_indent)
+{
+	gsize base_size = count_indent_size(editor, base_indent);
+	const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor);
+	gsize indent_width = iprefs->width;
+	GString *str = g_string_new("\n");
+
+	if (! editor->auto_indent)
+		indent_width = 0;
+
+	string_append_indent_width(str, iprefs, base_size + indent_width);
+	g_string_append(str, "<tr>\n");
+	string_append_indent_width(str, iprefs, base_size + indent_width + indent_width);
+	g_string_append(str, "<td>\n");
+	string_append_indent_width(str, iprefs, base_size + indent_width + indent_width);
+	g_string_append(str, "</td>\n");
+	string_append_indent_width(str, iprefs, base_size + indent_width);
+	g_string_append(str, "</tr>\n");
+	string_append_indent_width(str, iprefs, base_size);
+
+	return g_string_free(str, FALSE);
+}
+
+
 static void auto_table(GeanyEditor *editor, gint pos)
 {
 	ScintillaObject *sci = editor->sci;
 	gchar *table;
 	gint indent_pos;
-	gchar *indent_str;
 
 	if (SSM(sci, SCI_GETLEXER, 0, 0) != SCLEX_HTML) return;
 
@@ -1925,18 +1982,8 @@
 	}
 
 	/* get indent string for generated code */
-	if (! editor->auto_indent)
-		indent_str = g_strdup("");
-	else
-		indent_str = get_single_indent(editor);
-
-	table = g_strconcat("\n", indent, indent_str, "<tr>\n",
-						indent, indent_str, indent_str, "<td>\n",
-						indent, indent_str, indent_str, "</td>\n",
-						indent, indent_str, "</tr>\n",
-						indent, NULL);
+	table = get_table_body(editor, indent);
 	sci_insert_text(sci, pos, table);
-	g_free(indent_str);
 	g_free(table);
 }
 


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