Skip to content
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

Prevent error on loading search history if no active editor on startup #3146

Conversation

shawnaxsom
Copy link
Contributor

What this PR does / why we need it:

We were seeing the error on startup with globalState.loadSearchHistory(), related to #3116.

TypeError: Cannot read property 'document' of undefined

[Extension Host] Here is the error stack:  TypeError: Cannot read property 'document' of undefined
	at Function.getDocumentName (/Users/shawnaxsom/side-projects/Vim/out/src/textEditor.js:62:47)
	at SearchState._recalculateSearchRanges (/Users/shawnaxsom/side-projects/Vim/out/src/state/searchState.js:52:88)
	at SearchState.set searchString [as searchString] (/Users/shawnaxsom/side-projects/Vim/out/src/state/searchState.js:43:18)
	at new SearchState (/Users/shawnaxsom/side-projects/Vim/out/src/state/searchState.js:25:27)
	at __dirname.loadSearchHistory.GlobalState._searchHistory.get.forEach.val (/Users/shawnaxsom/side-projects/Vim/out/src/state/globalState.js:26:63)
	at Array.forEach (<anonymous>)
	at GlobalState.loadSearchHistory (/Users/shawnaxsom/side-projects/Vim/out/src/state/globalState.js:26:18)
	at /Users/shawnaxsom/side-projects/Vim/out/extension.js:248:21
	at Generator.next (<anonymous>)
	at __awaiter (/Users/shawnaxsom/side-projects/Vim/out/extension.js:7:71)
	at new Promise (<anonymous>)
	at __awaiter (/Users/shawnaxsom/side-projects/Vim/out/extension.js:3:12)
	at activate (/Users/shawnaxsom/side-projects/Vim/out/extension.js:64:12)
[...]

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).

We were seeing the error on startup with globalState.loadSearchHistory().

TypeError: Cannot read property 'document' of undefined

This happened if the editor loaded with no active tab when initializing VSCodeVim.

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.
@xconverge
Copy link
Member

Sorry! Thanks for the fix!

@xconverge
Copy link
Member

If @jpoon can't push a release soon, I can tonight

@xconverge xconverge merged commit 6de5685 into VSCodeVim:master Oct 18, 2018
@shawnaxsom shawnaxsom deleted the bugfix/crash-on-loading-search-history-no-tabs branch October 18, 2018 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 0.16.10 stuck in insert mode Escape key stopped being registered so can't exit insert mode
2 participants