Skip to content

Commit 6110d15

Browse files
committed
After pasting code, arrow keys don't navigate in a cell. (#8587)
1 parent 3676d20 commit 6110d15

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

news/2 Fixes/8495.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
After pasting code, arrow keys don't navigate in a cell.

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
319319
const cursor = this.state.editor.getPosition();
320320
if (cursor) {
321321
const top = this.state.editor.getTopForPosition(cursor.lineNumber, cursor.column);
322-
const lines = this.getVisibleLines();
323-
const lineTops = lines.length === this.lineTops.length ? this.lineTops : this.computeLineTops();
324-
for (let i = 0; i < lines.length; i += 1) {
322+
const count = this.getVisibleLineCount();
323+
const lineTops = count === this.lineTops.length ? this.lineTops : this.computeLineTops();
324+
for (let i = 0; i < count; i += 1) {
325325
if (top <= lineTops[i]) {
326326
return i;
327327
}
@@ -347,10 +347,12 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
347347

348348
private computeLineTops(): number[] {
349349
const lines = this.getVisibleLines();
350+
351+
// Lines are not sorted by monaco, so we have to sort them by their top value
350352
this.lineTops = lines.map(l => {
351353
const match = l.style.top ? /(.+)px/.exec(l.style.top) : null;
352354
return match ? parseInt(match[0], 10) : Infinity;
353-
});
355+
}).sort((a, b) => a - b);
354356
return this.lineTops;
355357
}
356358

@@ -359,7 +361,6 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
359361
const visibleLineDivs = this.getVisibleLines();
360362
const current = this.getCurrentVisibleLine();
361363
if (current !== undefined && current >= 0) {
362-
window.console.log(`Scrolling to line ${current}`);
363364
visibleLineDivs[current].scrollIntoView({ behavior: 'auto', block: 'nearest', inline: 'nearest' });
364365
}
365366
}

0 commit comments

Comments
 (0)