Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 71271

Summary: add "insert spaces for tabs" function to sse editors
Product: [WebTools] WTP Source Editing Reporter: Andrey Loskutov <loskutov>
Component: wst.sseAssignee: Amy Wu <for.work.things>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: daniel_megert, for.work.things, zaphod
Version: 0.7   
Target Milestone: 1.0 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 82296    
Bug Blocks: 71221, 97729    
Attachments:
Description Flags
org.eclipse.jst.jsp.ui.patch
none
org.eclipse.jst.jsp.ui.tests.patch
none
org.eclipse.wst.css.core.patch
none
org.eclipse.wst.css.ui.patch
none
org.eclipse.wst.html.core.patch
none
org.eclipse.wst.html.ui.patch
none
org.eclipse.wst.html.ui.tests.patch
none
org.eclipse.wst.javascript.ui.patch
none
org.eclipse.wst.sse.ui.patch
none
org.eclipse.wst.sse.ui.tests.patch
none
org.eclipse.wst.xml.core.patch
none
org.eclipse.wst.xml.ui.patch
none
org.eclipse.wst.xml.ui.tests.patch
none
org.eclipse.jst.jsp.ui2.patch
none
org.eclipse.wst.html.ui2.patch
none
org.eclipse.wst.xml.ui2.patch none

Description Andrey Loskutov CLA 2004-08-03 05:05:21 EDT
Even if "ident using tabs" is not checked on HTML editor preferences page, HTML 
editor uses always tabs for identation.
Comment 1 Joakim Kemeny CLA 2004-12-15 07:24:03 EST
This happens when you type, if you use the format command then the preferences 
will be used. However this is of cause wrong.
Comment 2 David Williams CLA 2005-01-05 12:22:41 EST
Kit ... sounds like something you would know about. Is there an easy way for us 
to fix this, and be consistent with base editors?
Comment 3 Kit Lo CLA 2005-01-05 12:58:22 EST
The "Indent using tabs" preference on the HTML Source Preferences page is 
for "Formatting" only. Note that all the "Line width", "Split multiple 
attributes", "Indent using tabs", and "Clear all blank lines" preferences are 
inside the "Formatting" groupbox.

If you don't want the tab key to tab 4 spaces, you should change 
the "Displayed tab width" preference on "All Text Editors" Preferences page to 
1 for all Eclipse editors, and change the same preference on "Structured Text 
Editors" Preferences page to 1 for all Structured Text Editors (including 
HTML, JSP, XML Editors).
Comment 4 Andrey Loskutov CLA 2005-01-05 14:51:29 EST
Hi, Kit, why this bug is marked as invalid?

The fact is, that if I type "TAB" key in jsp editor, *tabulator* character 
appears in source code (and I will only 4 spaces). I can set any preference in 
any place - this behavoir is still there. 
<bold>
I won't see tab characters in my source code - but currently they are there...
</bold>
I'm agree with you, that "tabs" preferences is for code *formatting* - but the 
bug was not against wrong prefrerences, but against editor behavoir. Probably my 
first description was not good enough, but in the bug summary I wrote: "HTML 
editor uses always tabs for identation" - and this bug ist still not fixed.
Comment 5 Kit Lo CLA 2005-01-05 15:32:17 EST
I'm sorry Andrei, I don't quite understand the problem. Do you want to see 4 
spaces (instead of the invisible tab character) inserted into the HTML Editor 
when you press the tab key on the keyboard?
Comment 6 Andrey Loskutov CLA 2005-01-05 16:42:40 EST
Exactly, e.g. like Java editor this does, if in "Java->Code style->Formatter" 
preferences the "use tab character" is not selected (this is similar to "HTML 
files->HTML source->Formatting->Ident using tabs" preference).

It will be better if inserted spaces count value will match any one of existing 
preferences for "tab width", either "All text editors -> Displayed tab width" or 
"Structured text editors -> Displayed tab width" or whatever.
Comment 7 Kit Lo CLA 2005-01-05 18:07:11 EST
Ah, I learned a new function!

That "tabs to spaces" function is specific to the Java Editor only. That 
function is not available in the Eclipse Text Editor, PDE Editor, or any of 
the Structured Text Editors. If we request that function to be moved from Java 
Editor to the Platform UI/Text level, then all subclasses of TextEditor will 
benifit from that.

Please open a separate bug against the Platform UI/Text component.
Comment 8 Andrey Loskutov CLA 2005-01-05 18:20:52 EST
Hi Kit, I have created bug 82296 as requested in your comment #7.
Comment 9 Amy Wu CLA 2005-05-16 19:30:12 EDT
changing the summary to more accurately describe the issue
Comment 10 Amy Wu CLA 2005-05-25 19:04:03 EDT
Ok, I have a solution that will insert spaces for tabs every time you hit the 
tab key.  However, it is different than what the Java editor provides.  Java 
editor now has a preference "Tab key indents the current line" (Java->Editor-
>Typing tab)  what it does is if you have it unchecked and you hit the tab 
key, spaces are inserted.  My solution does the same.  The difference, 
however, is that if you select multiple lines (or even if you select 1 whole 
line) and then hit the tab key, the Java editor will still add spaces.  My 
solution, however, does not (it will just add a tab character)

Codewise, the difference is that Java editor creates an Indent Action that is 
tied to the Tab key, versus my solution is tied to the AutoEdit function and 
all it does is replace the tab key with space keys.
Comment 11 Andrey Loskutov CLA 2005-05-26 16:12:58 EDT
> The difference, 
> however, is that if you select multiple lines [...] 
> and then hit the tab key, the Java editor will still add spaces.  
> My solution, however, does not (it will just add a tab character)

But then this is not really a good solution for this bug, because I would expect 
exactly the described behavoir of Java Editor for *any* number of selected 
lines, if I hit the "tab" in JSP file. I work in Eclipse on both Java and JSP 
code, and it  would be very annoying if they would have different behavoir for 
really *basic* text operations. Please do not implement such partial solution.

BTW, what is about bug 82296?
Comment 12 Amy Wu CLA 2005-05-27 14:42:45 EDT
Okay, I think i'm pretty close to solving the multiple lines problem (the 
solution involves overriding the shift left/shift right)

