-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extending Enter Key Behaviour #159
Comments
@alexandrudima do we have any way of doing this ? |
@itskhurram So you want If that does not work for you, you can define a command that executes on |
i am doing this like that but that is not working for me
|
export interface LanguageConfiguration {
// ...
onEnterRules?: OnEnterRule[];
// ...
}
/**
* Describes a rule to be evaluated when pressing Enter.
*/
export interface OnEnterRule {
/**
* This rule will only execute if the text before the cursor matches this regular expression.
*/
beforeText: RegExp;
/**
* This rule will only execute if the text after the cursor matches this regular expression.
*/
afterText?: RegExp;
/**
* The action to execute.
*/
action: EnterAction;
} You can find an example here: https://github.com/Microsoft/monaco-typescript/blob/master/src/mode.ts#L97 |
i am now doing this but when i press enter nothing happens monaco.languages.setLanguageConfiguration('gb', {
onEnterRules: [
{
beforeText: /^\s*[0-9]+/,
action: { appendText: 'hello world!' }
}
]
}) |
The following snippet works for me when I paste it in at https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-custom-languages for example and press Run so perhaps you have a problem elsewhere? monaco.languages.register({ id: 'mySpecialLanguage' });
monaco.editor.create(document.getElementById("container"), {
value: getCode(),
language: 'mySpecialLanguage'
});
monaco.languages.setLanguageConfiguration('mySpecialLanguage', {
onEnterRules: [
{
beforeText: /[0-9]$/,
action: {
indentAction: monaco.languages.IndentAction.None,
appendText: 'hello world!'
}
}
]
})
function getCode() {
return [
'A line that ends in numbers: 123123132',
'A line that doesn\'t end in numbers'
].join('\n');
} |
monaco.languages.setLanguageConfiguration('mySpecialLanguage', {
onEnterRules: [
{
beforeText: /[0-9]$/,
action: {
indentAction: monaco.languages.IndentAction.None,
appendText: getNewLineText();
}
}
]
}) but |
See my original answer:
Here is a self-contained example: var jsCode = [
'"use strict";',
'function Person(age) {',
' if (age) {',
' this.age = age;',
' }',
'}',
'Person.prototype.getAge = function () {',
' return this.age;',
'};'
].join('\n');
var editor = monaco.editor.create(document.getElementById("container"), {
value: jsCode,
language: "javascript"
});
editor.addCommand(monaco.KeyCode.Enter, function(accessor) {
editor.trigger('bla', 'type', { text: '\nMyGreatDynamicTextHere' });
}, '!suggestWidgetVisible && !renameInputVisible && !inSnippetMode && !quickFixWidgetVisible') |
everything working fine but when enter is pressed and find dialog in opened than instead of moving to next find result a new line is add with dynamic text. i think we are missing something here |
@naumanumer Yep, my bad, please also use So all in all: |
Hello, |
hello, editor.addCommand(monaco.KeyCode.Enter, function(accessor) { but it dose not work, help! |
Sorry to dig up an old thread - but is there a way of adding a choice to the appended text? Like with the provide completion items?
Is there a way to have this choice based on variables in the appended text here:
|
Let's track in #102 |
Hi,
Can you please let me know how can i extend the Enter Key behavior. I want to use Enter key behavior on suggestion box but i want if user press enter key other then suggestion box the cursor should moved to next line and line should be indented on the condition of current line text.
I have achieved this but as i added the Command on Enter key its behavior on the suggestion box has stopped working.
Regards,
Khurram
The text was updated successfully, but these errors were encountered: