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 151633

Summary: Code templates cannot be generated after fixing typo in abbreviation
Product: editor Reporter: tonybeckham <tonybeckham>
Component: Completion & TemplatesAssignee: Dusan Balek <dbalek>
Status: REOPENED ---    
Severity: blocker CC: belur_1d, ceklock, cfd, deepakjacob, dstrupl, markiewb, matthies, Monomachus, mrkam, saeed_z_f, sandipchitale, singa76, tor
Priority: P3    
Version: 7.0.1   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:
Attachments: Show the context tab

Description tonybeckham 2008-10-28 18:30:40 UTC
If you mistype a character in a code template that you want completed you cannot get code template generation unless you
start the shortcut over.  Not a bug but it would be a great enhancement to help adoption so I want to make it a P1
enhancement.

System:
Product Version: NetBeans IDE 6.5 RC2 (Build 20081028113643)
Java: 1.5.0_16; Java HotSpot(TM) Client VM 1.5.0_16-133
System: Mac OS X version 10.5.5 running on i386; MacRoman; en_US (nb)

Steps:
1. in a py file type ded (possible typo for def)
2. delete the "d" and replace with "f" and press tab, you will actually get the tab but it would be nice if generation
would still work.
3. delete the tab and def
4. start over and enter "def" + tab and generation is good.
Comment 1 Torbjorn Norbye 2008-10-28 19:16:32 UTC
This is just how code templates work in NetBeans.  I agree with you, and I think we have had some other requests for
this in the past. This is probably a duplicate of an existing issue in the editor.
Comment 2 Vitezslav Stejskal 2008-10-29 13:03:21 UTC

*** This issue has been marked as a duplicate of 57856 ***
Comment 3 tonybeckham 2008-10-29 21:42:48 UTC
verified duplicate
Comment 4 ceklock 2011-09-19 20:44:15 UTC
>> "If you mistype a character in a code template that you want completed you
cannot get code template generation unless you start the shortcut over."

I have this same issue in version 7.0.1 of NetBeans. Depending on what or how you mistype the characters of a code template and press TAB, the code template will not be expanded.

Example:
type "psvm_" (where _ is a space) and then backspace and TAB. The code template will not be expanded, you have to delete everything and type again.

I would like to have this fixed for 7.1. 

For me this is a bug. I don't know how this is implemented internally, but I think it is easy to fix.
Comment 5 ceklock 2011-09-19 20:53:04 UTC
*** Bug 57856 has been marked as a duplicate of this bug. ***
Comment 6 ceklock 2011-09-19 20:54:44 UTC
*** Bug 121198 has been marked as a duplicate of this bug. ***
Comment 7 ceklock 2011-09-19 20:55:00 UTC
*** Bug 144201 has been marked as a duplicate of this bug. ***
Comment 8 ceklock 2011-09-19 21:50:33 UTC
*** Bug 138197 has been marked as a duplicate of this bug. ***
Comment 9 Jiri Prox 2011-09-20 08:13:30 UTC
according to bug priority guide line, this is P3 IMHO
Comment 10 ceklock 2011-10-24 00:32:56 UTC
Still happening in NetBeans IDE Dev (Build 201110200600).
Comment 11 ceklock 2011-10-24 00:35:58 UTC
Copying comments from a duplicate issue:


------- Comment #1 From Petr Dvorak 2008-08-18 12:31:13 (-) -------

Well, I believe this is the way it is designed.

For example: If you type "for " (with a space) and then you realize you can
actually use a template "fori<tab>", you
need to delete all "for " and start over. If you just delete the last space and
if you press <tab>, it won't work...

I think this issue is probably invalid. What if you want to type "int
fori<tab>= 0;", for example because of the nice
indentation? You must leave the user some means to do that... If the code
template was expanded everytime you press tab
after template code, you wouldn't be able to type above mentioned text...

I am making this issue "invalid" for now, but please don't hesitate to reopen
this issue if you think it should be opened...

