Skip to content

Commit 0c1893f

Browse files
committed
Add hinting for the commands itself
1 parent 2d20cff commit 0c1893f

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## [v1.3.0] - 2022-12-09
4+
### Changed
5+
- Changed the way setting is loaded
6+
7+
### Added
8+
- Add i18n support for datetime commands
9+
- Add hinting for the commands themselves
10+
- Restore definitions to default if setting is blank
11+
312
## [v1.2.1] - 2022-01-15
413
### Changed
514
- Changed default definition of `/greet` command
@@ -18,6 +27,7 @@
1827

1928
Initial version with String and Datetime Commands
2029

30+
[v1.3.0]: https://github.com/hieuthi/joplin-plugin-slash-commands/compare/v1.2.1...v1.3.0
2131
[v1.2.1]: https://github.com/hieuthi/joplin-plugin-slash-commands/compare/v1.1.1...v1.2.1
2232
[v1.1.1]: https://github.com/hieuthi/joplin-plugin-slash-commands/compare/v1.0.0...v1.1.1
2333
[v1.0.0]: https://github.com/hieuthi/joplin-plugin-slash-commands/releases/tag/v1.0.0

src/command.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function Command(keyword, options, configs=null) {
1919
this.keyword_ = keyword;
2020
this.options_ = options;
2121
this.configs_ = configs;
22+
this.icon_ = '';
2223
};
2324
Command.prototype.getHints = function (token) {return null};
2425
Command.create = function(definition, prefix='/') {
@@ -37,15 +38,19 @@ Command.create = function(definition, prefix='/') {
3738
}
3839

3940
// COMMAND: String
40-
function StringCommand(keyword, options, configs=null) { Command.call(this, keyword, options, configs); };
41+
function StringCommand(keyword, options, configs=null) {
42+
Command.call(this, keyword, options, configs);
43+
this.icon_ = '𝐓';
44+
};
4145
StringCommand.prototype.getHints = function (token) {
4246
if (this.keyword_ !== token) {return [];}
4347

4448
let hints = [];
49+
let icon = this.icon_;
4550
this.options_.forEach(option => {
4651
hints.push({
4752
text: option,
48-
displayText: '𝐓\t' + option.replace(/\n/gm,"⏎") + ' ',
53+
displayText: icon + '\t' + option.replace(/\n/gm,"⏎") + ' ',
4954
hint: async (cm, data, completion) => {
5055
const from = completion.from || data.from;
5156
cm.replaceRange(option, from, cm.getCursor(), "complete");
@@ -58,6 +63,7 @@ StringCommand.prototype.getHints = function (token) {
5863
// COMMAND: Datetime
5964
function DatetimeCommand(keyword, options, configs=null) {
6065
Command.call(this, keyword, options, configs);
66+
this.icon_ = '🕒';
6167
};
6268
DatetimeCommand.prototype.getHints = function (token) {
6369
if (this.keyword_ > token.length) { return []; }
@@ -147,11 +153,12 @@ DatetimeCommand.prototype.getHints = function (token) {
147153
} else {
148154
dateFormat.i18n = I18N_;
149155
}
156+
let icon = this.icon_;
150157
this.options_.forEach(option => {
151158
let text = dateFormat(dt, option);
152159
hints.push({
153160
text: text,
154-
displayText: '🕒\t' + text + ' ',
161+
displayText: icon + '\t' + text + ' ',
155162
hint: async (cm, data, completion) => {
156163
const from = completion.from || data.from;
157164
cm.replaceRange(text, from, cm.getCursor(), "complete");
@@ -162,7 +169,10 @@ DatetimeCommand.prototype.getHints = function (token) {
162169
};
163170

164171

165-
function CalendarCommand(keyword, options, configs=null) { Command.call(this, keyword, options, configs); };
172+
function CalendarCommand(keyword, options, configs=null) {
173+
Command.call(this, keyword, options, configs);
174+
this.icon_ = '📅';
175+
};
166176
CalendarCommand.prototype.getHints = function (token) {
167177
if (this.keyword_ > token.length) { return []; }
168178
if (this.keyword_ !== token.slice(0,this.keyword_.length)) {return [];}
@@ -187,6 +197,7 @@ CalendarCommand.prototype.getHints = function (token) {
187197

188198
let hints = [];
189199
let date = new Date(year,month,1);
200+
let icon = this.icon_;
190201
this.options_.forEach(option => {
191202
let text = "";
192203
let display = "";
@@ -197,14 +208,14 @@ CalendarCommand.prototype.getHints = function (token) {
197208
text += asciiCalendar(year, month, lang);
198209
text += "\n\n";
199210
})
200-
display = `📅\t${month+1} ${year} (DEBUG - all locales)`;
211+
display = `${icon}\t${month+1} ${year} (DEBUG - all locales)`;
201212
} else if ( LOCALES_.includes(option) ){
202213
text = asciiCalendar(year, month, option);
203-
display = `📅\t${date.toLocaleString(option, { month: 'long' })} ${year} (${option})`;
214+
display = `${icon}\t${date.toLocaleString(option, { month: 'long' })} ${year} (${option})`;
204215
} else {
205216
let lang = typeof window !== 'undefined' ? window.navigator.language : undefined
206217
text = asciiCalendar(year, month, lang);
207-
display = `📅\t${date.toLocaleString(lang, { month: 'long' })} ${year} (${option}${lang})`;
218+
display = `${icon}\t${date.toLocaleString(lang, { month: 'long' })} ${year} (${option}${lang})`;
208219
}
209220
hints.push({
210221
text: text,

src/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 1,
33
"id": "com.hieuthi.joplin.slash-commands",
44
"app_min_version": "2.2",
5-
"version": "1.2.1",
5+
"version": "1.3.0",
66
"name": "Slash Commands: Datetime & More",
77
"description": "Execute several utilities by typing a command that starts with a slash.",
88
"author": "Hieu-Thi Luong",

src/slashCommands.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,24 @@ module.exports = {
2222
const cursor = cm.getCursor();
2323
const token = cm.getRange(change.from, cursor);
2424
let hints = [];
25+
let supps = [];
2526
for (let i=0; i<cm.state.slashCommands.length; i++){
26-
hints = hints.concat(cm.state.slashCommands[i].getHints(token))
27+
var command = cm.state.slashCommands[i];
28+
let keyword = command.keyword_;
29+
let icon = command.icon_;
30+
hints = hints.concat(command.getHints(token))
31+
if (token == keyword.substring(0,token.length)){
32+
supps.push({
33+
text: keyword,
34+
displayText: icon + '\t' + keyword,
35+
hint: async (cm, data, completion) => {
36+
const from = completion.from || data.from;
37+
cm.replaceRange(keyword, from, cm.getCursor(), "complete");
38+
},
39+
})
40+
}
2741
}
42+
hints = hints.concat(supps);
2843
callback({
2944
list: hints,
3045
from: change.from,
@@ -35,6 +50,7 @@ module.exports = {
3550
CodeMirror.showHint(cm, hintFunc, {
3651
completeSingle: false,
3752
closeOnUnfocus: true,
53+
completeSingle: false,
3854
async: true,
3955
closeCharacters: /[()\[\]{};>,.`'"]/
4056
});

0 commit comments

Comments
 (0)