Just to be clear, is your main concern that you do not want tabs to be 
inserted at all?

I had misunderstood the Java->Editor-
>Typing->"Tab key indents the current line" preference.  It does not control 
whether or not spaces are replacing tabs characters.  It's more about the 
Indent action, which sse editors really don't have at the moment (it only 
provides indentation when formatting, or indent 1 spot only)

As for bug 82296 according to the bug, it looks like the base text team is not 
going to try to push it down for 3.1.
Comment 13 Andrey Loskutov CLA 2005-05-27 15:02:22 EDT
> is your main concern that you do not want tabs to be inserted at all?
Hi Amy, this is the point.
Comment 14 Amy Wu CLA 2005-06-02 17:33:36 EDT
Created attachment 22276 [details]
org.eclipse.jst.jsp.ui.patch
Comment 15 Amy Wu CLA 2005-06-02 17:33:50 EDT
Created attachment 22277 [details]
org.eclipse.jst.jsp.ui.tests.patch
Comment 16 Amy Wu CLA 2005-06-02 17:37:54 EDT
Created attachment 22278 [details]
org.eclipse.wst.css.core.patch
Comment 17 Amy Wu CLA 2005-06-02 17:38:15 EDT
Created attachment 22279 [details]
org.eclipse.wst.css.ui.patch
Comment 18 Amy Wu CLA 2005-06-02 17:40:52 EDT
Created attachment 22281 [details]
org.eclipse.wst.html.core.patch
Comment 19 Amy Wu CLA 2005-06-02 17:41:10 EDT
Created attachment 22282 [details]
org.eclipse.wst.html.ui.patch
Comment 20 Amy Wu CLA 2005-06-02 17:42:14 EDT
Created attachment 22283 [details]
org.eclipse.wst.html.ui.tests.patch
Comment 21 Amy Wu CLA 2005-06-02 17:42:37 EDT
Created attachment 22284 [details]
org.eclipse.wst.javascript.ui.patch
Comment 22 Amy Wu CLA 2005-06-02 17:43:23 EDT
Created attachment 22285 [details]
org.eclipse.wst.sse.ui.patch
Comment 23 Amy Wu CLA 2005-06-02 17:44:54 EDT
Created attachment 22286 [details]
org.eclipse.wst.sse.ui.tests.patch
Comment 24 Amy Wu CLA 2005-06-02 17:45:05 EDT
Created attachment 22287 [details]
org.eclipse.wst.xml.core.patch
Comment 25 Amy Wu CLA 2005-06-02 17:45:29 EDT
Created attachment 22288 [details]
org.eclipse.wst.xml.ui.patch
Comment 26 Amy Wu CLA 2005-06-02 17:46:06 EDT
Created attachment 22289 [details]
org.eclipse.wst.xml.ui.tests.patch
Comment 27 Amy Wu CLA 2005-06-02 18:22:02 EDT
fixed so now when users select indent using spaces in the XX Source Formatting 
preference, spaces are used.  This includes when you hit the tab key on its 
own, or if you hit tab key with multiple lines selected, shift right, shift 
left.

add dependency on bug 82296 so that when that "spaces for tabs" function is 
finally pushed down to base, we can react to it.

Fix details:
(the following applies to JSP, CSS, HTML, XML)
-Fixed AutoEdit so when tabs are pressed, and "indent using spaces" spaces are 
inserted instead
-Fixed ViewerConfiguration by adding getIndentPrefixes so when proper 
indentation is retrieved by Shift Right/Shift Left operation
-Fixed StructuredTextViewer so indentprefixes is properly set on viewer when 
shift right/shift left
-Added testGetIndentPrefixes to TestViewerConfiguration

