Skip to content

Commit

Permalink
Slash command improvements v8.2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
arnoudkooi committed Oct 23, 2024
1 parent e454e27 commit 42fd05b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG.md

## 8.2.2.0 (2024-10-23)
Fixes / changes:
- Autocomplete for slash command switches, i.e. -u (Slack)
- Allow - and _ character in slash commands and switches (Slack)

## 8.2.1.4 (2024-10-21)
Fixes / changes:
- Fix Doubleclick refrence icon on catalog item variables in the formatter (LinkedIn post comment)
Expand Down
13 changes: 9 additions & 4 deletions inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,12 @@ function snuSlashCommandAddListener() {
if (originalShortcut.startsWith("-")) query = shortcut;
var extraParams = "";
var unusedSwitches = Object.assign({}, snuslashswitches);
var switches = (query + thisKey).match(/\-([a-z0-9]*)(\s|$)/g);
var switches = (query + thisKey).match(/\-([a-z0-9_-]*)(\s|$)/g);
var linkSwitch = false; //determine if this is a switch that converts the entire hyperlink
let autoCompleteSwitch = "";
if (switches) {
Object.entries(switches).forEach(([key, val]) => {
var prop = val.replace(/\s|\-/g, '');
var prop = val.replace(/\s/g, '').replace('-', '');
if (snuslashswitches.hasOwnProperty(prop) && !linkSwitch) {
var switchValue = snuslashswitches[prop].value;
var tableName = targeturl.split("_list.do")[0] || '';
Expand Down Expand Up @@ -802,12 +803,16 @@ function snuSlashCommandAddListener() {
switchText += "<div class='cmdlabel'>-" + prop + ": " + snuslashswitches[prop].description + '</div>';
delete unusedSwitches[prop];
}
else {
autoCompleteSwitch = prop;
}
});
targeturl += extraParams;
}

Object.entries(unusedSwitches).forEach(([key, val]) => {
switchText += "<div class='cmdlabel' style='color:#777777'>-" + key + ": " + val.description + '</div>';
if (key.startsWith(autoCompleteSwitch))
switchText += "<div class='cmdlabel' style='color:#777777'>-" + key + ": " + val.description + '</div>';
});

}
Expand Down Expand Up @@ -1338,7 +1343,7 @@ function snuSlashCommandShowHints(shortcut, selectFirst, snufilter, switchText,
// snuPropertyNames = [shortcut];
// }

if (snuPropertyNames.length > 0 && selectFirst && !snuPropertyNames.includes(shortcut)) { //select first hit when tap or space pressed
if (snuPropertyNames.length > 0 && selectFirst && (!snuPropertyNames.includes(shortcut) || snuIndex > 0)) { //select first hit when tap or space pressed
if (e) e.preventDefault();
shortcut = snuPropertyNames[snuIndex];
snuPropertyNames = [snuPropertyNames[snuIndex]];
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name": "SN Utils",
"description": "Productivity tools for ServiceNow. (Personal work, not affiliated to ServiceNow)",
"author": "Arnoud Kooi / arnoudkooi.com",
"version": "8.2.1.4",
"version": "8.2.2.0",
"manifest_version": 3,
"permissions": [
"activeTab",
Expand Down
2 changes: 1 addition & 1 deletion popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ function getSlashcommands() {
try {
cmds = JSON.parse($('#slashcommands').val());
} catch (e) { };
var cmdname = $('#tbxslashcmd').val().replace(/[^a-zA-Z0-9]/gi, '').toLowerCase();
var cmdname = $('#tbxslashcmd').val().replace(/[^a-zA-Z0-9_-]/gi, '').toLowerCase();
if (!cmdname){
$('#divslashmsg').text('No command name defined');
return;
Expand Down

0 comments on commit 42fd05b

Please sign in to comment.