-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 GraphQL non breaking space #2770
Prevent GraphQL non breaking space #2770
Conversation
@@ -804,16 +804,16 @@ class CodeEditor extends React.Component { | |||
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 > 0) { |
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.
change.text
is an array of the text that is inputted with each element being a line of text that was entered
- most cases would just be a single line so
change.text.length
== 1 - if
Enter
is pressed or text with newline is pasted thenchange.text.length
will be greater than 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.
@@ -990,7 +991,7 @@ class CodeEditor extends Component<Props, State> { | |||
} | |||
} | |||
|
|||
_codemirrorValueBeforeChange(doc, change) { | |||
_codemirrorValueBeforeChange(doc: CodeMirror.Editor, change: CodeMirror.EditorChangeCancellable) { |
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.
@gatzjames I believe we should be using CodeMirror.EditorFromTextArea
instead of the generic CodeMirror.Editor
; that's the only type of editor used AFAIK
if (doc.getOption('mode') === 'graphql') { | ||
const text = change.text.map(normalizeIrregularWhitespace); | ||
|
||
change.update?.(change.from, change.to, text); |
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 we shouldn't invoke update
if text.length === 0
(ie. no lines)?
@@ -0,0 +1,33 @@ | |||
// List of irregular whitespace characters adopted from https://eslint.org/docs/rules/no-irregular-whitespace#rule-details |
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 fix here 🙂
From https://github.com/Kong/insomnia/pull/2704/files#r505491859 it was found that the code to prevent GraphQL non breaking spaces (that cause a syntax error) is not working
This PR fixes the behaviour
Demo