Revision: 2605 http://geany.svn.sourceforge.net/geany/?rev=2605&view=rev Author: ntrel Date: 2008-05-21 07:00:27 -0700 (Wed, 21 May 2008)
Log Message: ----------- Refactor editor_auto_line_indentation(). Make auto-line indentation set the cursor to the beginning of indentation for single line selections, so the user can fine-tune indentation if necessary. For multiple line selections, select all the lines after indenting.
Modified Paths: -------------- trunk/ChangeLog trunk/src/editor.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-05-19 15:22:56 UTC (rev 2604) +++ trunk/ChangeLog 2008-05-21 14:00:27 UTC (rev 2605) @@ -1,3 +1,13 @@ +2008-05-21 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com> + + * src/editor.c: + Refactor editor_auto_line_indentation(). + Make auto-line indentation set the cursor to the beginning of + indentation for single line selections, so the user can fine-tune + indentation if necessary. For multiple line selections, select all + the lines after indenting. + + 2008-05-19 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/plugindata.h, src/plugins.c, doc/plugin-symbols.c,
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2008-05-19 15:22:56 UTC (rev 2604) +++ trunk/src/editor.c 2008-05-21 14:00:27 UTC (rev 2605) @@ -2671,11 +2671,36 @@ }
-/* simple auto indentation to indent the current line with the same indent as the previous one */ +/* simple indentation to indent the current line with the same indent as the previous one */ +static void auto_line_indentation(gint idx, gint first_line, gint last_line) +{ + gint i, sel_start = 0, sel_end = 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); + sci_replace_sel(doc_list[idx].sci, ""); + } + sci_insert_text(doc_list[idx].sci, sel_start, indent); + } +} + + +/* simple 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 = 0, sel_end = 0; + gint first_line, last_line; + gint first_sel_start, first_sel_end;
g_return_if_fail(DOC_IDX_VALID(idx));
@@ -2691,35 +2716,31 @@ if (pos == -1) pos = first_sel_start;
+ SSM(doc_list[idx].sci, SCI_BEGINUNDOACTION, 0, 0); + /* 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_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++) + auto_line_indentation(idx, first_line, last_line); + + /* set cursor position if there was no selection */ + if (first_sel_start == first_sel_end) { - /* 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; + gint indent_pos = SSM(doc_list[idx].sci, SCI_GETLINEINDENTPOSITION, first_line, 0);
- 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); - sci_replace_sel(doc_list[idx].sci, ""); - } - sci_insert_text(doc_list[idx].sci, sel_start, indent); + /* use indent position as user may wish to change indentation afterwards */ + sci_set_current_position(doc_list[idx].sci, indent_pos, FALSE); } + else + { + ScintillaObject *sci = doc_list[idx].sci;
- /* 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); + /* fully select all the lines affected */ + sci_set_selection_start(sci, sci_get_position_from_line(sci, first_line)); + sci_set_selection_end(sci, sci_get_position_from_line(sci, last_line + 1)); + }
SSM(doc_list[idx].sci, SCI_ENDUNDOACTION, 0, 0); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.