Skip to content

Commit 34ebe55

Browse files
author
David Kutugata
authored
remove the '$0' from the parenthesis when intellisense adds it. (#8731)
* remove the '$0' from the parenthesis when intellisense adds it. Cursor position still appears at the end instead of inside the parenthesis. * change the cursor position to be inside parenthesis * fixed how the string and cursor is manipulated
1 parent 8d760ee commit 34ebe55

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

news/2 Fixes/8101.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prevented '$0' from appearing inside brackets when using intellisense autocomplete.

src/datascience-ui/interactive-common/editor.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,25 @@ export class Editor extends React.Component<IEditorProps, IEditorState> {
188188
private modelChanged = (e: monacoEditor.editor.IModelContentChangedEvent) => {
189189
if (this.state.model) {
190190
this.props.onChange(e.changes, this.state.model);
191+
const value = this.state.model.getValue();
192+
const secondHalf = value.substr(e.changes[0].rangeOffset);
193+
194+
// The second condition makes sure this block is only entered once after
195+
// adding the intellisense suggestion.
196+
if (secondHalf.includes('($0)') && e.changes[0].rangeOffset > 0) {
197+
// We leave the first half of value intact and only replace the first occurance
198+
// of '($0)' on the second half
199+
this.state.model.setValue(value.substr(0, e.changes[0].rangeOffset) + secondHalf.replace('($0)', '()'));
200+
201+
// The monaco editor is leaving the cursor at the end of the intellisense,
202+
// so we move it one position to the left to leave it inside the parenthesis
203+
setTimeout(() => {
204+
if (this.state.editor) {
205+
const pos = this.state.editor.getPosition();
206+
this.state.editor.setPosition(pos!.delta(0, -1));
207+
}
208+
}, 0);
209+
}
191210
}
192211
}
193212

0 commit comments

Comments
 (0)