Closed reddys11 closed 4 years ago
Here is a sample showing how you can use context keys:
Thanks for the response.its working fine but, for the first right click context menu items appear based on the previous condition(not required items are coming in context menu). when i right click second time context menu items showing exactly what i required.
When I click for the second time context menu items getting correctly.how to resolve this,this is my code.
editor.onContextMenu(function (e) {
var editorContent=[];
editorContent = monaco.editor.getModels()[0].getValue().split("\n");
myCondition1=editor.createContextKey('myCondition1',editorContent[(editor.getPosition().lineNumber)-1].trim().length==0?false:true);
myCondition2=editor.createContextKey('myCondition2', editorContent[(editor.getPosition().lineNumber)-1].trim().length>0?false:true);
});
/* document.oncontextmenu = function() {return false;};
$(document).mousedown(function(e){
if( e.button == 2 ) {
$('#right-menu-click').trigger('Click');
var editorContent=[];
editorContent = monaco.editor.getModels()[0].getValue().split("\n");
// alert(editor.getPosition().lineNumber);
myCondition1=editor.createContextKey('myCondition1',editorContent[(editor.getPosition().lineNumber)-1].trim().length==0?false:true);
myCondition2=editor.createContextKey('myCondition2', editorContent[(editor.getPosition().lineNumber)-1].trim().length>0?false:true);
myCondition3=editor.createContextKey('myCondition3', editorContent.indexOf((editorContent[(editor.getPosition().lineNumber)-1].trim()).substring(1,editorContent[(editor.getPosition().lineNumber)-1].trim().length-1))==-1?false:true);
}
});*/
editor.addAction({
id: 'newStatement',
label: 'Add Statement',
keybindings: [
monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10,
monaco.KeyMod.chord(monaco.KeyMod.Alt | monaco.KeyCode.KEY_N)
],
precondition: 'myCondition2',
keybindingContext: null,
contextMenuGroupId: 'navigation',
contextMenuOrder: 1.5,
run: function() {
var statuscheck=statusCheckInOut();
if(statuscheck){
return;
}
$('#addService').trigger('click');
return null;
}
});
editor.addAction({
id: 'modifyStatement',
label: 'Modify Statement',
keybindings: [
monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10,
monaco.KeyMod.chord(monaco.KeyMod.Alt | monaco.KeyCode.KEY_M)
],
precondition: 'myCondition1',
keybindingContext: null,
contextMenuGroupId: 'navigation',
contextMenuOrder: 1.5,
run: function() {
var statuscheck=statusCheckInOut();
if(statuscheck){
return;
}
//var x=myApp.addServiceReplacerValues();
$('#ModifyService').trigger('click');
return null;
}
});
Unfortunately this looks like you need help with programming in general, not with specific editor APIs. Please ask such questions to Stack Overflow. Thank you!
Please ask your question on StackOverflow. We have a great community over there. They have already answered hundreds of questions and are happy to answer yours as well. See also our issue reporting guidelines.
Happy Coding!
monaco-editor version: 0.X.Y Browser: OS:
Steps or JS usage snippet reproducing the issue: