Repository navigation
fix: correctly handle falsy values in HistoryNavigator._currentPosition - #301176
Sangeet (Muszic) wants to merge 8 commits into
Conversation
|
Can you review the pr please Federico Brancasi (@federicobrancasi) |
2 similar comments
|
Can you review the pr please Federico Brancasi (@federicobrancasi) |
|
Can you review the pr please Federico Brancasi (@federicobrancasi) |
|
review the pr please Federico Brancasi (@federicobrancasi) |
|
Federico Brancasi (@federicobrancasi) review the PR please |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR fixes HistoryNavigator handling of falsy history entries (e.g., empty string) by avoiding a truthiness check when determining the current position, and adds a regression test to cover the scenario.
Changes:
- Update
_currentPosition()to treat onlynullas “no current element” (so falsyTvalues remain valid). - Add a test ensuring
previous()returnsnullwhen positioned at the first element even if that element is falsy ('').
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/vs/base/common/history.ts | Fixes falsy-element handling by replacing a truthiness check with a null check. |
| src/vs/base/test/common/history.test.ts | Adds a regression test for previous() behavior when the first element is a falsy value. |
|
|
||
| testObject.first(); | ||
|
|
||
| assert.deepStrictEqual(testObject.previous(), null); |
|
Federico Brancasi (@federicobrancasi) Please review |
This PR fixes a bug in
HistoryNavigator._currentPosition()where a falsy check (!currentElement) was used instead of a strict null check (currentElement === null).The Issue:
If the history contained a valid falsy value (such as an empty string
''from a cleared search input),!currentElementevaluated totrue, causing_currentPosition()to incorrectly return-1. This broke state-dependent methods likeisFirst(),isLast(), andprevious().The Fix:
Replaced
if (!currentElement)withif (currentElement === null)to ensure valid falsy values like'',0, orfalseare properly indexed.Tests:
Added a regression test to
history.test.tsto ensureisFirst()andprevious()correctly handle the start of the history array when the first element is a falsy value.