1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-13 21:34:51 +00:00
TiddlyWiki5/core/modules/macros/displayshortcuts.js

46 lines
975 B
JavaScript
Raw Normal View History

/*\
title: $:/core/modules/macros/displayshortcuts.js
type: application/javascript
module-type: macro
Macro to display a list of keyboard shortcuts in human readable form. Notably, it resolves named shortcuts like `((bold))` to the underlying keystrokes.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "displayshortcuts";
exports.params = [
{name: "shortcuts"},
{name: "prefix"},
{name: "separator"},
{name: "suffix"}
];
/*
Run the macro
*/
exports.run = function(shortcuts,prefix,separator,suffix) {
var shortcutArray = $tw.keyboardManager.getPrintableShortcuts($tw.keyboardManager.parseKeyDescriptors(shortcuts,{
wiki: this.wiki
}));
if(shortcutArray.length > 0) {
shortcutArray.sort(function(a,b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
})
return prefix + shortcutArray.join(separator) + suffix;
} else {
return "";
}
};
})();