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

Shows 'NaN' everytime and throws TypeError: Cannot read property 'getSelectedText' of undefined #81

Open
vivi90 opened this issue May 3, 2021 · 8 comments
Assignees
Labels

Comments

@vivi90
Copy link
Member

vivi90 commented May 3, 2021

Sometimes it happens, that the plugin is not usable, because it continues to display NaN.
In such a situation it also throws at least at the developer console the following message:

Uncaught TypeError: Cannot read property 'getSelectedText' of undefined
    at DecHexOctBinView.getSelectedText (dec-hex-oct-bin-view.js:73)
    at DecHexOctBinView.parseAsHex (dec-hex-oct-bin-view.js:85)
getSelectedText    @    dec-hex-oct-bin-view.js:73
parseAsHex    @    dec-hex-oct-bin-view.js:85

Confirmed affected operating systems are both Windows 10 and Manjaro Linux.
Some users are lucky and after closing and reopening the plugin panel, it works again.
But some users not.
Here are the environment versions of one of the unlucky users on Windows 10:

Atom    : 1.55.0       
Electron: 6.1.12       
Chrome  : 76.0.3809.146
Node    : 12.4.0  

The origin of this issue seems to be:

return atom.workspace.getActiveTextEditor().getSelectedText();

So this might be an issue with Atom itself?
Unfortunately this issue seems to be hardly reproducible.

@UziTech
Copy link
Member

UziTech commented May 3, 2021

Looks like it happens when the active pane is not a text editor.

The fix would probably be to return document.getSelection() if the active pane is not a text editor.

@vivi90
Copy link
Member Author

vivi90 commented May 3, 2021

Looks like it happens when the active pane is not a text editor.

I have seen a screenshot and it looks like the active pane was a text editor.

The fix would probably be to return document.getSelection() if the active pane is not a text editor.

Insteresting, might be a good idea to add that.

@UziTech
Copy link
Member

UziTech commented May 5, 2021

It looks like the issue happens when the dec-hex-oct-bin view is in the center workspace instead of in a dock. When a button is clicked the dec-hex-oct-bin view is activated making the TextEditor no longer the active pane item.

To fix this we have to find a way to get the selected text from the "last active" TextEditor instead of the "current active" TextEditor.

@vivi90
Copy link
Member Author

vivi90 commented May 5, 2021

It looks like the issue happens when the dec-hex-oct-bin view is in the center workspace instead of in a dock. When a button is clicked the dec-hex-oct-bin view is activated making the TextEditor no longer the active pane item.

At first i feel better with it, if the user has confirmed this.

To fix this we have to find a way to get the selected text from the "last active" TextEditor instead of the "current active" TextEditor.

I think it might be a more reliable solution, if we preventing the plugin pane from became a part of the center view by using the getAllowedLocations() method.

@UziTech
Copy link
Member

UziTech commented May 5, 2021

That sounds like an easier solution 👍

@UziTech
Copy link
Member

UziTech commented May 5, 2021

And we should add a check in getSelectedText that getActiveTextEditor() doesn't return undefined.

@vivi90
Copy link
Member Author

vivi90 commented May 5, 2021

And we should add a check in getSelectedText that getActiveTextEditor() doesn't return undefined.

Oh yes.
I think at this point it might be a good idea to also support other sorts of selection.

@vivi90
Copy link
Member Author

vivi90 commented May 5, 2021

And if none found but clicked it shows a friendly message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants