From 390646a412120375c63db41773950b0f32b68390 Mon Sep 17 00:00:00 2001 From: Eugene Arshinov Date: Mon, 26 Mar 2012 15:44:50 +0400 Subject: [PATCH] rewrite_reflow: Extract `split_line` function Extract `split_line` function from `reflow_lines` to reimplement it in the future without using SCI_SPLITLINES to achieve the behaviour consistent with the "Line breaking" option. --- src/keybindings.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/keybindings.c b/src/keybindings.c index 9a4b5b68..91a1aae0 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -2099,6 +2099,20 @@ static gint get_reflow_column(GeanyEditor *editor) } +/* Split the line where the cursor is positioned, on `column`, + possibly many times if the line is long. + Return the number of lines added because of the splitting. */ +static gint split_line(GeanyEditor *editor, gint column) +{ + gint linescount = sci_get_line_count(editor->sci); + sci_set_anchor(editor->sci, -1); + sci_target_from_selection(editor->sci); + sci_lines_split(editor->sci, column * sci_text_width(editor->sci, STYLE_DEFAULT, " ")); + /* use lines count to determine how many lines appeared after splitting */ + return sci_get_line_count(editor->sci) - linescount; +} + + static void reflow_lines(GeanyEditor *editor, gint column) { gint start, indent, linescount, i; @@ -2133,12 +2147,7 @@ static void reflow_lines(GeanyEditor *editor, gint column) indent = sci_get_line_indentation(editor->sci, start); sci_set_line_indentation(editor->sci, start, 0); - sci_target_from_selection(editor->sci); - linescount = sci_get_line_count(editor->sci); - sci_lines_split(editor->sci, - (column - indent) * sci_text_width(editor->sci, STYLE_DEFAULT, " ")); - /* use lines count to determine how many lines appeared after splitting */ - linescount = sci_get_line_count(editor->sci) - linescount; + linescount = split_line(editor, column - indent); /* Fix indentation. */ for (i = start; i <= start + linescount; i++)