This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 61817 - Code completion should not appear if the caret has moved since CC was implicitly or explicitly invoked
Summary: Code completion should not appear if the caret has moved since CC was implici...
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: Completion & Templates (show other bugs)
Version: 5.x
Hardware: All All
: P1 blocker (vote)
Assignee: Miloslav Metelka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-04 22:48 UTC by _ tboudreau
Modified: 2007-11-05 13:38 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ tboudreau 2005-08-04 22:48:17 UTC
Currently code completion opens after a delay, even if the caret has moved to 
a place where it is inappropriate.  This can be really maddening - especially 
if you paste anything ending in a . but basically, any time code completion 
comes up showing something inappropriate when the caret is in a place where no 
code completion is needed.

For example, say you have code like:

public Component foo (int val) {
  switch (val) {
     case 0 : setFont (font1);  break;
     case 1 : setFont (font2);  break;
     case 2 : setFont (font3);  break;
     default : assert false;
   }
  return this;
}

Now I decide Foo will instead delegate to another instance of a component.  So 
the method should look like

public Component foo (int val) {
  Component result = delegate.getFoo();
  switch (val) {
     case 0 : result.setFont (font1);  break;
     case 1 : result.setFont (font2);  break;
     case 2 : result.setFont (font3);  break;
     default : assert false;
   }
  return this;
}

Just try pasting "result." in front of each call to setFont().  Each time you 
do it, code completion starts getting ready to appear.  By the time it has 
appeared, the caret is usually in front of "setFont", and there is nothing to 
show.

This is a serious problem - about 75% of the time I see code completion, it is 
not appropriate.  A simple fix would be to save the caret position when code 
completion was invoked, and not show it if the caret position has changed when 
it is ready to appear.
Comment 1 Roman Strobl 2005-08-05 09:57:38 UTC
I've reported a very similar issue 61406.
Comment 2 _ tboudreau 2005-08-29 05:46:09 UTC
Relatedly, once code completion comes up, if you ignore it and start typing, it can do some strange 
things.  For example, frequently I'm typing something like.

for (Iterator i=someIterator(); i.hasNext();) {

Code completion pops up sometime around when I type i. - and it stays up as I type the rest of the line.    
I press enter to go to the next line and end up with some random thing that was in the code completion 
list inserted at the end of the line, which I then have to delete.

for (Iterator i=someIterator(); i.hasNext();) { someRandomThing



Comment 3 Roman Strobl 2005-09-07 10:10:19 UTC
Increasing priority to P1 to mark this issue as beta-stopper. Justification:
code completion appears when it should not and it happens often, it can be quite
frustrating.
Comment 4 Miloslav Metelka 2005-09-08 11:23:57 UTC
I'll try to fix this now.
Comment 5 Miloslav Metelka 2005-09-15 11:22:55 UTC
Fixed in trunk:
Checking in src/org/netbeans/modules/editor/completion/CompletionImpl.java;
/cvs/editor/completion/src/org/netbeans/modules/editor/completion/CompletionImpl.java,v
 <--  CompletionImpl.java
new revision: 1.12; previous revision: 1.11
Comment 6 _ tboudreau 2005-09-20 21:45:34 UTC
Sorry, this isn't fixed.

1:
Open any java source file.
In some method (or wherever), type .
Immediately press backspace
Code completion appears

2:
Type something
Code completion stays even though there is no purpose for it

2 perhaps can't be helped;  but 1 doesn't seem to have changed.
Comment 7 Martin Roskanin 2005-09-21 08:40:41 UTC
Original P1 problem was fixed. I cannot reproduce problem of opening CC after
pasting  "result."  as well as problem of 
for (Iterator i=someIterator(); i.hasNext();) {
where completion was not closed. Now, CC is closed after typing "(".
New problems you mentioned don't meet the P1 criteria. I am creating new issue
#64792 for that and closing this one.