------- Comment #2 From saeed_z_f 2008-08-18 15:51:13 (-) -------

Hi 

I think when a user change the short key of code template to shift + space this
is a problem and this is not the way it
is designed .

------- Comment #3 From Jiri Prox 2008-08-19 15:59:49 (-) -------

this is not so serious IMHO

------- Comment #4 From Vitezslav Stejskal 2008-08-20 09:20:29 (-) -------

Well, in fact this __is__ the way how code templates expansion was designed.
The question is whether this design is good
or not. Maybe it is not and maybe the expansion could behave differently
depending on what expansion key you choose. But
any change in this area may have potentially disastrous consequences for many
people who has already become familiar
with the way how it is now.
Comment 12 Dusan Balek 2012-05-15 07:55:18 UTC
*** Bug 212426 has been marked as a duplicate of this bug. ***
Comment 13 Dusan Balek 2012-10-16 15:27:28 UTC
*** Bug 219194 has been marked as a duplicate of this bug. ***
Comment 14 ceklock 2012-11-30 17:28:04 UTC
From comment #11: ----------------------------------------
1) For example: If you type "for " (with a space) and then you realize you can
actually use a template "fori<tab>", you
need to delete all "for " and start over. If you just delete the last space and
if you press <tab>, it won't work...

2) I think this issue is probably invalid. What if you want to type "int
fori<tab>= 0;", for example because of the nice
indentation? You must leave the user some means to do that... If the code
template was expanded everytime you press tab
after template code, you wouldn't be able to type above mentioned text...
-----------------------------------------------------------

1) I don't understand why case 1) is designed like that. Why do you have to delete all and start over? Does not make sense for me.

2) Ok, "int fori<tab>= 0;" is a special case with a keyword before the code template. Just keep like that, because this is not the problem. 

A code template must start with a space or nothing before it in the line. 

