-
Notifications
You must be signed in to change notification settings - Fork 231
fix: address 5 upstream issues (batch rollback, throttle, CheckboxGroup, Tree, Color) #3239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,22 @@ export class Tree extends Widget { | |||||||||||||||||||||||||||||||||||||||||
| this._roots = roots; | ||||||||||||||||||||||||||||||||||||||||||
| this._activeColor = options.activeColor ?? { type: 'named', name: 'cyan' }; | ||||||||||||||||||||||||||||||||||||||||||
| this._onSelect = options.onSelect; | ||||||||||||||||||||||||||||||||||||||||||
| this.events.on('key', this.handleKey.bind(this)); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private handleKey(event: { key: string }): void { | ||||||||||||||||||||||||||||||||||||||||||
| switch (event.key) { | ||||||||||||||||||||||||||||||||||||||||||
| case 'up': | ||||||||||||||||||||||||||||||||||||||||||
| this.selectPrev(); | ||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||
| case 'down': | ||||||||||||||||||||||||||||||||||||||||||
| this.selectNext(); | ||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||
| case 'enter': | ||||||||||||||||||||||||||||||||||||||||||
| case ' ': | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
rg -n -C2 "KeyEvent|case 'space'|emit\\('key'" packages/core/src packages/ui/srcRepository: Karanjot786/TermUI Length of output: 50375 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- packages/ui/src/Tree.ts outline ---'
ast-grep outline packages/ui/src/Tree.ts || true
printf '%s\n' '--- packages/ui/src/Tree.ts lines 1-220 ---'
cat -n packages/ui/src/Tree.ts
printf '%s\n' '--- relevant imports in ui package files ---'
for f in packages/ui/src/Tree.ts packages/ui/src/Tree.test.ts; do
if [ -f "$f" ]; then
echo "### $f"
sed -n '1,80p' "$f"
else
echo "missing: $f"
fi
done
printf '%s\n' '--- KeyEvent key maps for space / printable chars ---'
cat -n packages/core/src/input/KeyMap.ts | sed -n '1,130p'Repository: Karanjot786/TermUI Length of output: 14550 Use
Proposed fix- private handleKey(event: { key: string }): void {
+ private handleKey(event: KeyEvent): void {
...
- case ' ':
+ case 'space':📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||||||||||||||||||||||||||||||||||
| this.confirm(); | ||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private _flatten(): { node: TreeNode; depth: number; path: number[]; hasChildren: boolean }[] { | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -36,6 +52,7 @@ export class Tree extends Widget { | |||||||||||||||||||||||||||||||||||||||||
| selectNext(): void { const f = this._flatten(); if (this._cursorIndex < f.length - 1) { this._cursorIndex++; this.markDirty(); } } | ||||||||||||||||||||||||||||||||||||||||||
| selectPrev(): void { if (this._cursorIndex > 0) { this._cursorIndex--; this.markDirty(); } } | ||||||||||||||||||||||||||||||||||||||||||
| toggleExpand(): void { const f = this._flatten(); const it = f[this._cursorIndex]; if (it?.hasChildren) { it.node.expanded = !it.node.expanded; this.markDirty(); } } | ||||||||||||||||||||||||||||||||||||||||||
| toggleExpandKey(): void { this.toggleExpand(); } | ||||||||||||||||||||||||||||||||||||||||||
| confirm(): void { | ||||||||||||||||||||||||||||||||||||||||||
| const f = this._flatten(); const it = f[this._cursorIndex]; | ||||||||||||||||||||||||||||||||||||||||||
| if (it) { it.hasChildren ? this.toggleExpand() : this._onSelect?.(it.node, it.path); } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Reset
hasNewCallswhen cancelling.throttled.cancel()clears the timer and arguments at Lines 46-50 but leaves this new flag set. After a cancelled window that received a second call, the next independent leading call can incorrectly trigger a trailing invocation. ResethasNewCalls = falseincancel()and cover this sequence with a regression test.Proposed fix
throttled.cancel = () => { clearTimeout(timer); timer = undefined; lastArgs = undefined; + hasNewCalls = false; };📝 Committable suggestion
🤖 Prompt for AI Agents