Additional fixes included:
-small performance fix on css, html, xml formatters to use StringBuffer 
instead of String when calculating indentation
-make StructuredTextViewerConfigurationJSP use less internal classes by 
getting processors from StructuredTextViewerConfigurationHTML/XML
-fixed bug 97729


Additional action needed:
-delete org.eclipse.wst.sse.ui.internal.autoedit.BasicAutoEditStrategy if 
possible (i just deprecated it in my patch)
Comment 28 Amy Wu CLA 2005-06-02 18:28:41 EDT
Thanks, David.
Comment 29 Andrey Loskutov CLA 2005-06-03 04:58:00 EDT
Thanks, Amy
Comment 30 David Williams CLA 2005-06-06 01:09:26 EDT
Committed to HEAD. 

Thanks Amy. 
Comment 31 Andrey Loskutov CLA 2005-07-14 06:38:52 EDT
Reopened this bug - with the I20050707 build, I still have "tab" inserted if I 
hit the "tab" key, instead of 2 spaces, as defined in preferences.

This happens inside of scriplet code or inside of included javascript areas on 
any jsp we have.

e.g. inside this code the spaces are inserted on "tab" key (this is ok):
------------
<%@ include file="/common/include/i18n/definitions.inc" %>
<%@ taglib uri="/tags/xyz" prefix="fl" %>
 
<jsp:useBean id="pageBean" scope="request" class="xyz.ResultPageBean"/>
------------

just few lines later, in the same jsp, tabs are inserted instead of spaces on 
"tab" key:

-----------
<script type="text/javascript" language="JavaScript">
<!--
	
//-->
</script>
-----------

And 5 lines below we have scriplet code which also ignores "insert spaces for 
tabs" rule:

<%
	
  FlightViewDTO flight = pageBean.getFlights().getSelectedFlight();
  AirlineViewDTO marketingAirline = flight.getMarketingCarrier();
%>

I'm sure that on all appropriated settings for all file types (html, css, jsp, 
js, xml, default) in whole Eclipse + WTP + Structured Editor + Java preferences 
I have *only* spaces for tabs defined.
Comment 32 Amy Wu CLA 2005-07-18 14:33:53 EDT
it is the autoeditstrategy that is handling when the tab key is pressed on its 
own.

the problem is the java autoeditstrategy is used for jsp java regions and the 
default autoeditstrategy is used for non-html regions, like script and those 
autoeditstrategies do not have the spaces for tabs function built into them.

a solution would be to separate the spaces for tab function out to its own 
autoeditstrategy and then add it as an autoeditstrategy for all regions (you 
can have multiple autoeditstrategies)
Comment 33 Amy Wu CLA 2005-07-18 14:46:38 EDT
Created attachment 24931 [details]
org.eclipse.jst.jsp.ui2.patch
Comment 34 Amy Wu CLA 2005-07-18 14:46:56 EDT
Created attachment 24932 [details]
org.eclipse.wst.html.ui2.patch
Comment 35 Amy Wu CLA 2005-07-18 14:47:07 EDT
Created attachment 24933 [details]
org.eclipse.wst.xml.ui2.patch
Comment 36 Amy Wu CLA 2005-07-18 14:49:52 EDT
I've attached 3 new patches that should fix up the problem in comment #31.  
Solution is in comment #32.

David, please apply new patches when you see fit.
Comment 37 David Williams CLA 2005-07-18 17:47:15 EDT
Since this is almost WTP's oldest bug (going from when originally opened) I
think we should fix this for 0.7. 

Andrei, will you be in a position to quickly test this before our final RC2
build if I get this into a build on Tuesday or Wednesday?
Comment 38 Andrey Loskutov CLA 2005-07-18 17:55:35 EDT
I can not promise it for this week, sorry. But the test case is very simply - 
just one plain jsp with some mixed jsp / java and javascript parts is enough to 
test it.
Comment 39 David Williams CLA 2005-07-19 17:28:27 EDT
Thanks Amy, patch applied to head. 
Comment 40 David Williams CLA 2005-07-19 17:29:02 EDT
Will release for 7/20 I-build (for RC2). 
Comment 41 David Williams CLA 2006-09-25 02:43:12 EDT
This bug was moved to 'closed' state, since it is so old and it is assumed really fixed and no longer useful or need further attention. Feel free to re-open, or open a new bug, if this semi-automatic processing was done in error. 
Comment 42 Dani Megert CLA 2007-03-19 06:56:14 EDT
FYI: this is now supported for textual editors out of the box and there is API on the text viewer for this. See:

ITextViewerExtension7.setTabsToSpacesConverter(IAutoEditStrategy)
TabsToSpacesConverter
AbstractTextEditor.installTabsToSpacesConverter()
AbstractTextEditor.unnstallTabsToSpacesConverter()
AbstractTextEditor.isTabsToSpacesConversionEnabled()