Author Topic: Close code completion on "space"?  (Read 13246 times)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9615
Close code completion on "space"?
« on: March 15, 2006, 10:48:07 pm »
Dear all,
I know code completion is WIP, but a very minor change could improve the current functionality a lot - so I ask for it hereby:
Wouldn't it make sense to close the code completion window if the user presses "space"? That's actually the major issue (for me!) the window does not close if I continue typing and it is already empty and/or I press "space". Correct me if I'm wrong, but if I type "space" than this really cannot make sense in code completion because a variable/method/whatever cannot contain a space, right? So it would make sense to close the code completion window in that situation.
I tried to implement it myself so I've looked through the code to find how the CTRL+SPACE is handled but no success. Could someone of the devs give me a hint? At least the file I should look into? Hopefully I can provide a patch then...
Any help is appreciated. With regards, Morten.
« Last Edit: March 15, 2006, 11:00:11 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Close code completion on "space"?
« Reply #1 on: March 15, 2006, 11:16:16 pm »
If you 're not using the custom code-completion control (Settings->Editor->Code completion->Use custom control), in codecompletion.cpp line 395, add a space in the fill-up chars (in bold):

ed->GetControl()->AutoCompSetFillUps(m_IsAutoPopup ? _T("") : _T(">.;([="));

Else, for the custom control, in cclist.cpp line 267 insert:

case WXK_SPACE:

Of course you can do both of the above :)
Be patient!
This bug will be fixed soon...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9615
Re: Close code completion on "space"?
« Reply #2 on: March 15, 2006, 11:34:57 pm »
Thanks for the answer!
If you 're not using the custom code-completion control
Well, I do! But here it comes: I changed to the "default" control (removing the check in the checkbox, right?) and it works! This helps (for the first step).

ed->GetControl()->AutoCompSetFillUps(m_IsAutoPopup ? _T("") : _T(">.;([="));
Isn't this the place where I change when the code completion pops up? I want to change when it closes automatically, so it's the opposite... or am I missing something here?!

Else, for the custom control, in cclist.cpp line 267 insert:
case WXK_SPACE:
Aaaah! I guess that's what I was looking for. It seems I only need to add:
Code
    case WXK_SPACE:
    {
      Destroy();
      break;
    }
here. But I'm looking into this tomorrow, I'm far too tired for now to run a C::B build. Anyway, posting this here makes sure I've got that information tomorrow morning at work. Sorry for misusing the board as a scratchpad... ;-)

Thanks again, I'll report back...

With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Close code completion on "space"?
« Reply #3 on: March 16, 2006, 12:06:31 am »
Quote
Isn't this the place where I change when the code completion pops up? I want to change when it closes automatically, so it's the opposite... or am I missing something here?!

The fill-ups are the characters that when pressed will select the highlighted item and dismiss the code-completion window.
If you don't want to select the item using space, then the default behaviour is fine.
Be patient!
This bug will be fixed soon...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9615
Re: Close code completion on "space"?
« Reply #4 on: March 16, 2006, 08:43:58 am »
Else, for the custom control, in cclist.cpp line 267 insert:
case WXK_SPACE:
Alright, that's exactly what was to do. So now the custom control closes on space. But: In addition I would like to have the space also typed in the editor - this does not happen unfortunately. I thought using the event.Skip() would provide the "space" key to the editor but it seems the "space" ist lost... somewhere. But where?

I'm not sure how to better explain, so maybe here is an example: If I type "std::cout" then the code completion window is still open but empty. The next character shall be a space so if I just continue typing the "space" I would like to have the code completion window closed and in the editor is now "std::cout{space}". It works like that if I'm not using the custom control, but I would like to have this behaviour for the custom control, too.

With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Close code completion on "space"?
« Reply #5 on: March 16, 2006, 09:15:23 am »
Code: cpp
case WXK_SPACE:
    int pos = m_pEditor->GetCurrentPos();
    m_pEditor->InsertText(pos, _T(' ')); // I don't remember this by heart, sorry (look it up)
    m_pEditor->GotoPos(pos + 1);
    Destroy();
    break;
Be patient!
This bug will be fixed soon...

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: Close code completion on "space"?
« Reply #6 on: March 16, 2006, 10:20:09 am »
I don't remember this by heart, sorry (look it up)

this works fine
Code: cpp
    case WXK_SPACE:
    {
        m_pList->AddChar(c);
        Destroy();
        break;
    }

thanks for the tip !

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: Close code completion on "space"?
« Reply #7 on: March 16, 2006, 10:24:46 am »
btw:

this
Quote from:  source code
   // unfortunately, for some odd reason, we never get wxGrid's (m_pList)
   // OnChar event.
   // So we have to process all key handling here (with raw keycodes...)

is very ugly and really a shame (of wxWidgets ?) !

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: Close code completion on "space"?
« Reply #8 on: March 16, 2006, 10:33:40 am »
btw2:

CCList::PositionMe()

doesn't work on dual monitor desktop :(


