-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Prevent newlines for singleline Code editor #2704
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 newlines for singleline Code editor #2704
Conversation
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.
Seems good to me 👍
What happens when you paste something with a linebreak? Can look at that in a separate PR though.
Note: There were some other changes when I saved the file/ran the app that I did not include. Am unsure if that was done based on the editor configurations or if I haven't fully configured .editorconfig correctly 😅
What were the additional files? With the change you have made I don't anticipate any other changes, but it's possible there were package-lock.json
changes (which are okay to leave out).
The changes were in the same file I was editing. Digging a bit more I think I got some mix up with the old |
No worries! I'll mark this PR as draft, feel free to mark as ready, once you're ready for review again. Take your time, no rush. 😄 |
62dc390
to
03099a7
Compare
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.
Nice UX enhancement here!
.replace(/\n/g, ' '); // Convert all whitespace to spaces | ||
change.update(change.from, change.to, [text]); | ||
} | ||
|
||
// Suppress lint on empty doc or single space exists (default value) | ||
if (value.trim() === '') { |
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.
@develohpanda Managed to clean up my branch and updated code with a version that works with latest |
Needs re-review after the fix was changed
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.
LGTM, thanks for working through this!
// Don't allow non-breaking spaces because they break the GraphQL syntax | ||
if (doc.options.mode === 'graphql' && change.text && change.text.length > 1) { |
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.
I think this condition also needs to be moved out, for the same reason? The change.text.length > 1
condition is the same, and looking through the logic the graphql editor seems like it might exhibit the same buggy behavior when first entering text.
It doesn't relate directly to the issue this PR fixes so I would suggest doing it in a separate PR if it does need to be moved.
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.
Hmmm I'm not familiar with the graphql side of things so it wasn't something I tested. But definitely happy to test it and submit a PR if you know how and when that doc.options.mode == 'graphql'
would get triggered 😃
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.
Here's an example workspace with a request containing the special character after the "title" text (see screenshot below).
I think the intended behavior of this code is to replace the special space with a regular space. If you change the text in the request body, I'm guessing it should clear the error by replacing the character 🤔
Also, on Windows you can add that special character with Alt 255
(hold alt, and type 255 on the numpad)
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.
Managed to replicate the problem and PR to fix it is here #2770 💪
Aims to fix #2569 by detecting the enter key being pressed and returning early so that it doesn't register as a key press
Behaviour before the change

Behaviour after the change

Note: There were some other changes when I saved the file/ran the app that I did not include. Am unsure if that was done based on the editor configurations or if I haven't fully configured
.editorconfig
correctly 😅