Thanks, it's working.<div>I had that kind of code in my project since QScintilla 2.2 (or even earlier) where these functions didn't exist but now it's definitely a good time to drop it.<br><div>--</div><div>Mikhail.<br>


<br><br><div class="gmail_quote">On Tue, Nov 23, 2010 at 6:08 AM, Phil Thompson <span dir="ltr"><<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

On Mon, 22 Nov 2010 17:02:38 -0500, Mikhail Murzin <<a href="mailto:mezomish@gmail.com">mezomish@gmail.com</a>><br>
wrote:<br>
<div><div></div><div class="h5">> Hi folks,<br>
><br>
> Found the following issue: QScintilla highlights wrong ranges with<br>
> SCI_INDICATORFILLRANGE<br>
> if the text contains non-ascii characters.<br>
><br>
> Here is a code to reproduce:<br>
><br>
> #include <QApplication><br>
> #include <QFile><br>
> #include <Qsci/QsciScintilla.h><br>
><br>
> int main(int argc, char* argv[]) {<br>
>     QApplication app(argc, argv);<br>
><br>
>     if ( argc < 2 ) {<br>
>         return 0;<br>
>     }<br>
><br>
>     QsciScintilla sci;<br>
>     sci.setUtf8(true);<br>
> #ifdef Q_OS_WIN32<br>
>     sci.setFont(QFont("Courier New", 10));<br>
> #else<br>
>     sci.setFont(QFont("Monospace", 10));<br>
> #endif<br>
><br>
>     QFile file(argv[1]);<br>
>     if ( file.open(QIODevice::ReadOnly) ) {<br>
>         sci.read(&file);<br>
>         file.close();<br>
>     }<br>
><br>
>     int lineCount = sci.lines();<br>
>     for ( int line = 0; line < lineCount; ++line ) {<br>
>         // getting the position for the line's beginning<br>
>         long linePos =<br>
> sci.SendScintilla(QsciScintilla::SCI_POSITIONFROMLINE, line);<br>
>         // highlighting exactly 10 characters starting from the 5th<br>
> character<br>
>         sci.SendScintilla(QsciScintilla::SCI_INDICATORFILLRANGE, linePos<br>
+<br>
> 5, 10);<br>
>     }<br>
><br>
>     sci.resize(500, 150);<br>
>     sci.show();<br>
><br>
>     return app.exec();<br>
> }<br>
><br>
><br>
> The code is pretty much self-explanatory but just to be clear: trying to<br>
> highlight exactly 10 characters starting from the 5th character of each<br>
> line.<br>
> As you can see it's not always 10 characters highlighted and it can be<br>
any<br>
> number from 5 to 10 (depending on how many non-ascii symbols are there<br>
in<br>
> highlighting region).<br>
> Also highlighting not always starts at the 5th character (depending on<br>
how<br>
> many non-ascii characters are there before the highlighting region).<br>
> Looks like somewhere in highlighting code byte count is used instead of<br>
> character count - that's why it works for ASCII chars but doesn't work<br>
for<br>
> non-ASCII.<br>
><br>
> Here is the screenshot:<br>
> <a href="http://dl.dropbox.com/u/6404414/qscintilla_hl_bug.png" target="_blank">http://dl.dropbox.com/u/6404414/qscintilla_hl_bug.png</a><br>
> Here is the archive with the code above and a text file to test with:<br>
> <a href="http://dl.dropbox.com/u/6404414/hlexample.zip" target="_blank">http://dl.dropbox.com/u/6404414/hlexample.zip</a> (launch the app with<br>
> "test.txt" passed as the 1st argument).<br>
<br>
</div></div>Character positions are not the same as byte positions - you need to<br>
convert between the two using QsciScintilla::positionFromLineIndex().<br>
<br>
Change the body of your loop to...<br>
<br>
    int start = sci.positionFromLineIndex(line, 5);<br>
    int end = sci.positionFromLineIndex(line, 10);<br>
<br>
    sci.SendScintilla(QsciScintilla::SCI_INDICATORFILLRANGE, start, end -<br>
start);<br>
<font color="#888888"><br>
Phil<br>
</font></blockquote></div><br></div></div>