Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 71271 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jst/jsp/ui/internal/provisional/StructuredTextViewerConfigurationJSP.java (-1 / +15 lines)
Lines 59-64 Link Here
59
import org.eclipse.wst.css.ui.internal.style.LineStyleProviderForEmbeddedCSS;
59
import org.eclipse.wst.css.ui.internal.style.LineStyleProviderForEmbeddedCSS;
60
import org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl;
60
import org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl;
61
import org.eclipse.wst.html.core.internal.provisional.text.IHTMLPartitionTypes;
61
import org.eclipse.wst.html.core.internal.provisional.text.IHTMLPartitionTypes;
62
import org.eclipse.wst.html.ui.internal.autoedit.AutoEditStrategyForTabs;
62
import org.eclipse.wst.html.ui.internal.provisional.StructuredTextViewerConfigurationHTML;
63
import org.eclipse.wst.html.ui.internal.provisional.StructuredTextViewerConfigurationHTML;
63
import org.eclipse.wst.html.ui.internal.style.LineStyleProviderForHTML;
64
import org.eclipse.wst.html.ui.internal.style.LineStyleProviderForHTML;
64
import org.eclipse.wst.javascript.ui.internal.common.style.LineStyleProviderForJavaScript;
65
import org.eclipse.wst.javascript.ui.internal.common.style.LineStyleProviderForJavaScript;
Lines 108-114 Link Here
108
		if (contentType == IXMLPartitions.XML_DEFAULT) {
109
		if (contentType == IXMLPartitions.XML_DEFAULT) {
109
			strategies = getXMLSourceViewerConfiguration().getAutoEditStrategies(sourceViewer, contentType);
110
			strategies = getXMLSourceViewerConfiguration().getAutoEditStrategies(sourceViewer, contentType);
110
		} else if (contentType == IJSPPartitionTypes.JSP_CONTENT_JAVA) {
111
		} else if (contentType == IJSPPartitionTypes.JSP_CONTENT_JAVA) {
111
			strategies = getJavaSourceViewerConfiguration().getAutoEditStrategies(sourceViewer, IJavaPartitions.JAVA_PARTITIONING);
112
			List allStrategies = new ArrayList(0);
113
			
114
			IAutoEditStrategy[] javaStrategies = getJavaSourceViewerConfiguration().getAutoEditStrategies(sourceViewer, IJavaPartitions.JAVA_PARTITIONING);
115
			for (int i = 0; i < javaStrategies.length; i++) {
116
				allStrategies.add(javaStrategies[i]);
117
			}
118
			
119
			// add auto edit strategy that handles when tab key is pressed
120
			allStrategies.add(new AutoEditStrategyForTabs());
121
			
122
			strategies = (IAutoEditStrategy[]) allStrategies.toArray(new IAutoEditStrategy[0]);
112
		} else {
123
		} else {
113
			List allStrategies = new ArrayList(0);
124
			List allStrategies = new ArrayList(0);
114
	
125
	
Lines 116-121 Link Here
116
			for (int i = 0; i < superStrategies.length; i++) {
127
			for (int i = 0; i < superStrategies.length; i++) {
117
				allStrategies.add(superStrategies[i]);
128
				allStrategies.add(superStrategies[i]);
118
			}
129
			}
130
			
131
			// add auto edit strategy that handles when tab key is pressed
132
			allStrategies.add(new AutoEditStrategyForTabs());
119
	
133
	
120
			if (contentType == IHTMLPartitionTypes.HTML_DEFAULT || contentType == IHTMLPartitionTypes.HTML_DECLARATION) {
134
			if (contentType == IHTMLPartitionTypes.HTML_DEFAULT || contentType == IHTMLPartitionTypes.HTML_DECLARATION) {
121
				allStrategies.add(new StructuredAutoEditStrategyJSP());
135
				allStrategies.add(new StructuredAutoEditStrategyJSP());
(-)src/org/eclipse/jst/jsp/ui/internal/autoedit/AutoEditStrategyForTabs.java (+69 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *   IBM - Initial API and implementation
10
 *   Jens Lukowski/Innoopract - initial renaming/restructuring
11
 * 
12
 */
13
package org.eclipse.jst.jsp.ui.internal.autoedit;
14
15
import org.eclipse.core.runtime.Preferences;
16
import org.eclipse.jface.text.BadLocationException;
17
import org.eclipse.jface.text.DocumentCommand;
18
import org.eclipse.jface.text.IAutoEditStrategy;
19
import org.eclipse.jface.text.IDocument;
20
import org.eclipse.jface.text.IRegion;
21
import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
22
import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames;
23
import org.eclipse.wst.html.ui.internal.Logger;
24
25
/**
26
 * AutoEditStrategy to handle characters inserted when Tab key is pressed
27
 */
28
public class AutoEditStrategyForTabs implements IAutoEditStrategy {
29
30
	public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
31
		// spaces for tab character
32
		if (command.text != null && command.text.length() > 0 && command.text.charAt(0) == '\t')
33
			smartInsertForTab(command, document);
34
	}
35
36
	/**
37
	 * Insert spaces for tabs
38
	 * 
39
	 * @param command
40
	 */
41
	private void smartInsertForTab(DocumentCommand command, IDocument document) {
42
		// tab key was pressed. now check preferences to see if need to insert
43
		// spaces instead of tab
44
		Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences();
45
		if (HTMLCorePreferenceNames.SPACE.equals(preferences.getString(HTMLCorePreferenceNames.INDENTATION_CHAR))) {
46
			int indentationWidth = preferences.getInt(HTMLCorePreferenceNames.INDENTATION_SIZE);
47
48
			StringBuffer indent = new StringBuffer();
49
			if (indentationWidth != 0) {
50
				int indentSize = indentationWidth;
51
				try {
52
					IRegion firstLine = document.getLineInformationOfOffset(command.offset);
53
					int offsetInLine = command.offset - firstLine.getOffset();
54
					int remainder = offsetInLine % indentationWidth;
55
56
					indentSize = indentationWidth - remainder;
57
				} catch (BadLocationException e) {
58
					Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
59
				}
60
61
				for (int i = 0; i < indentSize; i++)
62
					indent.append(' ');
63
			}
64
65
			// replace \t characters with spaces
66
			command.text = indent.toString();
67
		}
68
	}
69
}

Return to bug 71271