diff --git a/ChangeLog b/ChangeLog index 9e804959..85447459 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-05-08 Enrico Tröger + + * src/sciwrappers.c, src/sciwrappers.h: + Added sci_get_line_indentation() and sci_set_line_indentation(). + * src/callbacks.c: Fixed broken increase/decrease indentation when + using only spaces for indentation. + + 2007-05-07 Enrico Tröger * data/filetypes.haskell: Added build instructions. diff --git a/src/callbacks.c b/src/callbacks.c index ac46d627..91c8f5fd 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -1863,7 +1863,7 @@ on_menu_increase_indent1_activate (GtkMenuItem *menuitem, gpointer user_data) { gint idx = document_get_cur_idx(); - if (idx == -1 || ! doc_list[idx].is_valid) return; + if (! DOC_IDX_VALID(idx)) return; if (sci_get_lines_selected(doc_list[idx].sci) > 1) { @@ -1871,16 +1871,18 @@ on_menu_increase_indent1_activate (GtkMenuItem *menuitem, } else { - gint line, ind_pos, old_pos; + gint line, ind_pos, old_pos, new_pos, step; old_pos = sci_get_current_position(doc_list[idx].sci); line = sci_get_current_line(doc_list[idx].sci, old_pos); ind_pos = sci_get_line_indent_position(doc_list[idx].sci, line); + // when using tabs increase cur pos by 1, when using space increase it by tab_width + step = (app->pref_editor_use_tabs) ? 1 : app->pref_editor_tab_width; + new_pos = (old_pos > ind_pos) ? old_pos + step : old_pos; sci_set_current_position(doc_list[idx].sci, ind_pos, TRUE); sci_cmd(doc_list[idx].sci, SCI_TAB); - sci_set_current_position(doc_list[idx].sci, - (old_pos > ind_pos) ? old_pos + 1 : old_pos, TRUE); + sci_set_current_position(doc_list[idx].sci, new_pos, TRUE); } } @@ -1890,7 +1892,7 @@ on_menu_decrease_indent1_activate (GtkMenuItem *menuitem, gpointer user_data) { gint idx = document_get_cur_idx(); - if (idx == -1 || ! doc_list[idx].is_valid) return; + if (! DOC_IDX_VALID(idx)) return; if (sci_get_lines_selected(doc_list[idx].sci) > 1) { @@ -1898,18 +1900,25 @@ on_menu_decrease_indent1_activate (GtkMenuItem *menuitem, } else { - gint line, ind_pos, old_pos; + gint line, ind_pos, old_pos, new_pos, step, indent; old_pos = sci_get_current_position(doc_list[idx].sci); line = sci_get_current_line(doc_list[idx].sci, old_pos); ind_pos = sci_get_line_indent_position(doc_list[idx].sci, line); + step = (app->pref_editor_use_tabs) ? 1 : app->pref_editor_tab_width; + new_pos = (old_pos >= ind_pos) ? old_pos - step : old_pos; if (ind_pos == sci_get_position_from_line(doc_list[idx].sci, line)) return; + sci_set_current_position(doc_list[idx].sci, ind_pos, TRUE); - sci_cmd(doc_list[idx].sci, SCI_BACKTAB); - sci_set_current_position(doc_list[idx].sci, - (old_pos >= ind_pos) ? old_pos - 1 : old_pos, TRUE); + indent = sci_get_line_indentation(doc_list[idx].sci, line); + indent -= app->pref_editor_tab_width; + if (indent < 0) + indent = 0; + sci_set_line_indentation(doc_list[idx].sci, line, indent); + + sci_set_current_position(doc_list[idx].sci, new_pos, TRUE); } } diff --git a/src/sciwrappers.c b/src/sciwrappers.c index 4611a6ad..c37b5c0f 100644 --- a/src/sciwrappers.c +++ b/src/sciwrappers.c @@ -941,3 +941,13 @@ void sci_set_scrollbar_mode(ScintillaObject *sci, gboolean visible) SSM(sci, SCI_SETVSCROLLBAR, visible, 0); } +void sci_set_line_indentation(ScintillaObject *sci, gint line, gint indent) +{ + SSM(sci, SCI_SETLINEINDENTATION, line, indent); +} + +int sci_get_line_indentation(ScintillaObject *sci, gint line) +{ + return SSM(sci, SCI_GETLINEINDENTATION, line, 0); +} + diff --git a/src/sciwrappers.h b/src/sciwrappers.h index 617520a1..c67249d2 100644 --- a/src/sciwrappers.h +++ b/src/sciwrappers.h @@ -167,6 +167,8 @@ void sci_set_styling (ScintillaObject * sci, gint len, gint style); void sci_start_styling (ScintillaObject * sci, gint pos, gint mask); void sci_select_all (ScintillaObject * sci); gint sci_get_line_indent_position(ScintillaObject * sci, gint line); +void sci_set_line_indentation (ScintillaObject * sci, gint line, gint indent); +int sci_get_line_indentation (ScintillaObject * sci, gint line); void sci_set_autoc_max_height (ScintillaObject * sci, gint val); gint sci_find_bracematch (ScintillaObject * sci, gint pos);