Prevent error on loading search history if no active editor on startup #3146
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
We were seeing the error on startup with globalState.loadSearchHistory(), related to #3116.
When creating a new SearchState in loadSearchHistory, it was calling searchState.set searchString, which calls _recalculateSearchRanges, which tried to access the document that didn't exist.
This happened if the editor loaded with no active tab when initializing VSCodeVim, and resulted in being "stuck in insert mode" when trying to edit when the user did open a tab.
Which issue(s) this PR fixes
fixes #3143
fixes #3139
Special notes for your reviewer:
I briefly tested #3116, and it seems to work, even if you loaded no tab on startup and then jumped to the last tab you searched on.
TextEditor.js
maybe should be less assuming that there is an active text editor, not using the!
symbol. But at that point we wouldn't want to just do nothing in many cases either, so maybe there isn't a good fix (ideally the consumer of TextEditor would check for an active editor, but it is easy to forget to do so).