Fix replacing colors with "0x" prefix with length different than 6
We used to assume that if the selected text started with "0x" when inserting a color, we had to replace exactly 6 bytes after the "0x" prefix. Although this is generally the case as most color formats use 6 hexadecimal digits, it still would erase either too many or too few characters if actually replacing something shorter (i.e. "0xfff") or longer (i.e. "0xffffffffffff"). It could even partially override multi-byte characters if the 8th byte after the selection start was in the middle of a character, as the length was in bytes and not characters. Fix this by honoring the actual selection end.
This commit is contained in:
parent
ab6390fc8c
commit
e135da8a79
@ -4164,8 +4164,12 @@ void editor_insert_color(GeanyEditor *editor, const gchar *colour)
|
||||
if (sci_get_char_at(editor->sci, start) == '0' &&
|
||||
sci_get_char_at(editor->sci, start + 1) == 'x')
|
||||
{
|
||||
gint end = sci_get_selection_end(editor->sci);
|
||||
|
||||
sci_set_selection_start(editor->sci, start + 2);
|
||||
sci_set_selection_end(editor->sci, start + 8);
|
||||
/* we need to also re-set the selection end in case the anchor was located before
|
||||
* the cursor, since set_selection_start() always moves the cursor, not the anchor */
|
||||
sci_set_selection_end(editor->sci, end);
|
||||
replacement++; /* skip the leading "0x" */
|
||||
}
|
||||
else if (sci_get_char_at(editor->sci, start - 1) == '#')
|
||||
|
Loading…
x
Reference in New Issue
Block a user