Skip to content

Commit

Permalink
Merge pull request #8 from wilsonneto-dev/wn/improve-model-for-custom…
Browse files Browse the repository at this point in the history
…-behavior

feat: Improve model for custom collapse state and custom nav on click
  • Loading branch information
wilsonneto-dev authored Oct 19, 2024
2 parents 00f4045 + 2434118 commit bcef986
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Change Log

All notable changes to the "httpfile-navigation" extension will be documented in this file.
All notable changes to the "navigation-powerups" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]

- Initial release
9 changes: 7 additions & 2 deletions src/editors/vscode/TreeNavigationAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ export default class TreeNavigationAdapter implements vscode.TreeDataProvider<vs

private convertToTreeItems(nodes: NavigationNode[]): vscode.TreeItem[] {
return nodes.map(node => {
const treeItem = new vscode.TreeItem(node.getName(), node.getChildren().length > 0 ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None);
if(node.getChildren().length === 0) {
var treeItemCollapsibleState = vscode.TreeItemCollapsibleState.None;
if(node.getChildren().length > 0)
treeItemCollapsibleState = node.getInitialStateAsCollapsed() ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.Expanded;

const treeItem = new vscode.TreeItem(node.getName(), treeItemCollapsibleState);

if(node.getChildren().length === 0 || node.getNavigateToLineOnClick()) {
treeItem.command = {
command: navigationCommandName,
title: 'Navigate',
Expand Down
20 changes: 19 additions & 1 deletion src/model/NavigationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ export default class NavigationNode {
private lineNumber: number | null;
private level: number;
private children: NavigationNode[];
private initialStateAsCollapsed: boolean;
private navigateToLineOnClick: boolean

constructor(name: string, level: number = 0, lineNumber: number | null = null) {
constructor(
name: string,
level: number = 0,
lineNumber: number | null = null,
initialStateAsCollapsed: boolean = false,
navigateToLineOnClick: boolean = true
) {
this.name = name;
this.level = level;
this.lineNumber = lineNumber;
this.children = [];
this.initialStateAsCollapsed = initialStateAsCollapsed;
this.navigateToLineOnClick = navigateToLineOnClick;
}

addChild(child: NavigationNode): void {
Expand All @@ -30,4 +40,12 @@ export default class NavigationNode {
getLineNumber(): number | null {
return this.lineNumber;
}

getInitialStateAsCollapsed(): boolean {
return false;
}

getNavigateToLineOnClick(): boolean {
return this.navigateToLineOnClick;
}
}

0 comments on commit bcef986

Please sign in to comment.