Branch: refs/heads/master Author: Eugene Arshinov earshinov@gmail.com Committer: Eugene Arshinov earshinov@gmail.com Date: Sat, 25 Feb 2012 15:48:07 Commit: 6b760b99d45238c343493f0bfe9f95958c071096 https://github.com/geany/geany/commit/6b760b99d45238c343493f0bfe9f95958c0710...
Log Message: ----------- join_lines: Add "Join lines" command.
The code of existing "Reflow paragraph" command was refactored to extract the bits required for the new command.
Modified Paths: -------------- src/keybindings.c src/keybindings.h
Modified: src/keybindings.c 105 files changed, 75 insertions(+), 30 deletions(-) =================================================================== @@ -394,6 +394,8 @@ static void init_default_kb(void) add_kb(group, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH, NULL, GDK_j, GDK_CONTROL_MASK, "format_reflowparagraph", _("_Reflow Lines/Block"), "reflow_lines_block1"); + keybindings_set_item(group, GEANY_KEYS_FORMAT_JOINLINES, NULL, + 0, 0, "edit_joinlines", _("Join lines"), NULL);
group = keybindings_get_core_group(GEANY_KEY_GROUP_INSERT);
@@ -2060,7 +2062,28 @@ static void join_lines(GeanyEditor *editor) }
-static void split_lines(GeanyEditor *editor, gint column) +static gint get_reflow_column(GeanyEditor *editor) +{ + const GeanyEditorPrefs *eprefs = editor_get_prefs(editor); + if (editor->line_breaking) + { + /* use line break column if enabled */ + return eprefs->line_break_column; + } + else if (eprefs->long_line_type != 2) + { + /* use long line if enabled */ + return eprefs->long_line_column; + } + else + { + /* do nothing if no column is defined */ + return -1; + } +} + + +static void reflow_lines(GeanyEditor *editor, gint column) { gint start, indent, linescount, i, end; gchar c; @@ -2130,8 +2153,23 @@ static void split_lines(GeanyEditor *editor, gint column) }
+/* deselect last newline of selection, if any */ +static void sci_deselect_last_newline(ScintillaObject *sci) +{ + gint start, end; + + start = sci_get_selection_start(sci); + end = sci_get_selection_end(sci); + if (end > start && sci_get_col_from_position(sci, end) == 0) + { + end = sci_get_line_end_position(sci, sci_get_line_from_position(sci, end-1)); + sci_set_selection(sci, start, end); + } +} + + /* if cursor < anchor, swap them */ -static void sci_fix_selection(ScintillaObject *sci) +static void sci_fix_selection_anchors(ScintillaObject *sci) { gint start, end;
@@ -2145,45 +2183,49 @@ static void reflow_paragraph(GeanyEditor *editor) { ScintillaObject *sci = editor->sci; gboolean sel; - gint column = -1; - const GeanyEditorPrefs *eprefs = editor_get_prefs(editor); + gint column;
- if (editor->line_breaking) + column = get_reflow_column(editor); + if (column == -1) { - /* use line break column if enabled */ - column = eprefs->line_break_column; - } - else if (eprefs->long_line_type != 2) - { - /* use long line if enabled */ - column = eprefs->long_line_column; - } - else - { - /* do nothing if no column is defined */ utils_beep(); return; } + sci_start_undo_action(sci); sel = sci_has_selection(sci); if (!sel) - { - gint line, pos; - editor_select_indent_block(editor); + sci_deselect_last_newline(sci); + sci_fix_selection_anchors(sci); + reflow_lines(editor, column); + if (!sel) + sci_set_anchor(sci, -1);
- /* deselect last line break */ - pos = sci_get_selection_end(sci); - line = sci_get_line_from_position(sci, pos); - if (line < sci_get_line_count(sci) - 1) - { - /* not last line */ - pos = sci_get_line_end_position(sci, line - 1); - sci_set_selection_end(sci, pos); - } + sci_end_undo_action(sci); +} + + +static void join_paragraph(GeanyEditor *editor) +{ + ScintillaObject *sci = editor->sci; + gboolean sel; + gint column; + + column = get_reflow_column(editor); + if (column == -1) + { + utils_beep(); + return; } - sci_fix_selection(sci); - split_lines(editor, column); + + sci_start_undo_action(sci); + sel = sci_has_selection(sci); + if (!sel) + editor_select_indent_block(editor); + sci_deselect_last_newline(sci); + //sci_fix_selection_anchors(sci); + join_lines(editor); if (!sel) sci_set_anchor(sci, -1);
@@ -2248,6 +2290,9 @@ static gboolean cb_func_format_action(guint key_id) case GEANY_KEYS_FORMAT_REFLOWPARAGRAPH: reflow_paragraph(doc->editor); break; + case GEANY_KEYS_FORMAT_JOINLINES: + join_paragraph(doc->editor); + break; } return TRUE; }
Modified: src/keybindings.h 1 files changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -240,6 +240,7 @@ enum GeanyKeyBindingID GEANY_KEYS_PROJECT_OPEN, /**< Keybinding. */ GEANY_KEYS_PROJECT_NEW, /**< Keybinding. */ GEANY_KEYS_PROJECT_CLOSE, /**< Keybinding. */ + GEANY_KEYS_FORMAT_JOINLINES, /**< Keybinding. */ GEANY_KEYS_COUNT /* must not be used by plugins */ };
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: TBD).