Skip to content

Commit

Permalink
Merge pull request #200051 from microsoft/aiday/checkingEffectiveLine…
Browse files Browse the repository at this point in the history
…Count

Checking that the effectiveLineNumber is valid before accessing the line content
  • Loading branch information
aiday-mar authored Dec 12, 2023
2 parents b1cffad + 7c7c185 commit 7bf0f1c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/vs/editor/contrib/codeAction/browser/lightBulbWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,22 @@ export class LightBulbWidget extends Disposable implements IContentWidget {
};

let effectiveLineNumber = lineNumber;
let effectiveColumnNumber = 1;
if (!lineHasSpace) {
if (lineNumber > 1 && !isFolded(lineNumber - 1)) {
effectiveLineNumber -= 1;
} else if (!isFolded(lineNumber + 1)) {
} else if ((lineNumber < model.getLineCount()) && !isFolded(lineNumber + 1)) {
effectiveLineNumber += 1;
} else if (column * fontInfo.spaceWidth < 22) {
// cannot show lightbulb above/below and showing
// it inline would overlay the cursor...
return this.hide();
}
effectiveColumnNumber = !!model.getLineContent(effectiveLineNumber).match(/^\S\s*$/) ? 2 : 1;
}

this.state = new LightBulbState.Showing(actions, trigger, atPosition, {
position: { lineNumber: effectiveLineNumber, column: !!model.getLineContent(effectiveLineNumber).match(/^\S\s*$/) ? 2 : 1 },
position: { lineNumber: effectiveLineNumber, column: effectiveColumnNumber },
preference: LightBulbWidget._posPref
});
this._editor.layoutContentWidget(this);
Expand Down

0 comments on commit 7bf0f1c

Please sign in to comment.