Add keybindings for smart indent and indent/deindent by one space.
Fix possible selection errors on commenting multiple lines when using CR/LF line endings. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1705 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
3e494fa3f5
commit
3bcd10b0d8
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
2007-07-16 Enrico Tröger <enrico.troeger@uvena.de>
|
||||||
|
|
||||||
|
* src/document.c, src/editor.c:
|
||||||
|
Fix possible selection errors on commenting multiple lines when using
|
||||||
|
CR/LF line endings.
|
||||||
|
* doc/geany.docbook, src/editor.c, src/editor.h, src/keybindings.c,
|
||||||
|
src/keybindings.h:
|
||||||
|
Add keybindings for smart indent and indent/deindent by one space.
|
||||||
|
|
||||||
|
|
||||||
2007-07-16 Nick Treleaven <nick.treleaven@btinternet.com>
|
2007-07-16 Nick Treleaven <nick.treleaven@btinternet.com>
|
||||||
|
|
||||||
* src/dialogs.c, src/callbacks.c:
|
* src/dialogs.c, src/callbacks.c:
|
||||||
|
@ -1885,12 +1885,27 @@ widget "GeanyPrefsDialog" style "geanyStyle"
|
|||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry>Increase indent</entry>
|
<entry>Increase indent</entry>
|
||||||
<entry>Indents the current line or selection by one tabulator.</entry>
|
<entry>Indents the current line or selection by one tabulator or
|
||||||
|
by spaces in the amount of the tab width setting.</entry>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry>Decrease indent</entry>
|
<entry>Decrease indent</entry>
|
||||||
<entry>Removes one tabulator from the indentation of the current
|
<entry>Removes one tabulator or the amount fo spaces of the tab
|
||||||
line or selection.</entry>
|
width setting from the indentation of the current line or
|
||||||
|
selection.</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry>Increase indent by one space</entry>
|
||||||
|
<entry>Indents the current line or selection by one space.</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry>Decrease indent by one space</entry>
|
||||||
|
<entry>Deindents the current line or selection by one space.</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry>Smart line indent</entry>
|
||||||
|
<entry>Indents the current line or all selected lines with the same
|
||||||
|
intentation as the previous line.</entry>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry>Goto matching brace</entry>
|
<entry>Goto matching brace</entry>
|
||||||
|
@ -1418,7 +1418,8 @@ void document_replace_sel(gint idx, const gchar *find_text, const gchar *replace
|
|||||||
|
|
||||||
first_line = sci_get_line_from_position(doc_list[idx].sci, selection_start);
|
first_line = sci_get_line_from_position(doc_list[idx].sci, selection_start);
|
||||||
// Find the last line with chars selected (not EOL char)
|
// Find the last line with chars selected (not EOL char)
|
||||||
last_line = sci_get_line_from_position(doc_list[idx].sci, selection_end - 1);
|
last_line = sci_get_line_from_position(doc_list[idx].sci,
|
||||||
|
selection_end - utils_get_eol_char_len(idx));
|
||||||
last_line = MAX(first_line, last_line);
|
last_line = MAX(first_line, last_line);
|
||||||
for (line = first_line; line < (first_line + selected_lines); line++)
|
for (line = first_line; line < (first_line + selected_lines); line++)
|
||||||
{
|
{
|
||||||
|
126
src/editor.c
126
src/editor.c
@ -1476,7 +1476,8 @@ gint editor_do_uncomment(gint idx, gint line, gboolean toggle)
|
|||||||
|
|
||||||
first_line = sci_get_line_from_position(doc_list[idx].sci, sel_start);
|
first_line = sci_get_line_from_position(doc_list[idx].sci, sel_start);
|
||||||
// Find the last line with chars selected (not EOL char)
|
// Find the last line with chars selected (not EOL char)
|
||||||
last_line = sci_get_line_from_position(doc_list[idx].sci, sel_end - 1);
|
last_line = sci_get_line_from_position(doc_list[idx].sci,
|
||||||
|
sel_end - utils_get_eol_char_len(idx));
|
||||||
last_line = MAX(first_line, last_line);
|
last_line = MAX(first_line, last_line);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1636,7 +1637,7 @@ void editor_do_comment_toggle(gint idx)
|
|||||||
sci_get_selection_start(doc_list[idx].sci));
|
sci_get_selection_start(doc_list[idx].sci));
|
||||||
// Find the last line with chars selected (not EOL char)
|
// Find the last line with chars selected (not EOL char)
|
||||||
last_line = sci_get_line_from_position(doc_list[idx].sci,
|
last_line = sci_get_line_from_position(doc_list[idx].sci,
|
||||||
sci_get_selection_end(doc_list[idx].sci) - 1);
|
sci_get_selection_end(doc_list[idx].sci) - utils_get_eol_char_len(idx));
|
||||||
last_line = MAX(first_line, last_line);
|
last_line = MAX(first_line, last_line);
|
||||||
|
|
||||||
// detection of HTML vs PHP code, if non-PHP set filetype to XML
|
// detection of HTML vs PHP code, if non-PHP set filetype to XML
|
||||||
@ -1802,7 +1803,8 @@ void editor_do_comment(gint idx, gint line, gboolean allow_empty_lines, gboolean
|
|||||||
|
|
||||||
first_line = sci_get_line_from_position(doc_list[idx].sci, sel_start);
|
first_line = sci_get_line_from_position(doc_list[idx].sci, sel_start);
|
||||||
// Find the last line with chars selected (not EOL char)
|
// Find the last line with chars selected (not EOL char)
|
||||||
last_line = sci_get_line_from_position(doc_list[idx].sci, sel_end - 1);
|
last_line = sci_get_line_from_position(doc_list[idx].sci,
|
||||||
|
sel_end - utils_get_eol_char_len(idx));
|
||||||
last_line = MAX(first_line, last_line);
|
last_line = MAX(first_line, last_line);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2409,6 +2411,124 @@ void editor_select_paragraph(ScintillaObject *sci)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// simple auto indentation to indent the current line with the same indent as the previous one
|
||||||
|
void editor_auto_line_indentation(gint idx, gint pos)
|
||||||
|
{
|
||||||
|
gint i, first_line, last_line;
|
||||||
|
gint first_sel_start, first_sel_end, sel_start, sel_end;
|
||||||
|
|
||||||
|
g_return_if_fail(DOC_IDX_VALID(idx));
|
||||||
|
|
||||||
|
first_sel_start = sci_get_selection_start(doc_list[idx].sci);
|
||||||
|
first_sel_end = sci_get_selection_end(doc_list[idx].sci);
|
||||||
|
|
||||||
|
first_line = sci_get_line_from_position(doc_list[idx].sci, first_sel_start);
|
||||||
|
// Find the last line with chars selected (not EOL char)
|
||||||
|
last_line = sci_get_line_from_position(doc_list[idx].sci,
|
||||||
|
first_sel_end - utils_get_eol_char_len(idx));
|
||||||
|
last_line = MAX(first_line, last_line);
|
||||||
|
|
||||||
|
if (pos == -1)
|
||||||
|
pos = first_sel_start;
|
||||||
|
|
||||||
|
// get previous line and use it for get_indent to use that line
|
||||||
|
// (otherwise it would fail on a line only containing "{" in advanced indentation mode)
|
||||||
|
get_indent(doc_list[idx].sci,
|
||||||
|
sci_get_position_from_line(doc_list[idx].sci, first_line - 1), TRUE);
|
||||||
|
SSM(doc_list[idx].sci, SCI_BEGINUNDOACTION, 0, 0);
|
||||||
|
|
||||||
|
for (i = first_line; i <= last_line; i++)
|
||||||
|
{
|
||||||
|
// skip the first line or if the indentation of the previous and current line are equal
|
||||||
|
if (i == 0 ||
|
||||||
|
SSM(doc_list[idx].sci, SCI_GETLINEINDENTATION, i - 1, 0) ==
|
||||||
|
SSM(doc_list[idx].sci, SCI_GETLINEINDENTATION, i, 0))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
sel_start = SSM(doc_list[idx].sci, SCI_POSITIONFROMLINE, i, 0);
|
||||||
|
sel_end = SSM(doc_list[idx].sci, SCI_GETLINEINDENTPOSITION, i, 0);
|
||||||
|
if (sel_start < sel_end)
|
||||||
|
{
|
||||||
|
SSM(doc_list[idx].sci, SCI_SETSEL, sel_start, sel_end);
|
||||||
|
SSM(doc_list[idx].sci, SCI_DELETEBACK, 0, 0);
|
||||||
|
}
|
||||||
|
sci_insert_text(doc_list[idx].sci, sel_start, indent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set cursor position if there was no selection
|
||||||
|
/// TODO implement selection handling if there was a selection
|
||||||
|
if (first_sel_start == first_sel_end)
|
||||||
|
sci_set_current_position(doc_list[idx].sci,
|
||||||
|
pos - (sel_end - sel_start) + strlen(indent), FALSE);
|
||||||
|
|
||||||
|
SSM(doc_list[idx].sci, SCI_ENDUNDOACTION, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// increase / decrease current line or selection by one space
|
||||||
|
void editor_indentation_by_one_space(gint idx, gint pos, gboolean decrease)
|
||||||
|
{
|
||||||
|
gint i, first_line, last_line, line_start, indentation_end, count = 0;
|
||||||
|
gint sel_start, sel_end, first_line_offset = 0;
|
||||||
|
|
||||||
|
g_return_if_fail(DOC_IDX_VALID(idx));
|
||||||
|
|
||||||
|
sel_start = sci_get_selection_start(doc_list[idx].sci);
|
||||||
|
sel_end = sci_get_selection_end(doc_list[idx].sci);
|
||||||
|
|
||||||
|
first_line = sci_get_line_from_position(doc_list[idx].sci, sel_start);
|
||||||
|
// Find the last line with chars selected (not EOL char)
|
||||||
|
last_line = sci_get_line_from_position(doc_list[idx].sci,
|
||||||
|
sel_end - utils_get_eol_char_len(idx));
|
||||||
|
last_line = MAX(first_line, last_line);
|
||||||
|
|
||||||
|
if (pos == -1)
|
||||||
|
pos = sel_start;
|
||||||
|
|
||||||
|
SSM(doc_list[idx].sci, SCI_BEGINUNDOACTION, 0, 0);
|
||||||
|
|
||||||
|
for (i = first_line; i <= last_line; i++)
|
||||||
|
{
|
||||||
|
indentation_end = SSM(doc_list[idx].sci, SCI_GETLINEINDENTPOSITION, i, 0);
|
||||||
|
if (decrease)
|
||||||
|
{
|
||||||
|
line_start = SSM(doc_list[idx].sci, SCI_POSITIONFROMLINE, i, 0);
|
||||||
|
// searching backwards for a space to remove
|
||||||
|
while (sci_get_char_at(doc_list[idx].sci, indentation_end) != ' ' &&
|
||||||
|
indentation_end > line_start)
|
||||||
|
indentation_end--;
|
||||||
|
|
||||||
|
if (sci_get_char_at(doc_list[idx].sci, indentation_end) == ' ')
|
||||||
|
{
|
||||||
|
sci_set_current_position(doc_list[idx].sci, indentation_end + 1, FALSE);
|
||||||
|
SSM(doc_list[idx].sci, SCI_DELETEBACK, 0, 0);
|
||||||
|
count--;
|
||||||
|
if (i == first_line)
|
||||||
|
first_line_offset = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sci_insert_text(doc_list[idx].sci, indentation_end, " ");
|
||||||
|
count++;
|
||||||
|
if (i == first_line)
|
||||||
|
first_line_offset = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set cursor position
|
||||||
|
if (sel_start < sel_end)
|
||||||
|
{
|
||||||
|
sci_set_selection_start(doc_list[idx].sci, sel_start + first_line_offset);
|
||||||
|
sci_set_selection_end(doc_list[idx].sci, sel_end + count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sci_set_current_position(doc_list[idx].sci, pos + count, FALSE);
|
||||||
|
|
||||||
|
SSM(doc_list[idx].sci, SCI_ENDUNDOACTION, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void editor_finalize()
|
void editor_finalize()
|
||||||
{
|
{
|
||||||
g_hash_table_destroy(editor_prefs.auto_completions);
|
g_hash_table_destroy(editor_prefs.auto_completions);
|
||||||
|
@ -143,6 +143,10 @@ void editor_select_paragraph(ScintillaObject *sci);
|
|||||||
|
|
||||||
void editor_insert_alternative_whitespace(ScintillaObject *sci);
|
void editor_insert_alternative_whitespace(ScintillaObject *sci);
|
||||||
|
|
||||||
|
void editor_auto_line_indentation(gint idx, gint pos);
|
||||||
|
|
||||||
|
void editor_indentation_by_one_space(gint idx, gint pos, gboolean decrease);
|
||||||
|
|
||||||
void editor_finalize();
|
void editor_finalize();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -266,6 +266,12 @@ void keybindings_init(void)
|
|||||||
GDK_i, GDK_CONTROL_MASK, "edit_increaseindent", _("Increase indent"));
|
GDK_i, GDK_CONTROL_MASK, "edit_increaseindent", _("Increase indent"));
|
||||||
keys[GEANY_KEYS_EDIT_DECREASEINDENT] = fill(cb_func_edit,
|
keys[GEANY_KEYS_EDIT_DECREASEINDENT] = fill(cb_func_edit,
|
||||||
GDK_i, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "edit_decreaseindent", _("Decrease indent"));
|
GDK_i, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "edit_decreaseindent", _("Decrease indent"));
|
||||||
|
keys[GEANY_KEYS_EDIT_INCREASEINDENTBYSPACE] = fill(cb_func_edit,
|
||||||
|
0, 0, "edit_increaseindentbyspace", _("Increase indent by one space"));
|
||||||
|
keys[GEANY_KEYS_EDIT_DECREASEINDENTBYSPACE] = fill(cb_func_edit,
|
||||||
|
0, 0, "edit_decreaseindentbyspace", _("Decrease indent by one space"));
|
||||||
|
keys[GEANY_KEYS_EDIT_AUTOINDENT] = fill(cb_func_edit,
|
||||||
|
0, 0, "edit_autoindent", _("Smart line indent"));
|
||||||
keys[GEANY_KEYS_EDIT_SENDTOCMD1] = fill(cb_func_edit,
|
keys[GEANY_KEYS_EDIT_SENDTOCMD1] = fill(cb_func_edit,
|
||||||
GDK_1, GDK_CONTROL_MASK, "edit_sendtocmd1", _("Send to Custom Command 1"));
|
GDK_1, GDK_CONTROL_MASK, "edit_sendtocmd1", _("Send to Custom Command 1"));
|
||||||
keys[GEANY_KEYS_EDIT_SENDTOCMD2] = fill(cb_func_edit,
|
keys[GEANY_KEYS_EDIT_SENDTOCMD2] = fill(cb_func_edit,
|
||||||
@ -1145,6 +1151,15 @@ static void cb_func_edit(guint key_id)
|
|||||||
case GEANY_KEYS_EDIT_DECREASEINDENT:
|
case GEANY_KEYS_EDIT_DECREASEINDENT:
|
||||||
on_menu_decrease_indent1_activate(NULL, NULL);
|
on_menu_decrease_indent1_activate(NULL, NULL);
|
||||||
break;
|
break;
|
||||||
|
case GEANY_KEYS_EDIT_INCREASEINDENTBYSPACE:
|
||||||
|
editor_indentation_by_one_space(idx, -1, FALSE);
|
||||||
|
break;
|
||||||
|
case GEANY_KEYS_EDIT_DECREASEINDENTBYSPACE:
|
||||||
|
editor_indentation_by_one_space(idx, -1, TRUE);
|
||||||
|
break;
|
||||||
|
case GEANY_KEYS_EDIT_AUTOINDENT:
|
||||||
|
editor_auto_line_indentation(idx, -1);
|
||||||
|
break;
|
||||||
case GEANY_KEYS_EDIT_TOLOWERCASE:
|
case GEANY_KEYS_EDIT_TOLOWERCASE:
|
||||||
on_to_lower_case1_activate(NULL, NULL);
|
on_to_lower_case1_activate(NULL, NULL);
|
||||||
break;
|
break;
|
||||||
|
@ -127,6 +127,9 @@ enum
|
|||||||
GEANY_KEYS_EDIT_UNCOMMENTLINE,
|
GEANY_KEYS_EDIT_UNCOMMENTLINE,
|
||||||
GEANY_KEYS_EDIT_INCREASEINDENT,
|
GEANY_KEYS_EDIT_INCREASEINDENT,
|
||||||
GEANY_KEYS_EDIT_DECREASEINDENT,
|
GEANY_KEYS_EDIT_DECREASEINDENT,
|
||||||
|
GEANY_KEYS_EDIT_INCREASEINDENTBYSPACE,
|
||||||
|
GEANY_KEYS_EDIT_DECREASEINDENTBYSPACE,
|
||||||
|
GEANY_KEYS_EDIT_AUTOINDENT,
|
||||||
GEANY_KEYS_EDIT_SENDTOCMD1,
|
GEANY_KEYS_EDIT_SENDTOCMD1,
|
||||||
GEANY_KEYS_EDIT_SENDTOCMD2,
|
GEANY_KEYS_EDIT_SENDTOCMD2,
|
||||||
GEANY_KEYS_EDIT_SENDTOCMD3,
|
GEANY_KEYS_EDIT_SENDTOCMD3,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user