Maybe we should have two types of shortcuts: TAB does the same thing that it is doing now. CTRL SPACE does what everyone wants (see comment #1).
Comment 15 ceklock 2012-11-30 17:29:20 UTC
Actually I wanted to say "see comment #0".
Comment 16 markiewb 2013-06-21 14:09:31 UTC
*** Bug 89281 has been marked as a duplicate of this bug. ***
Comment 17 markiewb 2013-06-21 14:10:06 UTC
*** Bug 90739 has been marked as a duplicate of this bug. ***
Comment 18 David Strupl 2013-08-22 12:31:13 UTC
I think this is a feature request. BTW it is not a trivial feature because after implementing this one can easily end up in expansion being done when the user doesn't want it to happen. It all depends on whether the expansion shortcut is used also for typing (as with Tab character). If it is used one must be careful not to cause problems when hitting the tab when the user wants to type tab.
Comment 19 matthies 2013-08-22 14:17:58 UTC
(In reply to David Strupl from comment #18)
> I think this is a feature request. BTW it is not a trivial feature because
> after implementing this one can easily end up in expansion being done when
> the user doesn't want it to happen. It all depends on whether the expansion
> shortcut is used also for typing (as with Tab character). If it is used one
> must be careful not to cause problems when hitting the tab when the user
> wants to type tab.

It's clear that there must be a way for the user to insert a tab whenever he needs to, even following a fragment that happens to be a code template abbreviation. One solution would be to have Shift+Tab do this (i.e. other than at the beginning of the line where it decrease the indentation). This is what SublimeText does for example, and it would also solve the "int fori<tab>= 0;" case from comment #11.

Note that if the user presses Tab behind some text that happens to be a code template abbreviation, but really wants to insert a tab, then he will usually just have typed this text. In this situation he will already get the undesired result of having the code template inserted today. Either this is something that happens rarely in practice, or users are already accustomed to working around it by e.g. pressing Space and Backspace before pressing Tab. If this is the case, then I would argue that they will be capable to get accustomed to pressing Shift+Tab just as easily.

Another possible solution could be to include code templates in the auto-completion popup (Ctrl+Space) as a way to insert a code template after a corrected abbreviation witout having to re-type the abbreviation. This already happens for some stuff; for example pressing Ctrl+Space after "for" presents a list of for-loop completions that correspond to code templates. (This is apparently context-sensitive, as it only happens within a code block.) But pressing Ctrl+Space after e.g. "psvm" doesn't suggest the public static void main code template.

Yet another possible solution would be for code template expansion to require only that either (a) the last character of the code template abbreviation must have been typed directly before pressing Tab or (b) Backspace must have been pressed directly before pressing Tab. This would solve many if not the majority of cases of correcting typos when entering code template abbreviations and would at most require having to re-type the last character of the code template.
Comment 20 Alexander Kouznetsov 2013-08-22 18:42:41 UTC
We may also consider putting template activation as a separate step in Undo history (as it is done in MS Word) so if template was activated when it was not needed, Ctrl-Z should undo it. This looks natural to me.

We can also consider backspace to undo it but this is more questionable to me.

Looks like some usability study is needed.
Comment 21 markiewb 2013-08-22 18:57:21 UTC
(In reply to matthies from comment #19)
> Another possible solution could be to include code templates in the
> auto-completion popup (Ctrl+Space) as a way to insert a code template after
> a corrected abbreviation witout having to re-type the abbreviation. This
> already happens for some stuff; for example pressing Ctrl+Space after "for"
> presents a list of for-loop completions that correspond to code templates.
> (This is apparently context-sensitive, as it only happens within a code
> block.) But pressing Ctrl+Space after e.g. "psvm" doesn't suggest the public
> static void main code template.
> 

FYI: Code completion for code templates was introduced by [1] [2]. Yes it would be nice to see "psvm" (and all the  other templates) in code completion too, but this would be overkill and "was in fact the main reason for introducing contexts" (cite of [3])

[1] https://netbeans.org/bugzilla/show_bug.cgi?id=160771
[2] https://netbeans.org/bugzilla/show_bug.cgi?id=184604
[3] https://netbeans.org/bugzilla/show_bug.cgi?id=212176#c7
Comment 22 matthies 2013-08-22 20:58:03 UTC
(In reply to markiewb from comment #21)
> FYI: Code completion for code templates was introduced by [1] [2]. Yes it
> would be nice to see "psvm" (and all the  other templates) in code
> completion too, but this would be overkill and "was in fact the main reason
> for introducing contexts" (cite of [3])

Then I wonder why the code templates dialog does not allow specification/editing of the context of a code template (whether custom or pre-defined). For example being able to specify a "class scope" context for "psvm" so that it appears in code completion. I'd be in favor of reopening Bug 212176 to have this feature added.
Comment 23 markiewb 2013-08-22 21:20:38 UTC
Created attachment 139093 [details]
Show the context tab

(In reply to matthies from comment #22)
> Then I wonder why the code templates dialog does not allow
> specification/editing of the context of a code template (whether custom or
> pre-defined). For example being able to specify a "class scope" context for
> "psvm" so that it appears in code completion. I'd be in favor of reopening
> Bug 212176 to have this feature added.

It is already possible. See the context tab (only for Java code templates) in the screenshot
Comment 24 matthies 2013-08-22 21:42:20 UTC
(In reply to markiewb from comment #23)
> Created attachment 139093 [details]
> Show the context tab
> 
> (In reply to matthies from comment #22)
> > Then I wonder why the code templates dialog does not allow
> > specification/editing of the context of a code template (whether custom or
> > pre-defined). For example being able to specify a "class scope" context for
> > "psvm" so that it appears in code completion. I'd be in favor of reopening
> > Bug 212176 to have this feature added.
> 
> It is already possible. See the context tab (only for Java code templates)
> in the screenshot

Ah, that's new in 7.4; I'm still using 7.3.1.
Comment 25 Martin Balin 2016-07-07 07:28:10 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss
Comment 26 matthies 2016-07-18 20:14:51 UTC
Still relevant in current dev build.