Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 25760 Details for
Bug 105912
Pasted text contains only one space if clipboard content starts with tab
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
org.eclipse.jst.jsp.ui.patch
org.eclipse.jst.jsp.ui.patch (text/plain), 7.54 KB, created by
Amy Wu
on 2005-08-05 12:46:38 EDT
(
hide
)
Description:
org.eclipse.jst.jsp.ui.patch
Filename:
MIME Type:
Creator:
Amy Wu
Created:
2005-08-05 12:46:38 EDT
Size:
7.54 KB
patch
obsolete
>Index: src/org/eclipse/jst/jsp/ui/internal/autoedit/AutoEditStrategyForTabs.java >=================================================================== >RCS file: /home/webtools/jst/components/jsp/plugins/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/autoedit/AutoEditStrategyForTabs.java,v >retrieving revision 1.1 >diff -u -r1.1 AutoEditStrategyForTabs.java >--- src/org/eclipse/jst/jsp/ui/internal/autoedit/AutoEditStrategyForTabs.java 19 Jul 2005 21:26:49 -0000 1.1 >+++ src/org/eclipse/jst/jsp/ui/internal/autoedit/AutoEditStrategyForTabs.java 5 Aug 2005 16:43:30 -0000 >@@ -14,22 +14,36 @@ > > import org.eclipse.core.runtime.Preferences; > import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.ConfigurableLineTracker; > import org.eclipse.jface.text.DocumentCommand; > import org.eclipse.jface.text.IAutoEditStrategy; > import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.ILineTracker; > import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.TextUtilities; >+import org.eclipse.jst.jsp.ui.internal.Logger; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.texteditor.ITextEditor; >+import org.eclipse.ui.texteditor.ITextEditorExtension3; > import org.eclipse.wst.html.core.internal.HTMLCorePlugin; > import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames; >-import org.eclipse.wst.html.ui.internal.Logger; > > /** > * AutoEditStrategy to handle characters inserted when Tab key is pressed > */ > public class AutoEditStrategyForTabs implements IAutoEditStrategy { >+ private final String TAB_CHARACTER = "\t"; //$NON-NLS-1$ > > public void customizeDocumentCommand(IDocument document, DocumentCommand command) { >+ // if not in smart insert mode just ignore >+ if (!isSmartInsertMode()) >+ return; >+ > // spaces for tab character >- if (command.text != null && command.text.length() > 0 && command.text.charAt(0) == '\t') >+ if (command.length == 0 && command.text != null && command.text.length() > 0 && command.text.indexOf(TAB_CHARACTER) != -1) > smartInsertForTab(command, document); > } > >@@ -41,29 +55,133 @@ > private void smartInsertForTab(DocumentCommand command, IDocument document) { > // tab key was pressed. now check preferences to see if need to insert > // spaces instead of tab >- Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences(); >- if (HTMLCorePreferenceNames.SPACE.equals(preferences.getString(HTMLCorePreferenceNames.INDENTATION_CHAR))) { >- int indentationWidth = preferences.getInt(HTMLCorePreferenceNames.INDENTATION_SIZE); >+ int indentationWidth = getIndentationWidth(); >+ if (indentationWidth > -1) { >+ String originalText = command.text; >+ StringBuffer newText = new StringBuffer(originalText); >+ >+ // determine where in line this command begins >+ int lineOffset = -1; >+ try { >+ IRegion lineInfo = document.getLineInformationOfOffset(command.offset); >+ lineOffset = command.offset - lineInfo.getOffset(); >+ } catch (BadLocationException e) { >+ Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >+ } > >- StringBuffer indent = new StringBuffer(); >- if (indentationWidth != 0) { >- int indentSize = indentationWidth; >- try { >- IRegion firstLine = document.getLineInformationOfOffset(command.offset); >- int offsetInLine = command.offset - firstLine.getOffset(); >- int remainder = offsetInLine % indentationWidth; >- >- indentSize = indentationWidth - remainder; >- } catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >+ ILineTracker lineTracker = getLineTracker(document, originalText); >+ >+ int startIndex = 0; >+ int index = newText.indexOf(TAB_CHARACTER); >+ while (index != -1) { >+ String indent = getIndentString(indentationWidth, lineOffset, lineTracker, index); >+ >+ // replace \t character with spaces >+ newText.replace(index, index + 1, indent); >+ if (lineTracker != null) { >+ try { >+ lineTracker.replace(index, 1, indent); >+ } catch (BadLocationException e) { >+ // if something goes wrong with replacing text, just >+ // reset to current string >+ lineTracker.set(newText.toString()); >+ Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >+ } > } > >- for (int i = 0; i < indentSize; i++) >- indent.append(' '); >+ startIndex = index + indent.length(); >+ index = newText.indexOf(TAB_CHARACTER, startIndex); >+ } >+ command.text = newText.toString(); >+ } >+ } >+ >+ /** >+ * Calculate number of spaces for next tab stop >+ */ >+ private String getIndentString(int indentationWidth, int lineOffset, ILineTracker lineTracker, int index) { >+ int indentSize = indentationWidth; >+ int offsetInLine = -1; >+ if (lineTracker != null) { >+ try { >+ IRegion lineInfo = lineTracker.getLineInformationOfOffset(index); >+ if (lineInfo.getOffset() == 0 && lineOffset > -1) >+ offsetInLine = lineOffset + index; >+ else >+ offsetInLine = index - lineInfo.getOffset(); >+ } catch (BadLocationException e) { >+ Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >+ } >+ } else { >+ if (lineOffset > -1) { >+ offsetInLine = lineOffset + index; > } >+ } >+ if (offsetInLine > -1) { >+ int remainder = offsetInLine % indentationWidth; >+ indentSize = indentationWidth - remainder; >+ } > >- // replace \t characters with spaces >- command.text = indent.toString(); >+ StringBuffer indent = new StringBuffer(); >+ for (int i = 0; i < indentSize; i++) >+ indent.append(' '); >+ return indent.toString(); >+ } >+ >+ /** >+ * Set up a line tracker for text within command if text is multi-line >+ */ >+ private ILineTracker getLineTracker(IDocument document, String originalText) { >+ ConfigurableLineTracker lineTracker = null; >+ int[] delims = TextUtilities.indexOf(document.getLegalLineDelimiters(), originalText, 0); >+ if (delims[0] != -1 || delims[1] != -1) { >+ lineTracker = new ConfigurableLineTracker(document.getLegalLineDelimiters()); >+ lineTracker.set(originalText); > } >+ return lineTracker; >+ } >+ >+ /** >+ * Return true if active editor is in smart insert mode, false otherwise >+ * >+ * @return >+ */ >+ private boolean isSmartInsertMode() { >+ boolean isSmartInsertMode = false; >+ >+ ITextEditor textEditor = null; >+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); >+ if (window != null) { >+ IWorkbenchPage page = window.getActivePage(); >+ if (page != null) { >+ IEditorPart editor = page.getActiveEditor(); >+ if (editor != null) { >+ if (editor instanceof ITextEditor) >+ textEditor = (ITextEditor) editor; >+ else >+ textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class); >+ } >+ } >+ } >+ >+ // check if smart insert mode >+ if (textEditor instanceof ITextEditorExtension3 && ((ITextEditorExtension3) textEditor).getInsertMode() == ITextEditorExtension3.SMART_INSERT) >+ isSmartInsertMode = true; >+ return isSmartInsertMode; >+ } >+ >+ /** >+ * Returns indentation width if using spaces for indentation, -1 otherwise >+ * >+ * @return >+ */ >+ private int getIndentationWidth() { >+ int width = -1; >+ >+ Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences(); >+ if (HTMLCorePreferenceNames.SPACE.equals(preferences.getString(HTMLCorePreferenceNames.INDENTATION_CHAR))) >+ width = preferences.getInt(HTMLCorePreferenceNames.INDENTATION_SIZE); >+ >+ return width; > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 105912
: 25760 |
25761
|
25762