Skip to content

Commit 78682b1

Browse files
committed
add auto folding
1 parent 7fde24a commit 78682b1

File tree

8 files changed

+648
-4
lines changed

8 files changed

+648
-4
lines changed

Context.sublime-menu

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// [
2+
// {
3+
// "id": "fold-angular-imports",
4+
// "caption": "Angular Imports",
5+
// "children": [
6+
// {
7+
// "caption": "Fold Import Statements",
8+
// "command": "fold_import_statements"
9+
// },
10+
// {
11+
// "caption": "Fold Import Arrays",
12+
// "command": "fold_import_arrays"
13+
// },
14+
// {
15+
// "caption": "Fold All Imports",
16+
// "command": "fold_all_imports"
17+
// },
18+
// {
19+
// "caption": "-"
20+
// },
21+
// {
22+
// "caption": "Unfold Import Statements",
23+
// "command": "unfold_import_statements"
24+
// },
25+
// {
26+
// "caption": "Unfold Import Arrays",
27+
// "command": "unfold_import_arrays"
28+
// },
29+
// {
30+
// "caption": "Unfold All Imports",
31+
// "command": "unfold_all_imports"
32+
// }
33+
// ]
34+
// }
35+
// ]

Default.sublime-commands

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[
2+
{
3+
"caption": "Ngx HTML: Settings",
4+
"command": "edit_settings",
5+
"args": {
6+
"base_file": "${packages}/Ngx HTML/NgxHTML.sublime-settings"
7+
}
8+
},
9+
{
10+
"caption": "Angular Imports: Fold Import Statements",
11+
"command": "fold_import_statements"
12+
},
13+
{
14+
"caption": "Angular Imports: Fold Import Arrays",
15+
"command": "fold_import_arrays"
16+
},
17+
{
18+
"caption": "Angular Imports: Fold All Imports",
19+
"command": "fold_all_imports"
20+
},
21+
{
22+
"caption": "Angular Imports: Unfold Import Statements",
23+
"command": "unfold_import_statements"
24+
},
25+
{
26+
"caption": "Angular Imports: Unfold Import Arrays",
27+
"command": "unfold_import_arrays"
28+
},
29+
{
30+
"caption": "Angular Imports: Unfold All Imports",
31+
"command": "unfold_all_imports"
32+
}
33+
]

Main.sublime-menu

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[
2+
{
3+
"id": "preferences",
4+
"children": [
5+
{
6+
"caption": "Package Settings",
7+
"id": "package-settings",
8+
"children": [
9+
{
10+
"caption": "Ngx HTML",
11+
"children": [
12+
{
13+
"caption": "Settings",
14+
"command": "edit_settings",
15+
"args": {
16+
"base_file": "${packages}/Ngx HTML/NgxHTML.sublime-settings",
17+
"default": "// Settings in here override those in \"Ngx HTML/NgxHTML.sublime-settings\",\n\n{\n\t$0\n}\n"
18+
}
19+
},
20+
{
21+
"caption": "Context Menu",
22+
"command": "edit_settings",
23+
"args": {
24+
"base_file": "${packages}/Ngx HTML/Context.sublime-menu",
25+
"default": "// Copy and uncomment\n\n[\n\t$0\n]\n"
26+
}
27+
},
28+
{
29+
"caption": "Main Menu",
30+
"command": "edit_settings",
31+
"args": {
32+
"base_file": "${packages}/Ngx HTML/Main.sublime-menu",
33+
"default": "// Copy and uncomment\n\n[\n\t$0\n]\n"
34+
}
35+
}
36+
]
37+
},
38+
]
39+
}
40+
]
41+
}
42+
// {
43+
// "id": "edit",
44+
// "children": [
45+
// {
46+
// "id": "angular-imports-folding",
47+
// "caption": "Angular Imports",
48+
// "children": [
49+
// {
50+
// "caption": "Fold Import Statements",
51+
// "command": "fold_import_statements"
52+
// },
53+
// {
54+
// "caption": "Fold Import Arrays",
55+
// "command": "fold_import_arrays"
56+
// },
57+
// {
58+
// "caption": "Fold All Imports",
59+
// "command": "fold_all_imports"
60+
// },
61+
// {
62+
// "caption": "-"
63+
// },
64+
// {
65+
// "caption": "Unfold Import Statements",
66+
// "command": "unfold_import_statements"
67+
// },
68+
// {
69+
// "caption": "Unfold Import Arrays",
70+
// "command": "unfold_import_arrays"
71+
// },
72+
// {
73+
// "caption": "Unfold All Imports",
74+
// "command": "unfold_all_imports"
75+
// }
76+
// ]
77+
// }
78+
// ]
79+
// }
80+
]

