Hi, I’ve been experimenting a bit with the javascript macros and stumbled upon a few issues.
First of all, very nice we can make these ourselves and thanks for the very extensive documentation. One of the most troubling issues I have is that there is no console to figure out the API. So I make some script, dump it into the macro, apply it to an empty file and wait for the results. And that is a slow process.
I’ve downloaded Tiny JS Debugger, but I think I’m using it wrong, cause it’s not helping either. Also I’ve tried Javascript Shell extended, but same goes there, I’m using it all wrong.
[Update]
I’ve somewhat figured out how to use the JS Shell extended. It was hard to determine the scope and to work with the ko.views …
So if I would trigger the autoComplete and request its methods I would’ve expected to find a function that I could use to catch the select event:
ko.views.manager.currentView.scimoz.autoCShow(0, ["option1","option2"].join(String.fromCharCode(ko.views.manager.currentView.scimoz.autoCSeparator)));
If I run that command from the Shell it shows the autocomplete popup, and the available methods in scimoz for the autoC are: autoCShow, autoCCancel, autoCActive, autoCPosStart, autoCComplete, autoCStops, autoCSeparator, autoCSelect, autoCCancelAtStart, autoCSetFillUps, autoCChooseSingle, autoCIgnoreCase, autoCAutoHide, autoCDropRestOfWord, autoCTypeSeparator, autoCMaxWidth, autoCMaxHeight, autoCCurrent, autoCGetCurrentText, autoCCaseInsensitiveBehaviour, autoCOrder .
But these are all actions instead of events … so I can manipulate the autocomplete but not retrieve the selected value in any way.
The following is what I currently have, and I only have 1 issue to fix until I can use it as an autocomplete for abbreviations. The issue is that the autocomplete does not complete the currentword, but it adds the full selected match at the current cursor position. On top of that, I can’t find a trigger being fired when a value is selected from the autocomplete. That would help me to complete the word myself and trigger the correct abbreviation.
if (typeof(window.extensions) == 'undefined') {
window.extensions = {};
}
if (extensions.abbreviation_autocomplete && extensions.abbreviation_autocomplete.onkeypress_handler) {
// Remove the existing trigger handler, we'll re-instate it.
var editor_pane = ko.views.manager.currentView;
editor_pane.removeEventListener('keyup', extensions.abbreviation_autocomplete.onkeypress_handler, true);
}
extensions.abbreviation_autocomplete = {};
(function(){
var log = ko.logging.getLogger("AbbreviationAutocomplete");
var scimoz = ko.views.manager.currentView.scimoz;
var sep = String.fromCharCode(scimoz.autoCSeparator);
var completions = ["function", "apex_debug","function_declaration"];
var lastWord = "";
//log.setLevel(ko.logging.LOG_DEBUG);
this.onkeypress_handler = function(e) {
try {
var autocompleteArray = [];
var currentWord = ko.interpolate.getWordUnderCursor(scimoz);
if (currentWord.length >= 3 && lastWord != currentWord) {
lastWord = currentWord;
for (var i=0; i < completions.length;i++) {
var option = completions[i];
var regex = new RegExp(currentWord + ".*");
var match = option.match(regex);
if (match && option != currentWord) {
autocompleteArray.push(option);
}
}
scimoz.autoCShow(0, autocompleteArray.join(sep));
}
log.debug("this works?");
} catch(ex) {
alert(ex);
log.exception(ex);
}
}
var editor_pane = ko.views.manager.currentView;
editor_pane.addEventListener('keyup', this.onkeypress_handler, true);
alert("applied");
}).apply(extensions.abbreviation_autocomplete);