Commit 01f9418a authored by Ricardo Silva Veloso's avatar Ricardo Silva Veloso
Browse files

python-indenter: insert matching brace for docstring

parent 9c4dfc92
Pipeline #72210 passed with stages
in 49 minutes and 46 seconds
......@@ -266,9 +266,9 @@ copy_indent_minus_tab (IdePythonIndenter *python,
static gchar *
copy_indent_plus_hash (IdePythonIndenter *python,
GtkTextIter *begin,
GtkTextIter *end,
GtkTextIter *copy)
GtkTextIter *begin,
GtkTextIter *end,
GtkTextIter *copy)
{
GString *str;
gchar *copied;
......@@ -282,6 +282,39 @@ copy_indent_plus_hash (IdePythonIndenter *python,
return g_string_free (str, FALSE);
}
static gchar *
maybe_insert_match (IdePythonIndenter *python,
GtkTextIter *begin,
GtkTextIter *end,
GtkTextIter *iter,
gint *cursor_offset,
gunichar ch)
{
GtkTextIter after = *begin;
GString *str;
gunichar match;
gint i = 3;
if (gtk_text_iter_get_char (&after) == ch)
return NULL;
if (!gtk_text_iter_backward_chars (iter, 2))
return NULL;
while ((match = gtk_text_iter_get_char (iter)) && i--)
if (match != ch)
return NULL;
*cursor_offset -= 3;
if (ch == '\'')
str = g_string_new ("'''");
else
str = g_string_new ("\"\"\"");
return g_string_free (str, FALSE);
}
static gboolean
find_bracket (gunichar ch,
gpointer state)
......@@ -716,6 +749,14 @@ ide_python_indenter_format (IdeIndenter *indenter,
return maybe_unindent_else_or_elif (python, text_view, begin, end);
}
if (event->keyval == GDK_KEY_apostrophe || event->keyval == GDK_KEY_quotedbl)
{
if (ch != '\'' && ch != '"')
return NULL;
return maybe_insert_match (python, begin, end, &iter, cursor_offset, ch);
}
iter = *begin;
line = gtk_text_iter_get_line (&iter);
......@@ -818,8 +859,7 @@ ide_python_indenter_is_trigger (IdeIndenter *indenter,
guint modifier_state;
modifier_state = gdk_keymap_get_modifier_state (keymap);
if (modifier_state & GDK_SHIFT_MASK ||
modifier_state & GDK_CONTROL_MASK ||
if (modifier_state & GDK_CONTROL_MASK ||
modifier_state & GDK_MOD1_MASK)
return FALSE;
......@@ -827,6 +867,8 @@ ide_python_indenter_is_trigger (IdeIndenter *indenter,
{
case GDK_KEY_e:
case GDK_KEY_f:
case GDK_KEY_apostrophe:
case GDK_KEY_quotedbl:
case GDK_KEY_KP_Enter:
case GDK_KEY_Return:
return TRUE;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment