rewrite_reflow: Reimplement split_line
function to achieve consistency with the "Line breaking" option
This commit is contained in:
parent
40fb3aa64d
commit
cc5e6d2a19
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user