User forums > General (but related to Code::Blocks)

Strange cursor position with wx3.0.2 (scintilla)

<< < (4/7) > >>

ollydbg:

--- Code: ---void UTF8FromUTF16(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned int len) {
unsigned int k = 0;
for (unsigned int i = 0; i < tlen && uptr[i];) {
unsigned int uch = uptr[i];
if (uch < 0x80) {
putf[k++] = static_cast<char>(uch);
} else if (uch < 0x800) {
putf[k++] = static_cast<char>(0xC0 | (uch >> 6));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
} else if ((uch >= SURROGATE_LEAD_FIRST) &&
(uch <= SURROGATE_TRAIL_LAST)) {
// Half a surrogate pair
i++;
unsigned int xch = 0x10000 + ((uch & 0x3ff) << 10) + (uptr[i] & 0x3ff);
putf[k++] = static_cast<char>(0xF0 | (xch >> 18));
putf[k++] = static_cast<char>(0x80 | ((xch >> 12) & 0x3f));
putf[k++] = static_cast<char>(0x80 | ((xch >> 6) & 0x3f));
putf[k++] = static_cast<char>(0x80 | (xch & 0x3f));
} else {
putf[k++] = static_cast<char>(0xE0 | (uch >> 12));
putf[k++] = static_cast<char>(0x80 | ((uch >> 6) & 0x3f));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
}
i++;
}
if (k < len)
putf[k] = '\0';
}
--- End code ---
Now, the last two line, I have k == len, and I see there is NO chances to set the null terminator.

ollydbg:

--- Quote from: ollydbg on December 23, 2015, 04:13:10 pm ---
--- Code: ---void UTF8FromUTF16(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned int len) {
unsigned int k = 0;
for (unsigned int i = 0; i < tlen && uptr[i];) {
unsigned int uch = uptr[i];
if (uch < 0x80) {
putf[k++] = static_cast<char>(uch);
} else if (uch < 0x800) {
putf[k++] = static_cast<char>(0xC0 | (uch >> 6));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
} else if ((uch >= SURROGATE_LEAD_FIRST) &&
(uch <= SURROGATE_TRAIL_LAST)) {
// Half a surrogate pair
i++;
unsigned int xch = 0x10000 + ((uch & 0x3ff) << 10) + (uptr[i] & 0x3ff);
putf[k++] = static_cast<char>(0xF0 | (xch >> 18));
putf[k++] = static_cast<char>(0x80 | ((xch >> 12) & 0x3f));
putf[k++] = static_cast<char>(0x80 | ((xch >> 6) & 0x3f));
putf[k++] = static_cast<char>(0x80 | (xch & 0x3f));
} else {
putf[k++] = static_cast<char>(0xE0 | (uch >> 12));
putf[k++] = static_cast<char>(0x80 | ((uch >> 6) & 0x3f));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
}
i++;
}
if (k < len)
putf[k] = '\0';
}
--- End code ---
Now, the last two line, I have k == len, and I see there is NO chances to set the null terminator.

--- End quote ---
OK, the following patch should fix the issue:

--- Code: --- src/sdk/wxscintilla/src/scintilla/src/UniConversion.cxx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sdk/wxscintilla/src/scintilla/src/UniConversion.cxx b/src/sdk/wxscintilla/src/scintilla/src/UniConversion.cxx
index c12ca34..e987963 100644
--- a/src/sdk/wxscintilla/src/scintilla/src/UniConversion.cxx
+++ b/src/sdk/wxscintilla/src/scintilla/src/UniConversion.cxx
@@ -68,7 +68,7 @@ void UTF8FromUTF16(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned
  }
  i++;
  }
- if (k < len)
+ if (k <= len)
  putf[k] = '\0';
 }
 

--- End code ---
This not only fix the issue about the extra bytes in the content of the cbEditor, it also fix the wrong line number margin width issue. Also, before using this patch, the font is totally wrong, and with this patch, the font in the editor is OK now.

ollydbg:

--- Quote from: ollydbg on December 20, 2015, 06:00:09 am ---I have 32 bit cb build myself with against wx3.0.2 under Windows XP.
I see some similar issue, see screen shot:

sometimes, I see two cursors in the previous locations, see screen shot:

Here is the steps to reproduce:
When I first put the cursor after the "main()", and I hit the arrow down key. I see the cursor is still there. After that, I hit the arrow down key again, I see the cursor is still there after the "{", and now the cursor is located after the "vector".
I guess it is related to highlight of the "()" or "{}".

