1
>
/*---------------------------------------------------------------------------------------------
onEnterRules.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { IndentAction } from '../../../../common/languages/languageConfiguration.js';
7
>
8
>
export const javascriptOnEnterRules = [
9
>
{
10
>
// e.g. /** | */
11
>
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
12
>
afterText: /^\s*\*\/$/,
13
>
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
14
>
}, {
15
>
// e.g. /** ...|
16
>
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
17
>
action: { indentAction: IndentAction.None, appendText: ' * ' }
18
>
}, {
19
>
// e.g. * ...|
20
>
beforeText: /^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/,
21
>
previousLineText: /(?=^(\s*(\/\*\*|\*)).*)(?=(?!(\s*\*\/)))/,
22
>
action: { indentAction: IndentAction.None, appendText: '* ' }
23
>
}, {
24
>
// e.g. */|
25
>
beforeText: /^(\t|[ ])*[ ]\*\/\s*$/,
26
>
action: { indentAction: IndentAction.None, removeText: 1 }
27
>
},
28
>
{
29
>
// e.g. *-----*/|
30
>
beforeText: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$/,
31
>
action: { indentAction: IndentAction.None, removeText: 1 }
32
>
},
33
>
{
34
>
beforeText: /^\s*(\bcase\s.+:|\bdefault:)$/,
35
>
afterText: /^(?!\s*(\bcase\b|\bdefault\b))/,
36
>
action: { indentAction: IndentAction.Indent }
37
>
},
38
>
{
39
>
previousLineText: /^\s*(((else ?)?if|for|while)\s*\(.*\)\s*|else\s*)$/,
40
>
beforeText: /^\s+([^{i\s]|i(?!f\b))/,
41
>
action: { indentAction: IndentAction.Outdent }
42
>
},
43
>
// Indent when pressing enter from inside ()
44
>
{
45
>
beforeText: /^.*\([^\)]*$/,
46
>
afterText: /^\s*\).*$/,
47
>
action: { indentAction: IndentAction.IndentOutdent, appendText: '\t' }
48
>
},
49
>
// Indent when pressing enter from inside {}
50
>
{
51
>
beforeText: /^.*\{[^\}]*$/,
52
>
afterText: /^\s*\}.*$/,
53
>
action: { indentAction: IndentAction.IndentOutdent, appendText: '\t' }
54
>
},
55
>
// Indent when pressing enter from inside []
56
>
{
57
>
beforeText: /^.*\[[^\]]*$/,
58
>
afterText: /^\s*\].*$/,
59
>
action: { indentAction: IndentAction.IndentOutdent, appendText: '\t' }
60
>
},
61
>
];
62
>
63
>
export const phpOnEnterRules = [
64
>
{
65
>
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
66
>
afterText: /^\s*\*\/$/,
67
>
action: {
68
>
indentAction: IndentAction.IndentOutdent,
69
>
appendText: ' * ',
70
>
}
71
>
},
72
>
{
73
>
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
74
>
action: {
75
>
indentAction: IndentAction.None,
76
>
appendText: ' * ',
77
>
}
78
>
},
79
>
{
80
>
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
81
>
action: {
82
>
indentAction: IndentAction.None,
83
>
appendText: '* ',
84
>
}
85
>
},
86
>
{
87
>
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
88
>
action: {
89
>
indentAction: IndentAction.None,
90
>
removeText: 1,
91
>
}
92
>
},
93
>
{
94
>
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
95
>
action: {
96
>
indentAction: IndentAction.None,
97
>
removeText: 1,
98
>
}
99
>
},
100
>
{
101
>
beforeText: /^\s+([^{i\s]|i(?!f\b))/,
102
>
previousLineText: /^\s*(((else ?)?if|for(each)?|while)\s*\(.*\)\s*|else\s*)$/,
103
>
action: {
104
>
indentAction: IndentAction.Outdent
105
>
}
106
>
},
107
>
];
108
>
109
>
export const cppOnEnterRules = [
110
>
{
111
>
previousLineText: /^\s*(((else ?)?if|for|while)\s*\(.*\)\s*|else\s*)$/,
112
>
beforeText: /^\s+([^{i\s]|i(?!f\b))/,
113
>
action: {
114
>
indentAction: IndentAction.Outdent
115
>
}
116
>
}
117
>
];
118
>
119
>
export const htmlOnEnterRules = [
120
>
{
121
>
beforeText: /<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr))([_:\w][_:\w\-.\d]*)(?:(?:[^'"/>]|"[^"]*"|'[^']*')*?(?!\/)>)[^<]*$/i,
122
>
afterText: /^<\/([_:\w][_:\w\-.\d]*)\s*>/i,
123
>
action: {
124
>
indentAction: IndentAction.IndentOutdent
125
>
}
126
>
},
127
>
{
128
>
beforeText: /<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr))([_:\w][_:\w\-.\d]*)(?:(?:[^'"/>]|"[^"]*"|'[^']*')*?(?!\/)>)[^<]*$/i,
129
>
action: {
130
>
indentAction: IndentAction.Indent
131
>
}
132
>
}
133
>
];
134
>
135
>
export const vbOnEnterRules = [
136
>
// Prevent indent after End statements and block terminators (but NOT ElseIf...Then or Else which should indent)
137
>
{
138
>
beforeText: /^\s*((End\s+(If|Sub|Function|Class|Module|Enum|Structure|Interface|Namespace|With|Select|Try|While|For|Property|Get|Set|SyncLock|Using|AddHandler|RaiseEvent|RemoveHandler|Event|Operator))|Loop|Next|Wend|Until)\b.*$/i,
139
>
action: {
140
>
indentAction: IndentAction.None
141
>
}
142
>
}
143
>
];
144
>
145
>
/*
146
>
export enum IndentAction {
147
>
None = 0,
148
>
Indent = 1,
149
>
IndentOutdent = 2,
150
>
Outdent = 3
151
>
}
152
>
*/