mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
FEATURE: Add shortcut to insert current time in composer (#20216)
Hitting `Ctrl+Shift+.` on Windows and `Command+Shift+.` on Mac will insert the current time in the composer.
This commit is contained in:
parent
5a94b33b3f
commit
a0ea17faea
@ -276,6 +276,11 @@ export default Component.extend(TextareaTextManipulation, {
|
|||||||
this._itsatrap.bind("tab", () => this.indentSelection("right"));
|
this._itsatrap.bind("tab", () => this.indentSelection("right"));
|
||||||
this._itsatrap.bind("shift+tab", () => this.indentSelection("left"));
|
this._itsatrap.bind("shift+tab", () => this.indentSelection("left"));
|
||||||
|
|
||||||
|
const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
||||||
|
const mod = mac ? "meta" : "ctrl";
|
||||||
|
|
||||||
|
this._itsatrap.bind(`${mod}+shift+.`, () => this.send("insertCurrentTime"));
|
||||||
|
|
||||||
// disable clicking on links in the preview
|
// disable clicking on links in the preview
|
||||||
this.element
|
this.element
|
||||||
.querySelector(".d-editor-preview")
|
.querySelector(".d-editor-preview")
|
||||||
@ -763,6 +768,15 @@ export default Component.extend(TextareaTextManipulation, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
insertCurrentTime() {
|
||||||
|
const sel = this.getSelected("", { lineVal: true });
|
||||||
|
const timezone = this.currentUser.user_option.timezone;
|
||||||
|
const time = moment().format("HH:mm:ss");
|
||||||
|
const date = moment().format("YYYY-MM-DD");
|
||||||
|
|
||||||
|
this.addText(sel, `[date=${date} time=${time} timezone="${timezone}"]`);
|
||||||
|
},
|
||||||
|
|
||||||
focusIn() {
|
focusIn() {
|
||||||
this.set("isEditorFocused", true);
|
this.set("isEditorFocused", true);
|
||||||
},
|
},
|
||||||
|
@ -194,6 +194,10 @@ export default Controller.extend(ModalFunctionality, {
|
|||||||
keys1: [SHIFT, "F11"],
|
keys1: [SHIFT, "F11"],
|
||||||
keysDelimiter: PLUS,
|
keysDelimiter: PLUS,
|
||||||
}),
|
}),
|
||||||
|
insertCurrentTime: buildShortcut("composing.insert_current_time", {
|
||||||
|
keys1: [META, SHIFT, "."],
|
||||||
|
keysDelimiter: PLUS,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
bookmarks: {
|
bookmarks: {
|
||||||
|
@ -1360,3 +1360,32 @@ acceptance("Composer - default category not set", function (needs) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
// END: Default Composer Category tests
|
// END: Default Composer Category tests
|
||||||
|
|
||||||
|
acceptance("Composer - current time", function (needs) {
|
||||||
|
needs.user();
|
||||||
|
|
||||||
|
test("composer insert current time shortcut", async function (assert) {
|
||||||
|
await visit("/t/internationalization-localization/280");
|
||||||
|
|
||||||
|
await click("#topic-footer-buttons .btn.create");
|
||||||
|
assert.ok(exists(".d-editor-input"), "the composer input is visible");
|
||||||
|
await fillIn(".d-editor-input", "and the time now is: ");
|
||||||
|
|
||||||
|
const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
||||||
|
|
||||||
|
await triggerKeyEvent(".d-editor-input", "keydown", ".", {
|
||||||
|
shiftKey: true,
|
||||||
|
ctrlKey: !mac,
|
||||||
|
metaKey: mac,
|
||||||
|
});
|
||||||
|
|
||||||
|
const time = moment().format("HH:mm:ss");
|
||||||
|
const date = moment().format("YYYY-MM-DD");
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
query("#reply-control .d-editor-input").value.trim(),
|
||||||
|
`and the time now is: [date=${date} time=${time} timezone="Australia/Brisbane"]`,
|
||||||
|
"it adds the current date"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -4059,6 +4059,7 @@ en:
|
|||||||
title: "Composing"
|
title: "Composing"
|
||||||
return: "%{shortcut} Return to composer"
|
return: "%{shortcut} Return to composer"
|
||||||
fullscreen: "%{shortcut} Fullscreen composer"
|
fullscreen: "%{shortcut} Fullscreen composer"
|
||||||
|
insert_current_time: "%{shortcut} Insert current time"
|
||||||
bookmarks:
|
bookmarks:
|
||||||
title: "Bookmarking"
|
title: "Bookmarking"
|
||||||
enter: "%{shortcut} Save and close"
|
enter: "%{shortcut} Save and close"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user