Skip to content

Commit 28584f2

Browse files
authored
Merge pull request spillz#6 from yvesdm3000/master
Fix unrequested codecompletion menu: When asking for auto-completion,…
2 parents 7301062 + c788f2f commit 28584f2

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

PythonCodeCompletion/PythonCodeCompletion.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ END_EVENT_TABLE()
4848
// constructor
4949
PythonCodeCompletion::PythonCodeCompletion() : m_ActiveCalltipDef(_(""))
5050
{
51+
m_comp_position.line = 0;
52+
m_comp_position.column = 0;
5153
// Make sure our resources are available.
5254
// In the generated boilerplate code we have no resources but when
5355
// we add some, it will be nice that this code is in place already ;)
@@ -320,9 +322,29 @@ PythonCodeCompletion::CCProviderStatus PythonCodeCompletion::GetProviderStatusFo
320322
std::vector<PythonCodeCompletion::CCToken> PythonCodeCompletion::GetAutocompList(bool isAuto, cbEditor* ed, int& tknStart, int& tknEnd)
321323
{
322324
Manager::Get()->GetLogManager()->DebugLog(_("PYCC: GetAutocompList called"));
325+
326+
cbStyledTextCtrl* control = ed->GetControl();
327+
const int line = control->LineFromPosition(tknStart);
328+
const int lnStart = control->PositionFromLine(line);
329+
int column = tknStart - lnStart;
330+
for (; column > 0; --column)
331+
{
332+
if ( !wxIsspace(control->GetCharAt(lnStart + column - 1))
333+
|| (column != 1 && !wxIsspace(control->GetCharAt(lnStart + column - 2))) )
334+
{
335+
break;
336+
}
337+
}
338+
323339
std::vector<CCToken> tokens;
324340
if (m_state == STATE_COMPLETION_RETURNED)
325341
{
342+
if ((m_comp_position.line != line)||(m_comp_position.column != column))
343+
{
344+
Manager::Get()->GetLogManager()->DebugLog( _("PYCC: Position has changed since last CC request") );
345+
m_state=STATE_NONE;
346+
return tokens;
347+
}
326348
for (int i = 0; i<m_comp_results.Count(); ++i)
327349
{
328350
long int category=-1;
@@ -331,7 +353,6 @@ std::vector<PythonCodeCompletion::CCToken> PythonCodeCompletion::GetAutocompList
331353
PythonCodeCompletion::CCToken t(i,m_comp_results[i].BeforeFirst('?'),category);
332354
tokens.push_back(t);
333355
}
334-
cbStyledTextCtrl* control = ed->GetControl();
335356
control->ClearRegisteredImages();
336357
for (int i = 0; i < m_pImageList->GetImageCount(); i++)
337358
control->RegisterImage(i+1,m_pImageList->GetBitmap(i));
@@ -343,7 +364,6 @@ std::vector<PythonCodeCompletion::CCToken> PythonCodeCompletion::GetAutocompList
343364
// if ( (!ed->AutoCompActive()) // not already active autocompletion
344365
// || (ch == _T('.')))
345366
Manager::Get()->GetLogManager()->DebugLog(_("PYCC: Checking lexical state..."));
346-
cbStyledTextCtrl *control=ed->GetControl();
347367
int pos = tknEnd;
348368
int style = control->GetStyleAt(pos);
349369
wxChar ch = control->GetCharAt(pos);
@@ -359,6 +379,8 @@ std::vector<PythonCodeCompletion::CCToken> PythonCodeCompletion::GetAutocompList
359379
wxString phrase=control->GetTextRange(tknStart,tknEnd);
360380
Manager::Get()->GetLogManager()->DebugLog(_T("PYCC: Looking for ")+phrase+_T(" in ")+ed->GetFilename()+wxString::Format(_T(" %i"),pos));
361381
m_state = STATE_COMPLETION_REQUEST;
382+
m_comp_position.line = line;
383+
m_comp_position.column = column;
362384
RequestCompletion(control,pos,ed->GetFilename());
363385
return tokens;
364386
}

PythonCodeCompletion/PythonCodeCompletion.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ class PythonCodeCompletion : public cbCodeCompletionPlugin
148148
wxImageList* m_pImageList; //Type icons displayed in the code completion popup
149149
CCCallTip m_ActiveCalltipDef; //contains the call tip definition retrieved from the server
150150
wxArrayString m_comp_results; //contains an array of completion results retrieved from the server
151-
151+
struct {
152+
int line;
153+
int column;
154+
} m_comp_position;
152155
DECLARE_EVENT_TABLE();
153156
};
154157

0 commit comments

Comments
 (0)