Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 95618 - Cannot specify spaces for tabs in JavaScript editor
Summary: Cannot specify spaces for tabs in JavaScript editor
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Webtools.WST.Javascript (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Amy Wu CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-17 14:02 EDT by Baron Roberts CLA
Modified: 2010-03-03 11:35 EST (History)
2 users (show)

See Also:


Attachments
Adds a group to the js source preferences to manage tab vs spaces and tab width (20.13 KB, patch)
2006-02-25 15:57 EST, Rudi Pettazzi CLA
no flags Details | Diff
patch to javascript.core & javascript.ui (24.02 KB, patch)
2006-03-13 14:31 EST, Amy Wu CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Baron Roberts CLA 2005-05-17 14:02:25 EDT
The JavaScript editor inserts tabs for indentation and I cannot find a way to 
tell it to use spaces. I have looked in all the expected places in the 
preferences (i.e. General > Editors > Structured Text Editors, General > 
Editors > Text Editors, Web and XML > JavaScript Files > JavaScript Sources).
Comment 1 David Williams CLA 2005-06-15 01:24:05 EDT
Changed Version field given new release numbering.
Comment 2 Rudi Pettazzi CLA 2006-02-25 15:57:27 EST
Created attachment 35359 [details]
Adds a group  to the js source preferences to manage tab vs spaces and tab width

This patch adds a group to the source preference page so that the user can
choose between tabs vs spaces indenting. Tab/spaces width can be specified as well. 
The feature is implemented in the attached TabsAutoEditStrategy and SourceViewerConfiguration
Comment 3 Amy Wu CLA 2006-02-27 17:09:11 EST
Thank you so much for patch.  I will look into applying it.  Using TabsAutoEditStrategy & SourceViewerConfiguration sounds like the right approach.  Did you basically use what is done in the SSE editors as an example?
Comment 4 Rudi Pettazzi CLA 2006-02-28 18:22:44 EST
(In reply to comment #3)
> Thank you so much for patch.  I will look into applying it.  Using
> TabsAutoEditStrategy & SourceViewerConfiguration sounds like the right
> approach.  Did you basically use what is done in the SSE editors as an example?

My impl. of AutoEditStrategy is simpler, I don't know if I'm missing something.
Another difference is that the js editor does not use the sse so I had to do to make sure that the right configured tabs were used even when you select 2+ lines of code and shift right. In that case the customizeCommand of autoeditstretgy is not called so I make sure that the textWidget.setTabs(int) is called when tabs preferences are updated.

Comment 5 Rudi Pettazzi CLA 2006-02-28 19:31:18 EST
By the way, I notice now (using the latest release - 1.0.0.v200602062135 - so no patch involved) that everyitme you select one or more lines of text and press tab, everyting runs fine apparently, but the error log reports: 

Exception in notifyChanged() of LineStyleProviderForJava

java.lang.IllegalArgumentException: Index out of bounds
	at org.eclipse.swt.SWT.error(SWT.java:2926)
	at org.eclipse.swt.SWT.error(SWT.java:2865)
	at org.eclipse.swt.SWT.error(SWT.java:2836)
	at org.eclipse.swt.custom.StyledText.redrawRange(StyledText.java:6203)
	at org.eclipse.wst.javascript.ui.internal.editor.JSLineStyleListener.redrawRegion(JSLineStyleListener.java:548)
	at org.eclipse.wst.javascript.ui.internal.editor.JSLineStyleListener.documentChanged(JSLineStyleListener.java:179)
	at org.eclipse.jface.text.AbstractDocument.doFireDocumentChanged2(AbstractDocument.java:729)
	at org.eclipse.jface.text.AbstractDocument.doFireDocumentChanged(AbstractDocument.java:692)
	at org.eclipse.jface.text.AbstractDocument.doFireDocumentChanged(AbstractDocument.java:677)
	at org.eclipse.jface.text.AbstractDocument.fireDocumentChanged(AbstractDocument.java:754)
	at org.eclipse.jface.text.AbstractDocument.replace(AbstractDocument.java:1112)
	at org.eclipse.jface.text.AbstractDocument.replace(AbstractDocument.java:1119)
	at org.eclipse.jface.text.TextViewer.shiftRight(TextViewer.java:3857)
	at org.eclipse.jface.text.TextViewer.shift(TextViewer.java:3809)
	at org.eclipse.jface.text.TextViewer.doOperation(TextViewer.java:3531)
	at org.eclipse.jface.text.source.SourceViewer.doOperation(SourceViewer.java:801)
	at org.eclipse.ui.texteditor.ShiftAction$1.run(ShiftAction.java:85)

and so on ...

Don't know if I should fill a bug for this.

Eclipse SDK 1.3.2
Comment 6 Amy Wu CLA 2006-03-10 14:46:11 EST
Actually, I believe that additional bug you are seeing is bug 92962
Comment 7 Amy Wu CLA 2006-03-13 14:28:25 EST
Okay, I've looked over the patch some more. I noticed the TabsAutoEditStrategy attached itself as a preference listener to keep track of when the tabs for spaces.  The problem is that I could not find where it removes itself as a preference listner.  This could turn into memory leaks.

I also noticed TabsAutoEditStrategy had a similar problem bug 105912 had.  If I copied and pasted text that had a tab in the middle of it, I would lose everything that was before the tab character.

Got any solutions for these issues?

I will attach a patch I created that takes the same approach as the source editors.  I think a difference in our fix approach is that instead of listening for a preference change, I am just checking the preference every time.  The problem I have is that I cannot short circuit the shift right & shift left actions to check the preference each time because those actions are in the SourceViewer, which JSEditor does not subclass.  So if the user changes the tab preference, the new preference is not picked up by shift right/left until after user closes and reopens the editor.

So I guess both our solutions are not fully there yet.
Comment 8 Amy Wu CLA 2006-03-13 14:31:23 EST
Created attachment 36173 [details]
patch to javascript.core & javascript.ui

Here's my partial solution.  See previous comment for more info.
Comment 9 Amy Wu CLA 2006-03-29 16:42:03 EST
I found a workaround to the problem with my patch (I basically add a preference listener in JSEditor that updates the indent prefixes when the preference changes) I also found a fix for bug 92962.  Both fixes should be in this week's ibuild.
Comment 10 Amy Wu CLA 2006-03-29 16:44:16 EST
released for this week's ibuild
Comment 11 John Lanuti CLA 2006-11-28 15:58:36 EST
This is part of a mass update to close out all stale WTP resolved bugs from the 1.0.x and 1.5.0 timeframe.  If you feel this bug was closed inappropriately, please reopen.

Thanks, John Lanuti