Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ricardo Silva Veloso
gnome-builder
Commits
01f9418a
Commit
01f9418a
authored
Aug 14, 2018
by
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
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/plugins/python-pack/ide-python-indenter.c
View file @
01f9418a
...
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment