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/wst/html/ui/internal/autoedit/StructuredAutoEditStrategyHTML.java (-42 lines)
Lines 10-29 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.html.ui.internal.autoedit;
11
package org.eclipse.wst.html.ui.internal.autoedit;
12
12
13
import org.eclipse.core.runtime.Preferences;
14
import org.eclipse.jface.text.BadLocationException;
13
import org.eclipse.jface.text.BadLocationException;
15
import org.eclipse.jface.text.DocumentCommand;
14
import org.eclipse.jface.text.DocumentCommand;
16
import org.eclipse.jface.text.IAutoEditStrategy;
15
import org.eclipse.jface.text.IAutoEditStrategy;
17
import org.eclipse.jface.text.IDocument;
16
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.IRegion;
19
import org.eclipse.ui.IEditorPart;
17
import org.eclipse.ui.IEditorPart;
20
import org.eclipse.ui.IWorkbenchPage;
18
import org.eclipse.ui.IWorkbenchPage;
21
import org.eclipse.ui.IWorkbenchWindow;
19
import org.eclipse.ui.IWorkbenchWindow;
22
import org.eclipse.ui.PlatformUI;
20
import org.eclipse.ui.PlatformUI;
23
import org.eclipse.ui.texteditor.ITextEditor;
21
import org.eclipse.ui.texteditor.ITextEditor;
24
import org.eclipse.ui.texteditor.ITextEditorExtension3;
22
import org.eclipse.ui.texteditor.ITextEditorExtension3;
25
import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
26
import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames;
27
import org.eclipse.wst.html.ui.internal.Logger;
23
import org.eclipse.wst.html.ui.internal.Logger;
28
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
24
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
29
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
25
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
Lines 53-62 Link Here
53
			if (model != null)
49
			if (model != null)
54
				model.releaseFromRead();
50
				model.releaseFromRead();
55
		}
51
		}
56
57
		// spaces for tab character
58
		if (command.text != null && command.text.length() > 0 && command.text.charAt(0) == '\t')
59
			smartInsertForTab(command, document);
60
	}
52
	}
61
53
62
	private boolean isCommentNode(IDOMNode node) {
54
	private boolean isCommentNode(IDOMNode node) {
Lines 105-144 Link Here
105
	}
97
	}
106
98
107
	/**
99
	/**
108
	 * Insert spaces for tabs
109
	 * 
110
	 * @param command
111
	 */
112
	private void smartInsertForTab(DocumentCommand command, IDocument document) {
113
		// tab key was pressed. now check preferences to see if need to insert
114
		// spaces instead of tab
115
		Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences();
116
		if (HTMLCorePreferenceNames.SPACE.equals(preferences.getString(HTMLCorePreferenceNames.INDENTATION_CHAR))) {
117
			int indentationWidth = preferences.getInt(HTMLCorePreferenceNames.INDENTATION_SIZE);
118
119
			StringBuffer indent = new StringBuffer();
120
			if (indentationWidth != 0) {
121
				int indentSize = indentationWidth;
122
				try {
123
					IRegion firstLine = document.getLineInformationOfOffset(command.offset);
124
					int offsetInLine = command.offset - firstLine.getOffset();
125
					int remainder = offsetInLine % indentationWidth;
126
127
					indentSize = indentationWidth - remainder;
128
				} catch (BadLocationException e) {
129
					Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
130
				}
131
132
				for (int i = 0; i < indentSize; i++)
133
					indent.append(' ');
134
			}
135
136
			// replace \t characters with spaces
137
			command.text = indent.toString();
138
		}
139
	}
140
141
	/**
142
	 * Return the active text editor if possible, otherwise the active editor
100
	 * Return the active text editor if possible, otherwise the active editor
143
	 * part.
101
	 * part.
144
	 * 
102
	 * 
(-)src/org/eclipse/wst/html/ui/internal/provisional/StructuredTextViewerConfigurationHTML.java (+4 lines)
Lines 42-47 Link Here
42
import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames;
42
import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames;
43
import org.eclipse.wst.html.core.internal.provisional.text.IHTMLPartitionTypes;
43
import org.eclipse.wst.html.core.internal.provisional.text.IHTMLPartitionTypes;
44
import org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML;
44
import org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML;
45
import org.eclipse.wst.html.ui.internal.autoedit.AutoEditStrategyForTabs;
45
import org.eclipse.wst.html.ui.internal.contentassist.HTMLContentAssistProcessor;
46
import org.eclipse.wst.html.ui.internal.contentassist.HTMLContentAssistProcessor;
46
import org.eclipse.wst.html.ui.internal.contentassist.NoRegionContentAssistProcessorForHTML;
47
import org.eclipse.wst.html.ui.internal.contentassist.NoRegionContentAssistProcessorForHTML;
47
import org.eclipse.wst.html.ui.internal.hyperlink.URIHyperlinkDetector;
48
import org.eclipse.wst.html.ui.internal.hyperlink.URIHyperlinkDetector;
Lines 101-106 Link Here
101
		for (int i = 0; i < superStrategies.length; i++) {
102
		for (int i = 0; i < superStrategies.length; i++) {
102
			allStrategies.add(superStrategies[i]);
103
			allStrategies.add(superStrategies[i]);
103
		}
104
		}
105
		
106
		// add auto edit strategy that handles when tab key is pressed
107
		allStrategies.add(new AutoEditStrategyForTabs());
104
108
105
		if (contentType == IHTMLPartitionTypes.HTML_DEFAULT || contentType == IHTMLPartitionTypes.HTML_DECLARATION) {
109
		if (contentType == IHTMLPartitionTypes.HTML_DEFAULT || contentType == IHTMLPartitionTypes.HTML_DECLARATION) {
106
			allStrategies.add(new StructuredAutoEditStrategyXML());
110
			allStrategies.add(new StructuredAutoEditStrategyXML());
(-)src/org/eclipse/wst/html/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.wst.html.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