diff --git a/src/commands.ts b/src/commands.ts index 6109b83..09749f6 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -36,9 +36,8 @@ export class PeripheralCommands { try { const result = await node.performUpdate(value); if (result) { - await this.peripheralsForceRefresh(); - } else { - this.dataTracker.refresh(); + // Update the tree view + this.dataTracker.fireOnDidChange(); } } catch (error) { @@ -75,7 +74,7 @@ export class PeripheralCommands { } node.format = result.value; - this.dataTracker.refresh(); + this.dataTracker.fireOnDidChange(); } private async peripheralsForceRefresh(node?: PeripheralBaseNode): Promise { @@ -85,7 +84,7 @@ export class PeripheralCommands { await p.updateData(); } - this.dataTracker.refresh(); + this.dataTracker.fireOnDidChange(); } else { await this.dataTracker.updateData(); } diff --git a/src/components/tree/components/treetable.tsx b/src/components/tree/components/treetable.tsx index e3b1f3f..3a1d8bf 100644 --- a/src/components/tree/components/treetable.tsx +++ b/src/components/tree/components/treetable.tsx @@ -117,6 +117,41 @@ export const AntDComponentTreeTable = (props: ComponentTreeTableProps) => return props.expansion?.expandedRowKeys; }, [props.expansion?.expandedRowKeys]); + + const expandIcon = useCallback( + ({ expanded, onExpand, record, expandable }: RenderExpandIconProps) => { + if (!expandable) { + // simulate spacing to the left that we gain through expand icon so that leaf items look correctly intended + return ; + } + + const doExpand = (event: React.MouseEvent) => { + event.stopPropagation(); + onExpand(record, event); + }; + + const iconClass = expanded ? 'codicon-chevron-down' : 'codicon-chevron-right'; + return ( +
{ if (event.key === 'Enter' || event.key === ' ') doExpand(event as unknown as React.MouseEvent); }} + >
+ ); + }, + [] + ); + + const handleExpand = useCallback( + (expanded: boolean, record: CDTTreeItem) => { + props.expansion?.onExpand?.(expanded, record); + }, + [props.expansion] + ); + // ==== Renderers ==== const renderStringColumn = useCallback( @@ -221,13 +256,6 @@ export const AntDComponentTreeTable = (props: ComponentTreeTableProps) => // ==== Handlers ==== - const handleExpand = useCallback( - (expanded: boolean, record: CDTTreeItem) => { - props.expansion?.onExpand?.(expanded, record); - }, - [props.expansion] - ); - const handleRowClick = useCallback( (record: CDTTreeItem) => () => { const isExpanded = props.expansion?.expandedRowKeys?.includes(record.id); @@ -236,28 +264,6 @@ export const AntDComponentTreeTable = (props: ComponentTreeTableProps) => [props.expansion] ); - const expandIcon = useCallback( - ({ expanded, onExpand, record, expandable }: RenderExpandIconProps) => { - if (!expandable) { - // simulate spacing to the left that we gain through expand icon so that leaf items look correctly intended - return ; - } - - const iconClass = expanded ? 'codicon-chevron-down' : 'codicon-chevron-right'; - return ( -
onExpand(record, e)} - role="button" - tabIndex={0} - aria-label={expanded ? 'Collapse row' : 'Expand row'} - onKeyDown={event => { if (event.key === 'Enter' || event.key === ' ') onExpand(record, event as unknown as React.MouseEvent); }} - >
- ); - }, - [] - ); - // ==== Return ==== return
diff --git a/src/plugin/peripheral/nodes/peripheral-field-node.ts b/src/plugin/peripheral/nodes/peripheral-field-node.ts index 819637e..2370a20 100644 --- a/src/plugin/peripheral/nodes/peripheral-field-node.ts +++ b/src/plugin/peripheral/nodes/peripheral-field-node.ts @@ -30,6 +30,7 @@ export class PeripheralFieldNode extends PeripheralBaseNode { // eslint-disable-next-line @typescript-eslint/no-explicit-any private enumerationMap: any; private previousValue?: number; + private currentValue?: number; constructor(public parent: PeripheralRegisterNode, protected options: FieldOptions) { super(parent); @@ -110,7 +111,6 @@ export class PeripheralFieldNode extends PeripheralBaseNode { if (val === undefined) { return false; } - const numval = this.enumerationMap[val.label]; this.parent.updateBits(this.offset, this.width, numval).then(resolve, reject); }); @@ -129,7 +129,8 @@ export class PeripheralFieldNode extends PeripheralBaseNode { } public updateData(): Thenable { - this.previousValue = this.getCurrentValue(); + this.previousValue = this.currentValue; + this.currentValue = this.getCurrentValue(); return Promise.resolve(true); } diff --git a/src/plugin/peripheral/nodes/peripheral-node.ts b/src/plugin/peripheral/nodes/peripheral-node.ts index cfe5001..32363b7 100644 --- a/src/plugin/peripheral/nodes/peripheral-node.ts +++ b/src/plugin/peripheral/nodes/peripheral-node.ts @@ -101,7 +101,7 @@ export class PeripheralNode extends PeripheralBaseNode { try { const errors = await this.readMemory(); for (const error of errors) { - const str = `Failed to update peripheral ${this.name}: ${error}`; + const str = `Failed to read peripheral ${this.name}: ${error}`; if (vscode.debug.activeDebugConsole) { vscode.debug.activeDebugConsole.appendLine(str); } @@ -109,7 +109,7 @@ export class PeripheralNode extends PeripheralBaseNode { } catch (e) { /* This should never happen */ const msg = (e as Error).message || 'unknown error'; - const str = `Failed to update peripheral ${this.name}: ${msg}`; + const str = `Failed to read peripheral ${this.name}: ${msg}`; if (vscode.debug.activeDebugConsole) { vscode.debug.activeDebugConsole.appendLine(str); } diff --git a/src/plugin/peripheral/nodes/peripheral-register-node.ts b/src/plugin/peripheral/nodes/peripheral-register-node.ts index 1e75a24..eba1217 100644 --- a/src/plugin/peripheral/nodes/peripheral-register-node.ts +++ b/src/plugin/peripheral/nodes/peripheral-register-node.ts @@ -33,7 +33,6 @@ export class PeripheralRegisterNode extends ClusterOrRegisterBaseNode { private hexRegex: RegExp; private binaryRegex: RegExp; private currentValue: number; - private prevValue = ''; private previousValue?: number; constructor(public parent: PeripheralNode | PeripheralClusterNode, protected options: PeripheralRegisterOptions) { diff --git a/src/plugin/peripheral/tree/peripheral-data-tracker.ts b/src/plugin/peripheral/tree/peripheral-data-tracker.ts index 79a9612..2cb6a21 100644 --- a/src/plugin/peripheral/tree/peripheral-data-tracker.ts +++ b/src/plugin/peripheral/tree/peripheral-data-tracker.ts @@ -115,7 +115,7 @@ export class PeripheralDataTracker { const children = await tree.getChildren(); children.forEach(c => this.collapseNode(c, false)); } - this.refresh(); + this.fireOnDidChange(); } public toggleNode( @@ -152,12 +152,12 @@ export class PeripheralDataTracker { public async updateData(): Promise { const trees = this.sessionPeripherals.values(); for (const tree of trees) { + // The tree will trigger a refresh on it's own await tree.updateData(); } - this.refresh(); } - public refresh(): void { + public fireOnDidChange(): void { this.onDidChangeEvent.fire(); } @@ -170,7 +170,7 @@ export class PeripheralDataTracker { } if (this.sessionPeripherals.get(session.id)) { - this.refresh(); + this.fireOnDidChange(); vscode.debug.activeDebugConsole.appendLine(`Internal Error: Session ${session.name} id=${session.id} already in the tree view?`); return; } @@ -180,7 +180,7 @@ export class PeripheralDataTracker { state = this.sessionPeripherals.size === 0 ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.Collapsed; } const peripheralTree = new PeripheralTreeForSession(session, this.api, state, () => { - this.refresh(); + this.fireOnDidChange(); }); this.sessionPeripherals.set(session.id, peripheralTree); @@ -195,7 +195,7 @@ export class PeripheralDataTracker { } catch (e) { vscode.debug.activeDebugConsole.appendLine(`Internal Error: Unexpected rejection of promise ${e}`); } finally { - this.refresh(); + this.fireOnDidChange(); } vscode.commands.executeCommand('setContext', `${PeripheralTreeDataProvider.viewName}.hasData`, this.sessionPeripherals.size > 0); @@ -211,7 +211,7 @@ export class PeripheralDataTracker { this.oldState.set(session.name, regs.myTreeItem.collapsibleState); this.sessionPeripherals.delete(session.id); regs.sessionTerminated(this.context); - this.refresh(); + this.fireOnDidChange(); } vscode.commands.executeCommand('setContext', `${PeripheralTreeDataProvider.viewName}.hasData`, this.sessionPeripherals.size > 0);