NgxHTML.sublime-settings

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extensions": [
3+
"component.html",
4+
"html",
5+
],
6+
"auto_fold_angular_imports": false
7+
}

README.md

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,100 @@ Now it supports Angular control flow.
7373
}
7474
```
7575

76-
## How to use
76+
## Angular Imports Folding
77+
78+
This package now includes functionality to fold import statements and import arrays in Angular TypeScript files to improve code readability.
79+
80+
### Features
81+
82+
- **Optional Automatic Folding**: When enabled, automatically folds import statements and import arrays when opening `.ts` files
83+
- **Separate Control**: Independent commands to fold/unfold import statements vs import arrays
84+
- **Smart Detection**: Groups import statements intelligently and only processes Angular files for import arrays
85+
- **Manual Commands**: Multiple commands for fine-grained control
86+
- **Non-Intrusive**: Auto-folding is disabled by default and must be explicitly enabled
87+
88+
### Usage
89+
90+
#### Enable Auto-Folding
91+
92+
Auto-folding is **disabled by default**. To enable it:
93+
94+
1. Go to `Preferences > Package Settings > NgxHTML > Settings`
95+
2. Set `"auto_fold_angular_imports": true`
96+
97+
#### Manual Commands
98+
99+
Access these commands via Command Palette (`Ctrl+Shift+P` / `Cmd+Shift+P`):
100+
101+
- **Angular Imports: Fold Import Statements** - Fold import statements at top of file
102+
- **Angular Imports: Fold Import Arrays** - Fold imports arrays in Angular decorators
103+
- **Angular Imports: Fold All Imports** - Fold both import statements and arrays
104+
- **Angular Imports: Unfold Import Statements** - Unfold import statements only
105+
- **Angular Imports: Unfold Import Arrays** - Unfold import arrays only
106+
- **Angular Imports: Unfold All Imports** - Unfold everything
107+
108+
#### How It Works
109+
110+
**Import Statements Folding**:
111+
1. Processes all `.ts` files
112+
2. Finds import statements at the top of the file
113+
3. Groups consecutive imports, separated by blank lines or comments
114+
4. Leaves the first import of each group visible
115+
116+
**Import Arrays Folding**:
117+
1. Looks for `@Component` or `@Directive` decorators
118+
2. Finds `imports: [` patterns within decorators
119+
3. Folds the content between the brackets
120+
121+
#### Examples
122+
123+
**Import Statements (Before)**:
124+
```typescript
125+
import { CommonModule } from '@angular/common';
126+
import { FormsModule } from '@angular/forms';
127+
import { MatButtonModule } from '@angular/material/button';
128+
129+
import { MyService } from './my-service';
130+
import { UtilsService } from '../utils/utils.service';
131+
```
132+
133+
**Import Statements (After)**:
134+
```typescript
135+
import { CommonModule } from '@angular/common';
136+
[•••]
137+
138+
import { MyService } from './my-service';
139+
[•••]
140+
```
141+
142+
**Import Arrays (Before)**:
143+
```typescript
144+
@Component({
145+
selector: 'app-example',
146+
imports: [
147+
CommonModule,
148+
FormsModule,
149+
MatButtonModule,
150+
MyComponent
151+
],
152+
templateUrl: './example.component.html'
153+
})
154+
```
155+
156+
**Import Arrays (After)**:
157+
```typescript
158+
@Component({
159+
selector: 'app-example',
160+
imports: [•••],
161+
templateUrl: './example.component.html'
162+
})
163+
```
164+
165+
## How to use syntax
77166

78167
The syntax is listed as `Ngx HTML` in Sublime syntax selection list.
79168

80-
I personaly use [ApplySyntax](https://github.com/facelessuser/ApplySyntax) plugin
169+
You could use [ApplySyntax](https://github.com/facelessuser/ApplySyntax) plugin
81170
with the following setting:
82171

83172
```json
@@ -90,4 +179,4 @@ with the following setting:
90179
```
91180

92181
You could use it in other ways...
93-
e.g. set it as the default syntax for all html files, since it's a superset of the html syntax anyway.
182+
e.g. set it as the default syntax for all html files, since it's a superset of the default html syntax anyway.

0 commit comments

Comments
 (0)