Lines 47-58
Link Here
|
47 |
import java.util.Stack; |
47 |
import java.util.Stack; |
48 |
import javax.swing.text.BadLocationException; |
48 |
import javax.swing.text.BadLocationException; |
49 |
import javax.swing.text.Document; |
49 |
import javax.swing.text.Document; |
|
|
50 |
import javax.swing.text.EditorKit; |
51 |
import org.netbeans.api.editor.mimelookup.MimeLookup; |
52 |
import org.netbeans.api.editor.mimelookup.MimePath; |
50 |
import org.netbeans.api.lexer.Token; |
53 |
import org.netbeans.api.lexer.Token; |
51 |
import org.netbeans.api.lexer.TokenHierarchy; |
54 |
import org.netbeans.api.lexer.TokenHierarchy; |
52 |
import org.netbeans.api.lexer.TokenId; |
55 |
import org.netbeans.api.lexer.TokenId; |
53 |
import org.netbeans.api.lexer.TokenSequence; |
56 |
import org.netbeans.api.lexer.TokenSequence; |
54 |
import org.netbeans.editor.BaseDocument; |
57 |
import org.netbeans.editor.BaseDocument; |
|
|
58 |
import org.netbeans.editor.Settings; |
59 |
import org.netbeans.editor.SettingsNames; |
55 |
import org.netbeans.editor.Utilities; |
60 |
import org.netbeans.editor.Utilities; |
|
|
61 |
import org.netbeans.modules.editor.options.BaseOptions; |
56 |
import org.netbeans.modules.gsf.api.CompilationInfo; |
62 |
import org.netbeans.modules.gsf.api.CompilationInfo; |
57 |
import org.netbeans.modules.gsf.api.OffsetRange; |
63 |
import org.netbeans.modules.gsf.api.OffsetRange; |
58 |
import org.netbeans.modules.javascript.editing.lexer.LexUtilities; |
64 |
import org.netbeans.modules.javascript.editing.lexer.LexUtilities; |
Lines 98-104
Link Here
|
98 |
private Stack<StackItem> stack = new Stack<StackItem>(); |
104 |
private Stack<StackItem> stack = new Stack<StackItem>(); |
99 |
|
105 |
|
100 |
public JsFormatter() { |
106 |
public JsFormatter() { |
101 |
this.codeStyle = CodeStyle.getDefault(null); |
107 |
this.codeStyle = new DocSyncedCodeStyle(); |
102 |
} |
108 |
} |
103 |
|
109 |
|
104 |
public JsFormatter(CodeStyle codeStyle, int rightMarginOverride) { |
110 |
public JsFormatter(CodeStyle codeStyle, int rightMarginOverride) { |
Lines 119-129
Link Here
|
119 |
} |
125 |
} |
120 |
|
126 |
|
121 |
public int indentSize() { |
127 |
public int indentSize() { |
122 |
return codeStyle.getIndentSize(); |
128 |
return -1; // Use IDE defaults |
123 |
} |
129 |
} |
124 |
|
130 |
|
125 |
public int hangingIndentSize() { |
131 |
public int hangingIndentSize() { |
126 |
return codeStyle.getContinuationIndentSize(); |
132 |
return -1; // Use IDE defaults |
127 |
} |
133 |
} |
128 |
|
134 |
|
129 |
/** Compute the initial balance of brackets at the given offset. */ |
135 |
/** Compute the initial balance of brackets at the given offset. */ |
Lines 849-857
Link Here
|
849 |
* those settings |
855 |
* those settings |
850 |
*/ |
856 |
*/ |
851 |
private static void syncOptions(BaseDocument doc, CodeStyle style) { |
857 |
private static void syncOptions(BaseDocument doc, CodeStyle style) { |
852 |
org.netbeans.editor.Formatter formatter = doc.getFormatter(); |
858 |
if (style instanceof DocSyncedCodeStyle) { |
853 |
if (formatter.getSpacesPerTab() != style.getIndentSize()) { |
859 |
((DocSyncedCodeStyle)style).syncToDocument(doc); |
854 |
formatter.setSpacesPerTab(style.getIndentSize()); |
860 |
} |
|
|
861 |
} |
862 |
|
863 |
private static final class DocSyncedCodeStyle extends CodeStyle { |
864 |
private DocSyncedCodeStyle() { |
865 |
super(null); |
866 |
} |
867 |
|
868 |
private int indentSize = 4; |
869 |
private int continuationIndentSize = 4; |
870 |
private int rightMargin = 80; |
871 |
private EditorKit kit; |
872 |
|
873 |
// Copied from option.editor's org.netbeans.modules.options.indentation.IndentationModel |
874 |
private EditorKit getEditorKit() { |
875 |
if(kit == null) |
876 |
kit = MimeLookup.getLookup(MimePath.parse("text/xml")).lookup(EditorKit.class); // NOI18N |
877 |
return kit; |
878 |
} |
879 |
|
880 |
// Copied from option.editor's org.netbeans.modules.options.indentation.IndentationModel |
881 |
private Integer getSpacesPerTab() { |
882 |
Integer sp = |
883 |
(Integer) Settings.getValue(getEditorKit().getClass(), SettingsNames.SPACES_PER_TAB); |
884 |
return sp; |
885 |
} |
886 |
|
887 |
public void syncToDocument(BaseDocument doc) { |
888 |
Integer sp = getSpacesPerTab(); |
889 |
int indent = sp.intValue(); |
890 |
if (indent <= 0) { |
891 |
indent = 4; |
892 |
} |
893 |
indentSize = continuationIndentSize = indent; |
894 |
} |
895 |
|
896 |
@Override |
897 |
public int getIndentSize() { |
898 |
return indentSize; |
899 |
} |
900 |
|
901 |
@Override |
902 |
public int getContinuationIndentSize() { |
903 |
return continuationIndentSize; |
904 |
} |
905 |
|
906 |
@Override |
907 |
public boolean reformatComments() { |
908 |
// This isn't used in JavaScript yet |
909 |
return false; |
910 |
} |
911 |
|
912 |
@Override |
913 |
public boolean indentHtml() { |
914 |
// This isn't used in JavaScript yet |
915 |
return false; |
916 |
} |
917 |
|
918 |
@Override |
919 |
public int getRightMargin() { |
920 |
return rightMargin; |
855 |
} |
921 |
} |
856 |
} |
922 |
} |
857 |
|
923 |
|