diff options
| author | Patrik Suzzi | 2016-08-24 19:35:12 +0000 |
|---|---|---|
| committer | Ilya Buziuk | 2016-08-25 10:39:51 +0000 |
| commit | d1cf6821fb18fd72631c99d1880a676bf722ab3d (patch) | |
| tree | a22bc5f74accdecea070fd6e9968c314d188b353 | |
| parent | 608a757bde667744fee6055ee8b7cf1e33ff1023 (diff) | |
| download | webtools.jsdt-d1cf6821fb18fd72631c99d1880a676bf722ab3d.tar.gz webtools.jsdt-d1cf6821fb18fd72631c99d1880a676bf722ab3d.tar.xz webtools.jsdt-d1cf6821fb18fd72631c99d1880a676bf722ab3d.zip | |
Bug 356606 - [formatter] Unwanted alignment on Enter when inside array
With the provided change we have now the expected behavior, including
indentation with tabs.
See: http://i.imgur.com/CD0HiAa.gif
Change-Id: If0dee986574c708d47f04d6a3c25dc91e25c4e2d
Signed-off-by: Patrik Suzzi <psuzzi@gmail.com>
3 files changed, 29 insertions, 5 deletions
diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/javaeditor/CompilationUnitEditor.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/javaeditor/CompilationUnitEditor.java index 151d07b32..e5ec601b4 100644 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/javaeditor/CompilationUnitEditor.java +++ b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/javaeditor/CompilationUnitEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Patrik Suzzi <psuzzi@gmail.com> - Bug 356606 *******************************************************************************/ package org.eclipse.wst.jsdt.internal.ui.javaeditor; @@ -254,12 +255,13 @@ public class CompilationUnitEditor extends JavaEditor implements IJavaReconcilin // don't enter the character if if its the closing peer return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); } - // when entering an anonymous class between the parenthesis', we don't want - // to jump after the closing parenthesis when return is pressed + // skip jumping after the closing parenthesis both when + // entering an anonymous class between curly braces and when + // closing an array literal if (event.character == SWT.CR && offset > 0) { IDocument document= getSourceViewer().getDocument(); try { - if (document.getChar(offset - 1) == '{') + if (document.getChar(offset - 1) == '{'||document.getChar(offset - 1) == '[') return new ExitFlags(ILinkedModeListener.EXIT_ALL, true); } catch (BadLocationException e) { } diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/JavaIndenter.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/JavaIndenter.java index 62dda75c8..d0d660157 100644 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/JavaIndenter.java +++ b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/JavaIndenter.java @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Patrik Suzzi <psuzzi@gmail.com> - Bug 356606 *******************************************************************************/ package org.eclipse.wst.jsdt.internal.ui.text; @@ -171,7 +172,7 @@ public final class JavaIndenter { } private boolean prefArrayDimensionsDeepIndent() { - return true; // sensible default, no formatter setting + return false; // sensible default, no formatter setting } private int prefArrayIndent() { diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/JavaAutoIndentStrategy.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/JavaAutoIndentStrategy.java index bbcacc98c..97fc7ec93 100644 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/JavaAutoIndentStrategy.java +++ b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/JavaAutoIndentStrategy.java @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * Nikolay Metchev - Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=29909 * Tom Eicher (Avaloq Evolution AG) - block selection mode + * Patrik Suzzi <psuzzi@gmail.com> - Bug 356606 *******************************************************************************/ package org.eclipse.wst.jsdt.internal.ui.text.java; @@ -345,6 +346,26 @@ public class JavaAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy { buf.append(reference); } } + // insert extra line upon new line between two braces + else if (c.offset > start && contentStart < lineEnd && d.getChar(contentStart) == ']') { + int firstCharPos= scanner.findNonWhitespaceBackward(c.offset - 1, start); + if (firstCharPos != JavaHeuristicScanner.NOT_FOUND && d.getChar(firstCharPos) == '[') { + c.caretOffset= c.offset + buf.length(); + c.shiftsCaret= false; + + StringBuffer reference= null; + int nonWS= findEndOfWhiteSpace(d, start, lineEnd); + if (nonWS < c.offset && d.getChar(nonWS) == '[') + reference= new StringBuffer(d.get(start, nonWS - start)); + else + reference= indenter.getReferenceIndentation(c.offset); + + buf.append(TextUtilities.getDefaultLineDelimiter(d)); + + if (reference != null) + buf.append(reference); + } + } c.text= buf.toString(); } catch (BadLocationException e) { |
