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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent newlines for singleline Code editor #2704
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -795,18 +795,20 @@ class CodeEditor extends React.Component { | |
|
||
_codemirrorValueBeforeChange(doc, change) { | ||
const value = this.codeMirror.getDoc().getValue(); | ||
|
||
// If we're in single-line mode, merge all changed lines into one | ||
if (this.props.singleLine && change.text && change.text.length > 1) { | ||
const text = change.text | ||
.join('') // join all changed lines into one | ||
.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() === '') { | ||
this._codemirrorSmartSetOption('lint', false); | ||
} else { | ||
this._codemirrorSmartSetOption('lint', this.props.lintOptions || true); | ||
// If we're in single-line mode, merge all changed lines into one | ||
if (this.props.singleLine && change.text && change.text.length > 1) { | ||
const text = change.text | ||
.join('') // join all changed lines into one | ||
.replace(/\n/g, ' '); // Convert all whitespace to spaces | ||
change.update(change.from, change.to, [text]); | ||
} | ||
|
||
// Don't allow non-breaking spaces because they break the GraphQL syntax | ||
if (doc.options.mode === 'graphql' && change.text && change.text.length > 1) { | ||
Comment on lines
813
to
814
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 馃挭 |
||
|
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.
A newline value when trimmed will be an empty string so old code to detect multilines is skipped. So just moved code up to allow processing so no net new code 馃挭