[geany/geany] e135da: Fix replacing colors with "0x" prefix with length different than 6
Colomban Wendling
git-noreply at xxxxx
Wed Apr 9 01:06:49 UTC 2014
Branch: refs/heads/master
Author: Colomban Wendling <ban at herbesfolles.org>
Committer: Colomban Wendling <ban at herbesfolles.org>
Date: Wed, 09 Apr 2014 01:06:49 UTC
Commit: e135da8a79fa2a96d836b18159b535d0f7294ecd
https://github.com/geany/geany/commit/e135da8a79fa2a96d836b18159b535d0f7294ecd
Log Message:
-----------
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.
Modified Paths:
--------------
src/editor.c
Modified: src/editor.c
6 files changed, 5 insertions(+), 1 deletions(-)
===================================================================
@@ -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) == '#')
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list