Fix HTML table autocompletion when the indent type is 'Tabs &
Spaces' (#2118289). Add some useful functions count_indent_size(), string_append_indent_width(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2982 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
a00dc77177
commit
3828682705
@ -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>
|
||||
|
71
src/editor.c
71
src/editor.c
@ -1897,12 +1897,69 @@ static gboolean handle_xml(GeanyEditor *editor, gchar ch)
|
||||
}
|
||||
|
||||
|
||||
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 @@ static void auto_table(GeanyEditor *editor, gint pos)
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user