Skip to content

Commit

Permalink
Command Palette: Add shortcuts to font changes
Browse files Browse the repository at this point in the history
Following Issue #78 this patch adds commands to the command palette
that wraps the current selection in textbf, textit, or texttt.
  • Loading branch information
hrjakobsen committed Apr 5, 2021
1 parent dbc2d80 commit 46b6f50
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
33 changes: 31 additions & 2 deletions app/scripts/commandpalette/commandbackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ interface Command {

@Service()
export class CommandBackend implements CommandPaletteBackend {
private _editorCommands;
constructor() {
this._editorCommands = Container.get(EditorCommands);
}

private commands: Command[] = [
{
name: "Character Count",
func: function () {
Container.get(EditorCommands)
func: () => {
this._editorCommands
.characterCount()
.then((response) => {
NotificationService.info(
Expand All @@ -25,6 +30,30 @@ export class CommandBackend implements CommandPaletteBackend {
},
description: "Counts the number of selected characters",
},
{
name: "Bold font",
func: () => {
this._editorCommands
.wrapInCommand("textbf")
},
description: "Wrap selected text in \\textbf{}",
},
{
name: "Italic font",
func: () => {
this._editorCommands
.wrapInCommand("textit")
},
description: "Wrap selected text in \\textit{}",
},
{
name: "Typewriter font",
func: () => {
this._editorCommands
.wrapInCommand("texttt")
},
description: "Wrap selected text in \\texttt{}",
},
];
selected(item: CommandItem): void {
const command = this.commands.find((x) => x.name == item.name);
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/editorcommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class EditorCommands {
if (command == null) return;
command = command.replace(/ /g, ""); //remove all spaces
this.lastWrappingCommand = command;
this.wrapInCommand(command);
}

public wrapInCommand(command: string): void {
const injectedFunction = function (command) {
const editor = _debug_editors[0];
const selection = editor.getSelection();
Expand Down

0 comments on commit 46b6f50

Please sign in to comment.