Skip to content
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

Manually execute "Format Code" action #32

Closed
MohammadYounes opened this issue Jun 26, 2016 · 7 comments
Closed

Manually execute "Format Code" action #32

MohammadYounes opened this issue Jun 26, 2016 · 7 comments

Comments

@MohammadYounes
Copy link

Is it possible to manually execute the "Format Code" action ? and How ?

Thanks!

@MohammadYounes
Copy link
Author

Found it!

editor.getAction('editor.action.format').run()

Thanks.

@risfeng
Copy link

risfeng commented Jun 10, 2017

I press your code and I'll make a mistake.
editor.getAction('editor.action.format').run()
The execution editor command should be like this:

  • format doc
    editor.trigger(‘anyString’, 'editor.action.formatDocument');
  • selected char to lower case
    editor.trigger(‘anyString’, 'editor.action.transformToLowercase');

Like this command editor.action.transformToLowercase , You can search in the file XX/editor/editor.main.js
vs code online demo :https://toolbag.online/home/index/online-vscode.html

@rart
Copy link

rart commented Dec 16, 2017

editor.getAction('editor.action.formatDocument').run() works for me.

@CoderPoet
Copy link

CoderPoet commented May 23, 2018

@MohammadYounes
why editor.getAction('editor.action.format') return null ?

@squareCY
Copy link

squareCY commented Jun 7, 2018

@CoderPoet
add this in your js:

let editor=monaco.editor.create(doc, {
            value: this.ngModel,
            language: 'sql',
            formatOnType: true//!important
        });
monaco.languages.registerDocumentFormattingEditProvider('sql', {
                provideDocumentFormattingEdits: function (model, options, token) {
                    return [
                        {
                            range: {
                                startLineNumber: 1,
                                startColumn: 1,
                                endLineNumber: 1,
                                endColumn: 1
                            },
                            text: 'a'
                        }
                    ];
                }
            });

@XHappyness
Copy link

hahaha;

editor.trigger(‘anyString’, 'editor.action.formatDocument'); works for me.

@lmxx1234567
Copy link

editor.getAction('editor.action.formatDocument').run();

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants