Skip to content

Commit 242746b

Browse files
committed
feat: add expanded option to expand all symbols on startup
1 parent 9713385 commit 242746b

File tree

7 files changed

+17
-8
lines changed

7 files changed

+17
-8
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,16 @@
227227
"enum": [
228228
"cursor",
229229
"viewport",
230-
"manual"
230+
"manual",
231+
"expanded"
231232
],
232233
"default": "viewport",
233234
"description": "%om.config.expand.description%",
234235
"markdownEnumDescriptions": [
235236
"%om.config.expand.enumDescriptions.cursor%",
236237
"%om.config.expand.enumDescriptions.viewport%",
237-
"%om.config.expand.enumDescriptions.manual%"
238+
"%om.config.expand.enumDescriptions.manual%",
239+
"%om.config.expand.enumDescriptions.expanded%"
238240
],
239241
"order": 4
240242
},

package.nls.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
"om.config.follow.description": "Choose when to scroll the outline. If set to manual, the outline will not scroll automatically.",
1919
"om.config.follow.enumDescriptions.cursor": "Scroll when the cursor moves to the symbol.",
2020
"om.config.follow.enumDescriptions.viewport": "Scroll when the editor view scrolls.",
21-
"om.config.follow.enumDescriptions.manual": "Manual scroll.",
21+
"om.config.follow.enumDescriptions.manual": "Manually scroll.",
2222
"om.config.expand.description": "Choose when to expand the outline. If set to manual, the outline will not expand automatically.",
2323
"om.config.expand.enumDescriptions.cursor": "Expand to the symbol where the cursor is.",
2424
"om.config.expand.enumDescriptions.viewport": "Expand all visible symbols in the editor view. When `Follow` is set to `cursor`, it will only expand when the cursor moves.",
25-
"om.config.expand.enumDescriptions.manual": "Manual expand.",
25+
"om.config.expand.enumDescriptions.manual": "Manually expand, and the outline is initially collapsed.",
26+
"om.config.expand.enumDescriptions.expanded": "Manually expand, but the outline is initially expanded.",
2627
"om.config.hiddenItem.description": "Choose items to hide in the outline.",
2728
"om.config.defaultMaxDepth.description": "Set the default maximum depth of the outline, set to 0 to not limit.",
2829
"om.config.customFont.description": "Set custom font. Syntax `[ <family-name> | <generic-family> ]#`",

package.nls.zh-cn.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"om.config.expand.description": "选择何时展开大纲。",
2323
"om.config.expand.enumDescriptions.cursor": "展开到光标所在的符号。",
2424
"om.config.expand.enumDescriptions.viewport": "展开编辑器视图内的所有可见符号。当`Follow`设置为`cursor`时,仅会在光标移动时展开。",
25-
"om.config.expand.enumDescriptions.manual": "手动展开。",
25+
"om.config.expand.enumDescriptions.manual": "手动展开,且大纲初始为收起。",
26+
"om.config.expand.enumDescriptions.expanded": "手动展开,但大纲初始为展开。",
2627
"om.config.hiddenItem.description": "选择要在大纲中隐藏的项目。",
2728
"om.config.defaultMaxDepth.description": "设置默认的大纲最大深度,设为0则不限制。",
2829
"om.config.customFont.description": "设置自定义字体。语法`[ <family-name> | <generic-family> ]#`",

src/common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class SymbolNode {
9393

9494
const root: SymbolNode[] = [];
9595
const hiddenItem = config.hiddenItem();
96+
const expandOnInit = config.expand() === 'expanded';
9697

9798
// A known issue of vscode is that the DocumentSymbols returned by
9899
// command 'vscode.executeDocumentSymbolProvider' does not include the
@@ -150,6 +151,9 @@ export class SymbolNode {
150151
if (hiddenItem.includes(node.kind.toLowerCase())) {
151152
return;
152153
}
154+
if (expandOnInit) {
155+
node.expand = true;
156+
}
153157
if (Array.isArray(parent)) {
154158
parent.push(node);
155159
node.selector = node.selector.concat(`[data-key="${node.kind}-${node.name}"]`);

src/extension/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const config = {
1515
//#endregion DEPRECATED
1616
/** When to expand the outline. */
1717
follow: () => getConfig('follow') as 'cursor' | 'viewport' | 'manual',
18-
expand: () => getConfig('expand') as 'cursor' | 'viewport' | 'manual',
18+
expand: () => getConfig('expand') as 'cursor' | 'viewport' | 'manual' | 'expanded',
1919
/** Hide specified items. */
2020
hiddenItem: () => getConfig('hiddenItem') as string[],
2121
/** The initial maximum depth of the outline. */

src/extension/outline.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export class OutlineView implements WebviewViewProvider {
216216
// 1. remove all nodes in the viewport
217217
for (const node of this.inView) {
218218
node.inView = false;
219-
if (config.expand() !== 'manual') {
219+
if (config.expand() === 'cursor' || config.expand() === 'viewport') {
220220
node.expand = false;
221221
}
222222
}
@@ -265,7 +265,7 @@ export class OutlineView implements WebviewViewProvider {
265265
property: 'inview',
266266
value: node.inView,
267267
} as UpdateOp);
268-
if (this.pinStatus === PinStatus.unpinned && config.expand() !== 'manual') {
268+
if (this.pinStatus === PinStatus.unpinned && (config.expand() === 'cursor' || config.expand() === 'viewport')) {
269269
Ops.push({
270270
type: 'update',
271271
selector: node.selector.join(' >.outline-children> '),

src/webview/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ function renderSymbolNode(symbolNode: SymbolNode, depth = 0): HTMLDivElement {
244244
})
245245
);
246246
container.classList.toggle('leaf', symbolNode.children.length === 0);
247+
container.classList.toggle('expand', depth >= maxDepth ? false : symbolNode.expand);
247248
container.style.setProperty('--depth', depth.toString());
248249

249250
container.innerHTML = /*html*/`

0 commit comments

Comments
 (0)