CodeMirror: xml attribute completion, add = automatically - codemirror

Is it possible in CodeMirror to automatically add the = sign when autocompleting an attribute? Specifically on ctrl-space (like in the xml completion demo) when you almost finished typing the attribute's name and want to complete it using ctrl space...
Thanks,
Jaap

Try this
http://jsfiddle.net/aljordan82/h5f67/
extraKeys: {
"Ctrl-Space": function(){
var cursor = editor.getCursor();
var token = editor.getTokenTypeAt(cursor);
//console.log(token)
if (token == "attribute"){
editor.replaceSelection("=" , "end");
}
}
}

Related

Neovim - How to filter out text snippets from nvim-lspconfig + nvim-cmp

I'm using NeoVim with autocomplete using nvim-lspconfig and nvim-cmp. I would like to know if there's a way of filtering out text feeds from the autocompletion menu, so that they don't appear in the contextual menu:
In your setup you can exclude any kind if suggestions thanks to this merged PR.
What is happening is the function "entry_filter" is getting called whenever a suggestion for nvim_lsp is being made. in it we return false if the entry is of the kind "text".
local cmp = require "cmp"
cmp.setup {
...
sources = cmp.config.sources({
-- Dont suggest Text from nvm_lsp
{ name = "nvim_lsp",
entry_filter = function(entry, ctx)
return require("cmp").lsp.CompletionItemKind.Text ~= entry:get_kind()
end },
})
}
Check out nvim-cmp sources list and remove whatever source you don't want to use. Text is quite probably coming from buffer:
cmp.setup({
...
sources = cmp.config.sources({
{ name = 'buffer' }, -- <- remove
{ name = 'nvim_lsp' },
...
})
})

How to replace text with a MS Word web add-in by preserving the formatting?

I'm working on a simple grammar correction web add-in for MS Word. Basically, I want to get the selected text, make minimal changes and update the document with the corrected text. Currently, if I use 'text' as the coercion type, I lose formatting. If there is a table or image in the selected text, they are also gone!
As I understand from the investigation I've been doing so far, openxml is the way to go. But I couldn't find any useful example on the web. How can I manipulate text by preserving the original formatting data? How can I ignore non-text paragraphs? I want to be able to do this with the Office JavaScript API:
I would do something like this:
// get data as OOXML
Office.context.document.getSelectedDataAsync(Office.CoercionType.Ooxml, function (result) {
if (result.status === "succeeded") {
var selectionAsOOXML = result.value;
var bodyContentAsOOXML = selectionAsOOXML.match(/<w:body.*?>(.*?)<\/w:body>/)[1];
// perform manipulations to the body
// it can be difficult to do to OOXML but with som regexps it should be possible
bodyContentAsOOXML = bodyContentAsOOXML.replace(/error/g, 'rorre'); // reverse the word 'error'
// insert the body back in to the OOXML
selectionAsOOXML = selectionAsOOXML.replace(/(<w:body.*?>)(.*?)<\/w:body>/, '$1' + bodyContentAsOOXML + '<\/w:body>');
// replace the selected text with the new OOXML
Office.context.document.setSelectedDataAsync(selectionAsOOXML, { coercionType: Office.CoercionType.Ooxml }, function (asyncResult) {
if (asyncResult.status === "failed") {
console.log("Action failed with error: " + asyncResult.error.message);
}
});
}
});

How to determine if something was copied or cut to the clipboard

in my #execute method I am able to get the selection out of the clipboard / LocalSelectionTransfer. But I have no idea how to react on that based on how the user has put the content to the clipboard.
I have to decide whether I duplicate or not the content.
This is what I have:
#Execute
public void execute(#Named(IServiceConstants.ACTIVE_SHELL) Shell shell, #Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
Clipboard clipboard = new Clipboard(shell.getDisplay());
TransferData[] transferDatas = clipboard.getAvailableTypes();
boolean weCanUseIt= false;
for(int i=0; i<transferDatas.length; i++) {
if(LocalSelectionTransfer.getTransfer().isSupportedType(transferDatas[i])) {
weCanUseIt = true;
break;
}
}
if (weCanUseIt) {
#SuppressWarnings("unchecked")
List<Object> objects = ((StructuredSelection)LocalSelectionTransfer.getTransfer().getSelection()).toList();
for(Object o: objects) {
System.out.println(o.getClass());
}
}
}
any Ideas???
You only get something in the clipboard using LocalSelectionTransfer if you code a part in your RCP to use this transfer type for a Copy operation. It provides a way to transfer the selection directly.
This transfer type will not be used if something is copied to the clipboard any other way (in this case it might be something like TextTransfer or FileTransfer).
So you will only be using LocalSelectionTransfer to deal with a selection from another part in which case you presumably know how to deal with the objects.
If you are trying to do Copy and Cut then you should do the Cut in the source viewer - but this will remove the selection so you can't use LocalSelectionTransfer for that. Use a transfer such as FileTransfer or TextTransfer which doesn't rely on the current selection.

How to check if the edit mode in jstree is on? Is it possible to check it?

I am using jsTree and I want to get the name/value/text of the node I just created so that I can pass it and store it in the database.
My problem is that after enabling the edit mode, I have no wayof getting the value entered by the user.
My idea is that if I can only determine if the edit mode is on or off, then I can kinda run a function that will now get the user's input. I included here the function for creating the node.
Any other way to solve this problem is much appreciated. Thanks in advance.
function demo_create(){
var ref = $('#data').jstree(true),
p_id = sel = ref.get_selected();
console.log("Parent Id: "+p_id);
if(!sel.length) { return false; }
sel = sel[0];
id = sel = ref.create_node(sel, {"type":"file"});
console.log("Newly Created Id: "+id);
if(sel) {
ref.edit(sel);
}
};
edit will fire the rename_node.jstree once the node name is changed.
You can also use the callback of edit:
ref.edit(sel, null, function (node, status) {
console.log(node.text); // the new node title
})

Inserting cursor in middle of Komodo Edit macro

I have set up a macro for Smarty in Komodo Edit which adds a {$|#dumpr} when I press my specified key binding (which, for info is Ctrl+Alt+P).
What I would like is the cursor to be automatically inserted between the $ and the | so I can type my variable name without having to manually navigate my way in there.
Any help?
Many thanks.
Use the currentPos and gotoPos methods:
komodo.assertMacroVersion(2);
if (komodo.view && komodo.view.scintilla) { komodo.view.scintilla.focus(); } // bug 67103
var currentPos = komodo.editor.currentPos;
komodo.editor.insertText(currentPos, '{$|#dumpr}');
komodo.editor.gotoPos(currentPos+2);