Skip to content

Commit

Permalink
Hide scroll to source context menu if line has no source (#4263)
Browse files Browse the repository at this point in the history
Closes #4171
  • Loading branch information
RubenRBS committed Nov 12, 2022
1 parent 37ce074 commit 17000a9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions static/panes/compiler.ts
Expand Up @@ -285,6 +285,7 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
private isLabelCtxKey: monaco.editor.IContextKey<boolean>;
private revealJumpStackHasElementsCtxKey: monaco.editor.IContextKey<boolean>;
private isAsmKeywordCtxKey: monaco.editor.IContextKey<boolean>;
private lineHasLinkedSourceCtxKey: monaco.editor.IContextKey<boolean>;

private ppViewOpen: boolean;
private astViewOpen: boolean;
Expand Down Expand Up @@ -994,6 +995,7 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.isLabelCtxKey = this.editor.createContextKey('isLabel', true);
this.revealJumpStackHasElementsCtxKey = this.editor.createContextKey('hasRevealJumpStackElements', false);
this.isAsmKeywordCtxKey = this.editor.createContextKey('isAsmKeyword', true);
this.lineHasLinkedSourceCtxKey = this.editor.createContextKey('lineHasLinkedSource', false);

this.editor.addAction({
id: 'jumptolabel',
Expand Down Expand Up @@ -1027,6 +1029,10 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.isAsmKeywordCtxKey.set(this.isWordAsmKeyword(e.target.position.lineNumber, currentWord));
}
}

const lineSource = this.assembly[e.target.position.lineNumber - 1].source;

this.lineHasLinkedSourceCtxKey.set( lineSource != null && lineSource.line > 0);
}
});

Expand All @@ -1049,11 +1055,13 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
keybindingContext: undefined,
contextMenuGroupId: 'navigation',
contextMenuOrder: 1.5,
precondition: 'lineHasLinkedSource',
run: ed => {
const position = ed.getPosition();
if (position != null) {
const desiredLine = position.lineNumber - 1;
const source = this.assembly[desiredLine].source;
// The precondition ensures that this is always true, but lets not blindly belive it
if (source && source.line > 0) {
const editorId = this.getEditorIdBySourcefile(source);
if (editorId) {
Expand Down

0 comments on commit 17000a9

Please sign in to comment.