--- End quote ---
The above issue still exists in the scintilla branch(which is scintilla 3.6.2) with wx 3.0.2.
There are two issues:
1, the blinking cursor is not removed when another brace highlight is added(by click on the other brace pair)
2, from the image shot above, it looks like when I hit after the "{", the closing "}" (the end of the main() function body) is not highlighted.

ollydbg:
If you click from top to bottom as pointed by the screen shot, you get many brace highlight...
See image shot below:

It looks like the old brace highlight does not get clean up.

EDIT: I just tested the SciTE 2.6.2 release, it dose not have such issue. So, it is related to wx 3.0.2's platform support for scintilla.

EDIT2: make the whole editor window refresh(such as minimize the C::B window, and restore it) will totally remove the old high light.

ollydbg:
Debugged for a while, I found that, when I click on a brace(if there are some braces already highlighted)
I get to those code:

--- Code: ---void Editor::SetBraceHighlight(Position pos0, Position pos1, int matchStyle) {
if ((pos0 != braces[0]) || (pos1 != braces[1]) || (matchStyle != bracesMatchStyle)) {
if ((braces[0] != pos0) || (matchStyle != bracesMatchStyle)) {
CheckForChangeOutsidePaint(Range(braces[0]));
CheckForChangeOutsidePaint(Range(pos0));
braces[0] = pos0;
}
if ((braces[1] != pos1) || (matchStyle != bracesMatchStyle)) {
CheckForChangeOutsidePaint(Range(braces[1]));
CheckForChangeOutsidePaint(Range(pos1));
braces[1] = pos1;
}
bracesMatchStyle = matchStyle;
if (paintState == notPainting) {
Redraw();
}
}
}

--- End code ---
This function is called inside the function call "Paint(surfaceWindow, rcPaint);" inside the below function.

--- Code: ---void ScintillaWX::DoPaint(wxDC* dc, wxRect rect) {

    paintState = painting;
    AutoSurface surfaceWindow(dc, this);
    if (surfaceWindow) {
        rcPaint = PRectangleFromwxRect(rect);
        PRectangle rcClient = GetClientRectangle();
        paintingAllText = rcPaint.Contains(rcClient);

        ClipChildren(*dc, rcPaint);
        Paint(surfaceWindow, rcPaint);
        surfaceWindow->Release();
    }

    if (paintState == paintAbandoned) {
        // Painting area was insufficient to cover new styling or brace
        // highlight positions.  So trigger a new paint event that will
        // repaint the whole window.
        sci->Refresh(false);

#if defined(__WXOSX__)
        // On Mac we also need to finish the current paint to make sure that
        // everything is on the screen that needs to be there between now and
        // when the next paint event arrives.
        FullPaintDC(dc);
#endif
    }
    paintState = notPainting;
}

--- End code ---

Then, we will get into the condition that satisfy this condition "if (!PaintContains(rcRange))", so that "paintAbandonedByStyling = true;" is reached.

--- Code: ---void Editor::CheckForChangeOutsidePaint(Range r) {
if (paintState == painting && !paintingAllText) {
//Platform::DebugPrintf("Checking range in paint %d-%d\n", r.start, r.end);
if (!r.Valid())
return;

PRectangle rcRange = RectangleFromRange(r, 0);
PRectangle rcText = GetTextRectangle();
if (rcRange.top < rcText.top) {
rcRange.top = rcText.top;
}
if (rcRange.bottom > rcText.bottom) {
rcRange.bottom = rcText.bottom;
}

if (!PaintContains(rcRange)) {
AbandonPaint();
paintAbandonedByStyling = true;
}
}
}
--- End code ---
Back to the function "void ScintillaWX::DoPaint(wxDC* dc, wxRect rect)", you will see the Refresh() call is reached.

--- Code: ---    if (paintState == paintAbandoned) {
        // Painting area was insufficient to cover new styling or brace
        // highlight positions.  So trigger a new paint event that will
        // repaint the whole window.
        sci->Refresh(false);

--- End code ---
Now, you get a repaint:


--- Code: ---void wxScintilla::OnPaint(wxPaintEvent& WXUNUSED(evt))
{
#ifdef __WXGTK__
    wxBufferedPaintDC dc(this);
#else
    wxPaintDC dc(this);
#endif
    m_swx->DoPaint(&dc, GetUpdateRegion().GetBox());
}

--- End code ---

But here comes the bug!
I see that "GetUpdateRegion().GetBox()" only gives the area around the current line. This not cover the old brace highlight, so that the old brace highlight is not removed. Also, if you click on the "{", while the associated "}" is on the other line(which means the "}" is not in the area of the "GetUpdateRegion().GetBox()"), so the "}" is not highlighted.

What's wrong with the "GetUpdateRegion().GetBox()", It should at least be a rectangle area which covers the current braces and the old braces.


Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version