Patch #3311 2012-08-04 15:51
alpha0010
CC: do not draw tooltips off the edge of the window- Download
- 3311-CC_do_not_draw.patch (3.2 KB)
Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 8193)
+++ src/plugins/codecompletion/codecompletion.cpp (working copy)
@@ -1510,7 +1510,7 @@
}
else
{
- if (style != wxSCI_C_DEFAULT && style != wxSCI_C_OPERATOR && style != wxSCI_C_IDENTIFIER)
+ if (style != wxSCI_C_DEFAULT && style != wxSCI_C_OPERATOR && style != wxSCI_C_IDENTIFIER && style != wxSCI_C_WORD2 && style != wxSCI_C_GLOBALCLASS)
{
event.Skip();
return;
@@ -2529,7 +2529,9 @@
int style = event.GetInt();
if ( (style != wxSCI_C_DEFAULT)
&& (style != wxSCI_C_OPERATOR)
- && (style != wxSCI_C_IDENTIFIER) )
+ && (style != wxSCI_C_IDENTIFIER)
+ && (style != wxSCI_C_WORD2)
+ && (style != wxSCI_C_GLOBALCLASS) )
{
event.Skip();
return;
@@ -2556,6 +2558,7 @@
CC_LOCKER_TRACK_TT_MTX_LOCK(s_TokensTreeMutex)
int count = 0;
+ size_t tipWidth = 0;
for (TokenIdxSet::iterator it = result.begin(); it != result.end(); ++it)
{
Token* token = tree->at(*it);
@@ -2567,6 +2570,8 @@
tips.Add(tip);
calltip << tip << _T("\n");
+ if (tip.Length() > tipWidth)
+ tipWidth = tip.Length();
++count;
if (count > 32) // allow max 32 matches (else something is definitely wrong)
{
@@ -2581,6 +2586,20 @@
if (!calltip.IsEmpty())
{
calltip.RemoveLast(); // last \n
+
+ int lnStart = ed->GetControl()->PositionFromLine(ed->GetControl()->LineFromPosition(pos));
+ // pos - lnStart == distance from start of line
+ // + tipWidth + 1 == projected virtual position of tip end (with a 1 character buffer) from start of line
+ // - (width_of_editor_in_pixels / width_of_character) == distance tip extends past window edge
+ // horizontal scrolling is accounted for by PointFromPosition().x
+ int offset = tipWidth + pos + 1 - lnStart -
+ (ed->GetControl()->GetSize().x - ed->GetControl()->PointFromPosition(lnStart).x) /
+ ed->GetControl()->TextWidth(wxSCI_STYLE_LINENUMBER, _T("W"));
+ if (offset > 0)
+ pos -= offset;
+ if (pos < lnStart) // do not go to previous line if tip is wider than editor
+ pos = lnStart;
+
ed->GetControl()->CallTipShow(pos, calltip);
TRACE(calltip);
}
@@ -2672,7 +2691,7 @@
else if (lineFirstChar == _T(':') && curChar == _T(':'))
return;
- if (style != wxSCI_C_DEFAULT && style != wxSCI_C_OPERATOR && style != wxSCI_C_IDENTIFIER)
+ if (style != wxSCI_C_DEFAULT && style != wxSCI_C_OPERATOR && style != wxSCI_C_IDENTIFIER && style != wxSCI_C_WORD2 && style != wxSCI_C_GLOBALCLASS)
return;
TRACE(_T("DoCodeComplete -> CodeComplete"));
History
ollydbg 2012-08-06 03:37
Can you add some comments on this code below: if (!calltip.IsEmpty()) { calltip.RemoveLast(); // last \n int lnStart = ed->GetControl()->PositionFromLine(ed->GetControl()->LineFromPosition(pos)); int offset = tipWidth + pos + 1 - lnStart - (ed->GetControl()->GetSize().x - ed->GetControl()->PointFromPosition(lnStart).x) / ed->GetControl()->TextWidth(wxSCI_STYLE_LINENUMBER, _T("W")); if (offset > 0) pos -= offset; if (pos < lnStart) pos = lnStart; ed->GetControl()->CallTipShow(pos, calltip); TRACE(calltip); } You calculate a "offset" value, but I'm not quite understand what is the logic of this code snippet? Thanks
alpha0010 2012-08-06 20:59
Sorry, that code was quite unreadable. Here are some comments.