Bug 54940 - [Java] Compare editor does not replace tabs by spaces
Summary: [Java] Compare editor does not replace tabs by spaces
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Compare (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P4 normal with 1 vote (vote)
Target Milestone: 3.5 M5   Edit
Assignee: Platform-Compare-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 154306 (view as bug list)
Depends on: 82296
Blocks: 169386
  Show dependency tree
 
Reported: 2004-03-16 02:35 EST by Edwin van Gruijthuijsen CLA
Modified: 2009-01-14 12:07 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Edwin van Gruijthuijsen CLA 2004-03-16 02:35:43 EST
When I type tabs in the normal Java editors, tabs are replaced by spaces
because I have set the following preference:

Java | Editor | Typing | Insert space for tabs

The compare editor however does not seem to use this setting: it keeps the
tabs I type in.
Comment 1 MG CLA 2004-10-26 21:26:23 EDT
I have this same problem 3.1m2, can we have this re-targetted to 3.1 please?
Comment 2 Jianbo Wu CLA 2005-07-28 13:42:09 EDT
The same is true for C/C++ editors.
Comment 3 Mike Carr CLA 2006-07-10 15:35:14 EDT
I just noticed this in the production release of 3.2 as well.  It's a pretty painful one for me.  I have to manually spacebar in the compare editor instead of using tabs as we can't have tabs in our Java source.
Comment 4 Michael Valenta CLA 2006-07-10 16:55:51 EDT
The problem is that the viewer used in a comparison is not a Java editor so it has none of the niffty Java features.
Comment 5 Michael Valenta CLA 2006-09-06 11:18:13 EDT
*** Bug 154306 has been marked as a duplicate of this bug. ***
Comment 6 Adam Kiezun CLA 2006-09-06 11:25:14 EDT
Re comment 4 --- I have seen this on a regular txt file.
Comment 7 Michael Valenta CLA 2006-09-06 11:27:16 EDT
The same applied to txt (i.e. compare makes use of a SourceViewer which has different capabilites than a text editor).
Comment 8 Michael Valenta CLA 2006-09-07 09:36:52 EDT
Dani, can you give me some idea of what would be involved in moving the tabbing behavior down from the Java editor into the source viewer configuration that comapre uses?
Comment 9 Dani Megert CLA 2006-09-07 10:54:00 EDT
I suggest to wait because I plan to push this (see bug 82296) down to Platform Text anyway. If all goes well you should be able to simply configure this in the configuration.
Comment 10 Michael Valenta CLA 2006-09-07 10:59:05 EDT
Sounds good to me.
Comment 11 Dani Megert CLA 2007-03-19 07:36:42 EDT
The support is now available and can be configured directly on the text viewer (see ITextViewerExtension7.setTabsToSpacesConverter(IAutoEditStrategy)).

Create a TabsToSpacesConverter and configure it as outlined in:
AbstractTextEditor.installTabsToSpacesConverter()

Here's how to find out whether the conversion is enabled:
AbstractTextEditor.isTabsToSpacesConversionEnabled()

IMPORTANT NOTE: general text editors and the Java editor DO NOT share the same preferences when it comes to tabs width and inserting tabs/spaces. Take a look at the above methods in CompilationUnitEditor for details.
Comment 12 Michael Valenta CLA 2007-03-19 08:22:24 EDT
We will investigate for M7, time permitting.
Comment 13 Michael Valenta CLA 2007-03-28 13:23:41 EDT
Dani, I've had a quick look at the places you suggested and it looks like the only way I could possibly do this right without adding API is to add the behavior to the source viewer configuration. For basic text files, I would need to subclass SourceViewrerConfiguration and for Java I would need to subclass the JavaSourceViewerConfiguration. Is there any reason why the editor behavior was implemented at the editor level and not in the SourceViewerConfiguration (i.e. do you know of any reason why the approach I just outlined wouldn't work)?
Comment 14 Dani Megert CLA 2007-03-29 04:27:23 EDT
>Is there any reason why the editor behavior
>was implemented at the editor level and not in the SourceViewerConfiguration
That's not true for the behavior: the work is done by the TextViewer where you can call setTabsToSpacesConverter(...) and there is a TabsToSpacesConverter in jface.text. Now when it comes to the setup/configuration you're right. The main reason I've put it into the editor is because on/off and space size depends on preference and project properties, but I agree that it would also fit well into the SVC. Please file a feature request if you want this for 3.4.

Now, I don't see your point regarding subclassing the SVCs: can't you simply check the preference(s) and then call setTabsToSpacesConverter with a TabsToSpacesConverter? Keep in mind that your (Java) compare editor has to update the settings if the input changes as these settings can be project specific for CUs.
Comment 15 Michael Valenta CLA 2007-03-29 08:48:38 EDT
What I was trying to say was that I need to implement it in TextMergeViewer in such a way that the JavaMergeViewer can override it without providing API (or have a compare specific setting which is not good). The only point in the current API where this is possible is the TextMergeViewer#configureTextViewer which registers the SVC. Therefore, one approach would be to implement the behavior in the SVCs (one for Text and one for Java). I don't think I could just do it directly in the configureTextViewer method since we need to react to preference changes. I just wanted to make sure there was no technical reason why it could be done in the SVC.

I'm starting to think that the right way to do this is to log the request for Text to put the preference handling in the SVC. Without this, it becomes very difficult to describe to compare providers how get the behavior (i.e. they would get it for free if they don't use there own SVC but would need to implement it themselves if they use their own). I've logged bug 179975 against Text for putting the preference handling in the SVC and will defer this enhancement.
Comment 16 John Norvell CLA 2008-08-26 18:29:04 EDT
I am having the same problem:

I'm using eclipse 3.3.2 M20080221-1800

I've changed the global preferences for editors to use spaces rather than tabs

General > Editors > Text Editors

Displayed tab width: 3
[x] Insert spaces for tabs

However, when I reformat an XML file using editor, it replaces all of the spaces with tabs.

I have also enabled this option to visually see the tabs:

[x] Show whitespace characters.
Comment 17 Dani Megert CLA 2008-08-27 06:39:53 EDT
John, your problem is either wrong XML formatter preferences in your workspace or a bug in the XML formatter but definitely unrelated to the compare editor.
Comment 18 Tomasz Zarna CLA 2009-01-14 05:51:58 EST
This seems to be working fine, at least in Java compare since we started to embedded a Java editor (see bug 169386). The pref is no longer available under "Java | Editor | Typing | Insert space for tabs" but when I played with "Java | Code Style | Formatter" I did manage to get a result when tab gets replaced with spaces. Could someone verify if my finding is correct, I'm not 100% what expected behavior should be.

Text compare doesn't use a text editor so far (see bug 259410), so the pref won't work when comparing txt .
Comment 19 Szymon Brandys CLA 2009-01-14 06:32:42 EST
(In reply to comment #18)
> This seems to be working fine, at least in Java compare since we started to
> embedded a Java editor (see bug 169386). 

I can confirm that it works the same in the java compare and java editor.
Comment 20 Szymon Brandys CLA 2009-01-14 09:36:03 EST
This is fixed in the java compare. It still remains in the text compare, however this is covered in bug 259410.