From: Sean H. <jal...@ho...> - 2007-05-04 00:24:57
|
I tracked down the extra spaces problem. It turned out to be a space at = = the end of the line (after the EOL character(s)), not at the beginning, = = which is why it doesn't show up on the first line. Here's the cause of the problem: # How many characters are on a line, not including end of line character= s? sub LineLength { my ($self, $line) =3D @_; return $self->SendMessage (2350, $line, 0); } Scintilla's documentation says: SCI_LINELENGTH(int line) This returns the length of the line, including any line end characters. = If = line is negative or beyond the last line in the document, the result is = 0. = If you want the length of the line not including any end of line = characters, use SCI_GETLINEENDPOSITION(line) - SCI_POSITIONFROMLINE(line= ). Laurent's code makes an incorrect assumption about EOL markers and = SCI_LINELENGTH. (Although it may have been correct when it was coded, an= d = Scintilla later changed.) Everywhere Laurent has used LineLength to get = = the text at a line, he has done the following: my $lenght =3D $self->LineLength($line); my $text =3D " " x ($lenght + 1); $self->SendMessageNP (2153, $line, $text); He has to create the buffer first, because SendMessage requires the memo= ry = to be already allocated, so he creates a buffer of spaces. But he create= s = it one byte too long, so there's a trailing space in the returned text. (SendMessageNP is an alias for SendMessage with the second parameter as = a = pointer. There is also SendMessage PN for the first parameter as a point= er = and SendMessagePP for both parameters as pointers. It would probably be = = better to have a single SendMessage function, and use references when yo= u = want a parameter to be a pointer, but I don't currently have a compiler,= = so I can't mess with the C code. We'd have to leave the extra methods in= = for a couple versions anyway, to prevent older code from breaking.) The intermediate solution is to go to line 196 in Scintilla.pm (in the = GetLine() sub) and take out the '+1'. Then when SaveFile calls GetLine, = = you won't get a trailing space. The long-term solution is to find every place Laurent has used LineLengt= h, = and fix it. I am willing to do this and email the fixed file to someone = = with CVS access, so it will be correct in the next version. I'll test it= = via SaveFile, with differrent combinations of EOL markers in source and = = destination files, to make sure it really works. (I'll also fix that = annoying little misspelling in the local variable while I'm at it.) |