Inserting cursor in middle of Komodo Edit macro - macros

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);

Related

Prevent user from Enter-pressing on MESSAGE type I?

Is there any way to disable the enter key when a MESSAGE TYPE I is displayed? The users are just pressing away the note without reading it.
We want to force them to actually click the green button to confirm the message instead (Yes, I know it's dumb, but I was tasked to implement this so wcyd).
SELECT SINGLE text
FROM ZWM_MATVERMERK
INTO lv_verm
WHERE matnr = <lf_main>-matnr
AND werk = <lf_main>-werks.
IF lv_verm IS NOT INITIAL.
MESSAGE | Note: { lv_verm } | TYPE 'I'.
CLEAR lv_verm.
ENDIF.
You can use the function module POPUP_TO_CONFIRM to create a modal dialog which gives you more control than the standard MESSAGE TYPE 'I'.
Among others, this function module has the parameter default_button which decides which button is the one highlighted when the popup appears and thus will be considered clicked when the user just presses enter.
DATA lv_answer TYPE c.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = 'Are you sure?'
default_button = 2
IMPORTING
answer = lv_answer.
" lv_answer will be '1' for yes, '2' for no and 'A' for canceling the dialog.
If you want to make really really sure that the user read the message, then one option is to use POPUP_TO_GET_ONE_VALUE to make the user confirm that they read the message by reciting something from it.
DATA lv_answer TYPE c.
DATA lv_value TYPE pvarfield.
CALL FUNCTION 'POPUP_TO_GET_ONE_VALUE'
EXPORTING
titel = 'Safety check'
textline1 = |This operation will affect { lv_count } items.|
textline2 = |When you are aware of that, please enter "{ lv_count }" below:|
valuelength = 20
IMPORTING
answer = lv_answer
value1 = lv_value.
IF lv_answer = 'J' and lv_value = lv_count.
"...proceed...
ENDIF.
This will look like this:
By the way: There are a lot more standard function modules starting with POPUP_* which cover a wide variety of common use-cases for modal dialogs. Some of those can be really useful.

How to select symbols onWorkspaceSymbol

I am developing an extension for visual studio code using language server protocol, and I am including the support for "Go to symbol in workspace". My problem is that I don't know how to select the matches...
Actually I use this function I wrote:
function IsInside(word1, word2)
{
var ret = "";
var i1 = 0;
var lenMatch =0, maxLenMatch = 0, minLenMatch = word1.length;
for(var i2=0;i2<word2.length;i2++)
{
if(word1[i1]==word2[i2])
{
lenMatch++;
if(lenMatch>maxLenMatch) maxLenMatch = lenMatch;
ret+=word1[i1];
i1++;
if(i1==word1.length)
{
if(lenMatch<minLenMatch) minLenMatch = lenMatch;
// Trying to filter like VSCode does.
return maxLenMatch>=word1.length/2 && minLenMatch>=2? ret : undefined;
}
} else
{
ret+="Z";
if(lenMatch>0 && lenMatch<minLenMatch)
minLenMatch = lenMatch;
lenMatch=0;
}
}
return undefined;
}
That return the sortText if the word1 is inside the word2, undefined otherwise. My problem are cases like this:
My algorithm see that 'aller' is inside CallServer, but the interface does not mark it like expected.
There is a library or something that I must use for this? the code of VSCode is big and complex and I don't know where start looking for this information...
VSCode's API docs for provideWorkspaceSymbols() provide the following guidance (which I don't think your example violates):
The query-parameter should be interpreted in a relaxed way as the editor will apply its own highlighting and scoring on the results. A good rule of thumb is to match case-insensitive and to simply check that the characters of query appear in their order in a candidate symbol. Don't use prefix, substring, or similar strict matching.
These docs were added in response to this discussion, where somebody had very much the same issue as you.
Having a brief look at VSCode sources, internally it seems to use filters.matchFuzzy2() for the highlighting (see here and here). I don't think it's exposed in the API, so you would probably have to copy it if you wanted the behavior to match exactly.

Check if text binded to a control is null

I'm trying to check if I'm binding a null data on a controller. If the data is null, I need to not show the label as well as the binded data.
Below is my code right now.
var oMatNrRow1 = new sap.ui.commons.layout.MatrixLayoutRow();
control1 = new sap.ui.commons.Label({
text : Appcc.getText("MATERIAL_NO") + ":"
});
matrixCell1 = new sap.ui.commons.layout.MatrixLayoutCell();
matrixCell1.addContent(control1);
control = new sap.ui.commons.Label();
control.bindProperty("text", "matnr");
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
I have tried control.getProperty("text") but it only returns null when it should have return a number if matnr is not null.
I also tried formatter. I will have no problem with formatter if matnr is not null. But if it is null, the point is to destroy/delete contents of both matrixCell1 instances. In my code below, addition of matrixCell1 content will still push through.
...
formatter: function(matnr){
if (matnr !== ''){
return contract
} else{
matrixCell.destroyContent();
}
});
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
Not sure if you can move the ff code inside if statement
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
Any ideas are appreciated.
I would also suggest to user the visible property.
Are you aware of conditional binding of UI5? Using them you do not need the formatter at all in that case. see
Found a workaround on my issue. It was a simple if else condition. For the if statement, I just added data[j].matnr and it worked! I also noticed that this was how SAP implemented the behavior also e.g. oSearchViewData.description.

CodeMirror: xml attribute completion, add = automatically

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");
}
}
}

How Do I detect Text and Cursor position changes in Word using VSTO

I want to write a word addin that does some computations and updates some ui whenever the user types something or moves the current insertion point. From looking at the MSDN docs, I don't see any obvious way such as an TextTyped event on the document or application objects.
Does anyone know if this is possible without polling the document?
Actually there is a way to run some code when a word has been typed, you can use SmartTags, and override the Recognize method, this method will be called whenever a word is type, which means whenever the user typed some text and hit the space, tab, or enter keys.
one problem with this however is that if you change the text using "Range.Text" it will detect it as a word change and call the function so it can cause infinite loops.
Here is some code I used to achieve this:
public class AutoBrandSmartTag : SmartTag
{
Microsoft.Office.Interop.Word.Document cDoc;
Microsoft.Office.Tools.Word.Action act = new Microsoft.Office.Tools.Word.Action("Test Action");
public AutoBrandSmartTag(AutoBrandEngine.AutoBrandEngine _engine, Microsoft.Office.Interop.Word.Document _doc)
: base("AutoBrandTool.com/SmartTag#AutoBrandSmartTag", "AutoBrand SmartTag")
{
this.cDoc = _doc;
this.Actions = new Microsoft.Office.Tools.Word.Action[] { act };
}
protected override void Recognize(string text, Microsoft.Office.Interop.SmartTag.ISmartTagRecognizerSite site,
Microsoft.Office.Interop.SmartTag.ISmartTagTokenList tokenList)
{
if (tokenList.Count < 1)
return;
int start = 0;
int length = 0;
int index = tokenList.Count > 1 ? tokenList.Count - 1 : 1;
ISmartTagToken token = tokenList.get_Item(index);
start = token.Start;
length = token.Length;
}
}
As you've probably discovered, Word has events, but they're for really coarse actions like a document open or a switch to another document. I'm guessing MS did this intentionally to prevent a crappy macro from slowing down typing.
In short, there's no great way to do what you want. A Word MVP confirms that in this thread.