return selectedText.len + 1;
Is this correct? selectedText.len already is 1 longer, at least in the
stream selection case, to account for the '\0' on the end of the text.
Adding 1 here makes the returned result 1 too long... except, if you have no
selection, selectedText.len holds 0.
As we really have to use SCI_GETSELTEXT() now to find the length of the
selection, I would expect SCI_GETSELTEXT()-1 to be the number of selected
characters in the window. So would it be possible to either adjust
CopySelectionRange() to return "\0" and a .len of 1 for an empty selection,
or change line 6468 to:
return selectedText.len ? selectedText.len : 1;
A user of our code noticed this as our scripting language can report the
length of the selection. We used to work out the selection size using the
Caret position and the Anchor position, but this is no longer possible with
multiple selections, so we changed to using SCI_GETSELTEXT()-1, expecting
this to be the number of selected characters.
Greg Smith
Director
Cambridge Electronic Design Limited
Science Park, Milton Road, Cambridge CB4 0FE, UK
Web: http://www.ced.co.uk
Tel: +44 (0)1223 420186
Fax: +44 (0)1223 420488
Registered in the UK no. 972132
> As we really have to use SCI_GETSELTEXT() now to find the length of the
> selection, I would expect SCI_GETSELTEXT()-1 to be the number of selected
> characters in the window. So would it be possible to either adjust
> CopySelectionRange() to return "\0" and a .len of 1 for an empty selection,
> or change line 6468 to:
>
> return selectedText.len ? selectedText.len : 1;
OK, committed.
Also changed the case where the allowLineCopy case of
CopySelectionRange was not counting the '\0'.
Neil
> This is changing line 5333 in Editor::CopySelectionRange() to the
> following?
> ss->Set(textWithEndl, strlen(textWithEndl) + 1,
Yes.
Neil
> If selectedText.len is 1 (implying an empty string), the return value
> is 1, but there is a handler for selectedText.len being 0, which
> generates a string containing '\0', but returns 0. If selectedText.len
> can never be 0, then the code is redundant,
selectedText.len can be 0 since this is the value it is initialized to
and it retains this value when there is no need to allocate such as
when the selection is empty and allowLineCopy is false.
Neil