Branch: refs/heads/master Author: Eugene Arshinov earshinov@gmail.com Committer: elextr elextr@gmail.com Date: Sun, 21 Apr 2013 01:45:09 UTC Commit: cc5e6d2a19e3ac434621d2d7ed867fd4caaff19b https://github.com/geany/geany/commit/cc5e6d2a19e3ac434621d2d7ed867fd4caaff1...
Log Message: ----------- rewrite_reflow: Reimplement `split_line` function to achieve consistency with the "Line breaking" option
Modified Paths: -------------- src/keybindings.c
Modified: src/keybindings.c 56 files changed, 50 insertions(+), 6 deletions(-) =================================================================== @@ -2104,12 +2104,56 @@ static gint get_reflow_column(GeanyEditor *editor) 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; + ScintillaObject *sci = editor->sci; + gint start_line = sci_get_current_line(sci); + gint line = start_line; + + while (TRUE) + { + gint lstart = sci_get_position_from_line(sci, line); + gint lend = sci_get_line_end_position(sci, line); + gint edge = sci_get_position_from_col(sci, line, column); + gboolean found; + gint pos; + + /* don't split on a trailing space of a line */ + if (sci_get_char_at(sci, lend - 1) == GDK_space) + lend--; + + /* detect when the line is short enough and no more splitting is needed */ + if (sci_get_col_from_position(sci, lend) < column) + break; + + /* lookup split position */ + found = FALSE; + for (pos = edge - 1; pos > lstart; pos--) + { + if (sci_get_char_at(sci, pos) == GDK_space) + { + found = TRUE; + break; + } + } + if (!found) + { + for (pos = edge; pos < lend; pos++) + { + if (sci_get_char_at(sci, pos) == GDK_space) + { + found = TRUE; + break; + } + } + } + if (!found) + break; + + sci_set_current_position(sci, pos + 1, FALSE); + sci_cancel(sci); /* don't select from completion list */ + sci_send_command(sci, SCI_NEWLINE); + line++; + } + return line - start_line; }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).