Skip to content

Commit 3d4f49d

Browse files
committed
Fix up/down when autocomplete is open (#5776)
1 parent f7df23d commit 3d4f49d

File tree

4 files changed

+59
-24
lines changed

4 files changed

+59
-24
lines changed

news/2 Fixes/5774.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix problem with using up/down arrows in autocomplete.

package-lock.json

Lines changed: 33 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datascience-ui/history-react/code.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ interface ICodeState {
4343
export class Code extends React.Component<ICodeProps, ICodeState> {
4444
private subscriptions: monacoEditor.IDisposable[] = [];
4545
private lastCleanVersionId: number = 0;
46+
private editorRef: React.RefObject<MonacoEditor> = React.createRef<MonacoEditor>();
4647

4748
constructor(prop: ICodeProps) {
4849
super(prop);
@@ -102,6 +103,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
102103
editorMounted={this.editorDidMount}
103104
options={options}
104105
openLink={this.props.openLink}
106+
ref={this.editorRef}
105107
/>
106108
<div className={waterMarkClass}>{this.getWatermarkString()}</div>
107109
</div>
@@ -135,9 +137,11 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
135137
// Listen for model changes
136138
this.subscriptions.push(editor.onDidChangeModelContent(this.modelChanged));
137139

138-
// List for key up/down events.
139-
this.subscriptions.push(editor.onKeyDown(this.onKeyDown));
140-
this.subscriptions.push(editor.onKeyUp(this.onKeyUp));
140+
// List for key up/down events if not read only
141+
if (!this.props.readOnly) {
142+
this.subscriptions.push(editor.onKeyDown(this.onKeyDown));
143+
this.subscriptions.push(editor.onKeyUp(this.onKeyUp));
144+
}
141145

142146
// Indicate we're ready
143147
this.props.onCreated(this.props.code, model!.id);
@@ -203,8 +207,15 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
203207
return '';
204208
}
205209

210+
private isAutoCompleteOpen() : boolean {
211+
if (this.editorRef.current) {
212+
return this.editorRef.current.isSuggesting();
213+
}
214+
return false;
215+
}
216+
206217
private arrowUp(e: monacoEditor.IKeyboardEvent) {
207-
if (this.state.editor && this.state.model) {
218+
if (this.state.editor && this.state.model && !this.isAutoCompleteOpen()) {
208219
const cursor = this.state.editor.getPosition();
209220
if (cursor && cursor.lineNumber === 1 && this.props.history) {
210221
const currentValue = this.getContents();
@@ -220,7 +231,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
220231
}
221232

222233
private arrowDown(e: monacoEditor.IKeyboardEvent) {
223-
if (this.state.editor && this.state.model) {
234+
if (this.state.editor && this.state.model && !this.isAutoCompleteOpen()) {
224235
const cursor = this.state.editor.getPosition();
225236
if (cursor && cursor.lineNumber === this.state.model.getLineCount() && this.props.history) {
226237
const currentValue = this.getContents();

src/datascience-ui/react-common/monacoEditor.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
182182
);
183183
}
184184

185+
public isSuggesting() : boolean {
186+
// This should mean our widgetParent has some height
187+
if (this.widgetParent && this.widgetParent.firstChild && this.widgetParent.firstChild.childNodes.length >= 2) {
188+
const suggestWidget = this.widgetParent.firstChild.childNodes.item(1) as HTMLDivElement;
189+
return suggestWidget && suggestWidget.className.includes('visible');
190+
}
191+
return false;
192+
}
193+
185194
private windowResized = () => {
186195
if (this.resizeTimer) {
187196
clearTimeout(this.resizeTimer);

0 commit comments

Comments
 (0)