Is there a way to edit a built-in command in VSCode? - visual-studio-code

I like using the Toggle Block Comment command (editor.action.blockComment) with its default keybinding, but I don't like the fact that it only makes block comments that look like this
/*
I don't like this
*/
I want something more like this
/**
* Oh yeah...
**/
Is there a way to edit what the Toggle Block Comment command (editor.action.blockComment) does?

You can make your own custom extension to achieve this. Here is the code:
let selectedText = activeEditor.document.getText(activeEditor.selection);
selectedText = selectedText.replace(/^/gm, "* ");
selectedText = '/** \n' + selectedText + '\n**/';
activeEditor.edit((edittedText) => {
edittedText.replace(activeEditor.selection, selectedText);
})
I am also working on an extension where you will find exactly this. I will update the name once it hits the marketplace.

Related

how to make snippets auto complete in my custom vs code extension?

im korean beginner developer... help... T^T
i want to make auto complete like snippets in my custom vs code extension.
now my code,
const snippetBase = `axios.({
url: "${service.url}",
method: "${service.description}",
`
const editor = vscode.window.activeTextEditor
const selection: any = editor?.selection
editor?.edit(builder => {
builder.replace(
selection,
snippetBase + snippetHeaders(snippetRes.data.header) + snippetBody(snippetRes.data.body)
)
})
then, my extension auto complete image
I want to focus my cursor automatically inside the format after the snippet is shown.
Just like picture below.
snippets image
help me plz!!
It sounds from your comment that you want the edit to act as a snippet. Then you need to make a SnippetString and use the editor.insertSnippet() command which can take that SnippetString as an argument. This should work for you:
const editor = vscode.window.activeTextEditor
const selection = editor?.selection
const axiosSnippet = new vscode.SnippetString("axios.({\n")
axiosSnippet.appendText("\turl: \"")
axiosSnippet.appendPlaceholder(service.url)
axiosSnippet.appendText("\",\n")
axiosSnippet.appendText("\tmethod: \"")
axiosSnippet.appendPlaceholder(service.description)
axiosSnippet.appendText("\",\n")
editor.insertSnippet(axiosSnippet, selection)
axiosSnippet.appendPlaceholder(service.url); is the key to this, as it will select that placeholder first and then allow you to tab to the next placeholder axiosSnippet.appendPlaceholder(service.description).
[I don't know the structure of the rest of your snippet,e.g., snippetHeaders(snippetRes.data.header). If it is just text than you can use the appendText method with \n for newlines.

How can I add space between code and comment?

I'm using nerdcommenter alongside neovim, and every time I comment out a block of code with <leader>cc, the code isn't really spaced out:
fn main() {
//println!("Hello, world!");
}
I want to get an output of something like this:
fn main() {
// println!("Hello, world!");
}
Is there a command or configuration that I'm missing out on? (I haven't configured nerdcommenter at all in my vimrc)
See the plugin docs : use g:NERDSpaceDelims configuration option
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
Or for Neovim with Lua configuration :
vim.g.NERDSpaceDelims = 1

Issue when clicking enter button in CellEditorDialog using MultiLineTextCellEditor in nattable eclispe

When editing multiple cell content in nattable using MultiLineTextCellEditor the opened CellEditorDialog text area collapses when enter is clicked instead of OK button as in the below attached image.
Before Pressing Enter
After Pressing Enter
MultiLineTextCellEditor textCellEditor = new MultiLineTextCellEditor(true) {
/**
* {#inheritDoc}
*/
#Override
public boolean openInline(final IConfigRegistry configRegistry, final List<String> configLabels) {
return true;
}
/**
* {#inheritDoc}
*/
#Override
public boolean openMultiEditDialog() {
return super.openMultiEditDialog();
}
};
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, textCellEditor, DisplayMode.NORMAL,
COMMENT_CNG_LBL + "_" + COMMENT_COL_NUMBER);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE,
DisplayMode.EDIT, COMMENT_CNG_LBL + "_" + COMMENT_COL_NUMBER);
But the similar issue doesn't occur when using a TextCellEditor in nattable.
I need Multi Line inline cell editing feature so i cannot go for TextCellEditor
Please let me know if there some specific configuration that i am missed.
Do I understand correctly that for single cell you want to edit multiline text inline?
Because it looks like a bug. When the multi-value dialog is opened for a multiline value, the dialog should show a multiline input field. But in your case it only shows a single line input field. So I assume the configurations collide here.
Feel free to open a ticket via Bugzilla.

How can I prevent tinyMCE's paste event?

I need to prevent the paste event of tinyMCE if the length of the current content of editor plus the length of the words to be pasted exceed the specified limit. How can I do it? Thank you.
I was wrong. I dont need to prevent or disable paste in tinyMCE to do this. I used their paste plugin and modified the content before it is pasted.
function(pl, o) {
...
if(len > limit) {
o.content = '';
}
}
I think it's better to use the paste_preprocess function.
It's a old question, but others may stumble on this problem.
Here is the solution:
paste_preprocess: function (plugin, args) {
args.content = ''; // modify or do anything with the clipboard data
},
Do it inside, init

Ajax Auto Suggest v.2 suggestion depends on radio button?

I am using auto suggest v.2.1.3 from brandspankingnew.
I have a form with two radio button and a text field and would like to know how to make the auto suggest script pointing to a different php file if one of the radio button is checked.
I tried this but it doesnt work, its always point to the same php file even if second button is checked
Could you please assist?
Many thanks in advance.
My code is as follows:
function targetvalue()
{
for (i=0;i
/>Business Street
var options = {
script:"autosuggest.php?json=true&limit=6&",
varname:"input",
json:true,
shownoresults:false,
maxresults:10,
callback: function (obj) { document.getElementById('name').value = obj.id; }
};
var as_json = new bsn.AutoSuggest('business', options);
var options_xml = {
script: function (input) { return "autosuggest.php?input="+input+"&testid="+document.getElementById('testid').value; },
varname:"input"
};
var as_xml = new bsn.AutoSuggest('business', options_xml);
As for me, the easiest solution is to pass the the button state to the one script eg only one script but can return different results depending on button state. Otherwise you need to rewrite options each time someone clicks on the radio button. The second solution an lead to unpredictable behavior of auto suggest component.
Sample script:
var selectedValue = getRadioSelectedValue("radioGroupName");
var options_xml = { script: function (input) { return "autosuggest.php?input="+input+"&testid="+document.getElementById('testid').value+"&mode="+selectedValue; },
Write getRadioSelectedValue by yourself to get selected radio button value or set some flag on click. Mode param in GET request will indicates the state of the button, so you can return proper response.