-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
CodeEditor: Ensure suggestions only apply to the instance of the editor that registered them #69995
Changes from all commits
b546486
84623b2
a06aa67
dd5f416
489840a
a60323a
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ type Props = CodeEditorProps & Themeable2; | |
class UnthemedCodeEditor extends PureComponent<Props> { | ||
completionCancel?: monacoType.IDisposable; | ||
monaco?: Monaco; | ||
modelId?: string; | ||
|
||
constructor(props: Props) { | ||
super(props); | ||
|
@@ -44,8 +45,8 @@ class UnthemedCodeEditor extends PureComponent<Props> { | |
return; | ||
} | ||
|
||
if (getSuggestions) { | ||
this.completionCancel = registerSuggestions(this.monaco, language, getSuggestions); | ||
if (getSuggestions && this.modelId) { | ||
this.completionCancel = registerSuggestions(this.monaco, language, getSuggestions, this.modelId); | ||
} | ||
} | ||
|
||
|
@@ -85,20 +86,21 @@ class UnthemedCodeEditor extends PureComponent<Props> { | |
|
||
handleBeforeMount = (monaco: Monaco) => { | ||
this.monaco = monaco; | ||
const { language, getSuggestions, onBeforeEditorMount } = this.props; | ||
|
||
if (getSuggestions) { | ||
this.completionCancel = registerSuggestions(monaco, language, getSuggestions); | ||
} | ||
const { onBeforeEditorMount } = this.props; | ||
|
||
onBeforeEditorMount?.(monaco); | ||
}; | ||
|
||
handleOnMount = (editor: MonacoEditorType, monaco: Monaco) => { | ||
const { onChange, onEditorDidMount } = this.props; | ||
const { getSuggestions, language, onChange, onEditorDidMount } = this.props; | ||
|
||
this.modelId = editor.getModel()?.id; | ||
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. This doesn't require a URI? 😮 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. nope, i think because the model is associated with this editor (as opposed to getting it from the global monaco namespace) |
||
this.getEditorValue = () => editor.getValue(); | ||
|
||
if (getSuggestions && this.modelId) { | ||
this.completionCancel = registerSuggestions(monaco, language, getSuggestions, this.modelId); | ||
} | ||
// Save when pressing Ctrl+S or Cmd+S | ||
editor.onKeyDown((e: monacoType.IKeyboardEvent) => { | ||
if (e.keyCode === monaco.KeyCode.KeyS && (e.ctrlKey || e.metaKey)) { | ||
|
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.
What is the logical difference ebtween doing this onMount instead of beforeMount?
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 guess it will happen slightly later, but by doing it
onMount
we get access to the editor instance, whereas before mount we only have access to the global monaco instance