has anybody any tips how to solve this ?

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Close code completion on "space"?
« Reply #9 on: March 16, 2006, 10:40:55 am »
btw:

this
Quote from:  source code
   // unfortunately, for some odd reason, we never get wxGrid's (m_pList)
   // OnChar event.
   // So we have to process all key handling here (with raw keycodes...)

is very ugly and really a shame (of wxWidgets ?) !

This part of the code was created very early in the project history. I believe it was with wx2.4?
Anyway, this might have been fixed by now but I don't see the point of adding functionality in this custom control anymore. As you saw, it also has positioning problems with multi-monitor setups. Also, in KDE, it looses focus or something (we had a bug report about it).

For these reasons, the scintilla's embedded auto-complete box has been enabled and favoured over our custom implementation. The only reason I left this custom control in there, is for reference purposes on how to use/create a custom renderer for wxGrid (!).
Be patient!
This bug will be fixed soon...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9615
Re: Close code completion on "space"?
« Reply #10 on: March 16, 2006, 10:48:46 am »
For these reasons, the scintilla's embedded auto-complete box has been enabled and favoured over our custom implementation.
Oh no! I thought the "custom implementation" is better for some reason - thus I enabled it. I mean why would someone use a custom control if the default one is better? I've switched now to the default allthough I got it to work with the custom control, too (using yout hints). ;-)
With regards, Morten.
« Last Edit: March 16, 2006, 11:12:44 am by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Close code completion on "space"?
« Reply #11 on: March 16, 2006, 10:53:01 am »
For these reasons, the scintilla's embedded auto-complete box has been enabled and favoured over our custom implementation.
Oh no! I thought the "custom implementation" is better for some reason - thus I enabled it. I mean why would someone use a custom control if the defautl one is better? I've switched now to the default allthough I got it to work with the cvustom control, too (using yout hints). ;-)
With regards, Morten.

The custom control is better in the sense that it displays a lot more info. BUT, it only works well on windows and even then it still has some bugs because of handling raw keycodes...
Be patient!
This bug will be fixed soon...

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Close code completion on "space"?
« Reply #12 on: March 16, 2006, 11:12:44 am »
CCList::PositionMe()
doesn't work on dual monitor desktop :(
has anybody any tips how to solve this ?
Yes, by turning PositionMe() into SizeMe() and using PlaceWindow(this, pdlConstrain); instead:
Code
Index: plugins/codecompletion/cclist.cpp
===================================================================
--- plugins/codecompletion/cclist.cpp (revision 2190)
+++ plugins/codecompletion/cclist.cpp (working copy)
@@ -29,6 +29,7 @@
 #include <wx/sizer.h>
 #include <configmanager.h>
 #include <manager.h>
+#include <globals.h>
 
 const wxEventType csdEVT_CCLIST_CODECOMPLETE = wxNewEventType();
 
@@ -72,6 +73,8 @@
 {
  m_StartPos = m_pEditor->GetCurrentPos();
  PositionMe();
+       PlaceWindow(this, pdlConstrain);
+
  int start = m_pEditor->WordStartPosition(m_StartPos, true);
  wxString prefix = m_pEditor->GetTextRange(start, m_StartPos);
 
@@ -106,34 +109,6 @@
  if (h > screenH)
  h = screenH;
 
-// now we 're where we want to be, but check that the whole window is visible...
-// the main goal here is that the caret *should* be visible...
-
-// for the horizontal axis, easy stuff
- if (pt.x + w > screenW)
- pt.x = screenW - w;
-
- // for the vertical axis, more work has to be done...
- if (pt.y + h > screenH)
- {
- // it doesn't fit to the bottom of the screen
- // check if it fits to the top
- if (h < pt.y)
- pt.y -= h + lineHeight; // fits
- else
- {
- // we have to shrink the height...
- // determine if pt.y is closer to top or bottom
- if (pt.y <= screenH / 2)
- h = screenH = pt.y; // to top
- else
- {
- h = pt.y - lineHeight; // to bottom
- pt.y = 0;
- }
- }
- }
- // we should be OK now
  SetSize(pt.x, pt.y, w, h);
 // PlaceWindow(this, pdlConstrain, true);
 }
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9615
Re: Close code completion on "space"?
« Reply #13 on: March 16, 2006, 11:16:42 am »
The custom control is better in the sense that it displays a lot more info. [...]
Yes, I was too fast with writing to the forum. Meanwhile I've realised this, too. :oops: :oops: :oops:
Anyway: Do you think it makes sense to apply the "space" thing generally? It's the same behaviour as the default control then. I could file a patch with the changes I've done but it's actually the code mandrav has already posted... how about it?!
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Close code completion on "space"?
« Reply #14 on: March 16, 2006, 11:22:09 am »
Anyway: Do you think it makes sense to apply the "space" thing generally? It's the same behaviour as the default control then. I could file a patch with the changes I've done but it's actually the code mandrav has already posted... how about it?!
With regards, Morten.

Sure, go ahead. All I said is that *I* wouldn't update this code ;)
Be patient!
This bug will be fixed soon...