Skip to content

Commit

Permalink
Added command to toggle line numbers inside frames.
Browse files Browse the repository at this point in the history
  • Loading branch information
sedwards2009 committed Jul 18, 2016
1 parent fcc6d46 commit ee8e4ae
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 13 deletions.
32 changes: 25 additions & 7 deletions src/codemirrorcommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ function unescapeShellChars(cm: CodeMirror.Editor): void {
export const COMMAND_UNESCAPE_SHELL_CHARS = "unescapeShellChars";
CodeMirror.commands[COMMAND_UNESCAPE_SHELL_CHARS] = unescapeShellChars;

function toggleLineNumbers(cm: CodeMirror.Editor): void {
const isSet = cm.getOption("lineNumbers");
cm.setOption("lineNumbers", ! isSet);
}
export const COMMAND_TOGGLE_LINE_NUMBERS = "toggleLineNumbers";

export function init() {
// This is needed to make sure that the TypeScript compile sees that that module is used and should be included.
}
Expand All @@ -108,22 +114,34 @@ export function isCommand(command: string): boolean {
COMMAND_ESCAPE_SHELL_CHARS,
COMMAND_UNESCAPE_SHELL_CHARS,
COMMAND_VERTICAL_MULTICURSOR,
COMMAND_TOGGLE_LINE_NUMBERS,
].indexOf(command) !== -1;
}

export function executeCommand(cm: CodeMirror.Editor, command: string): void {
if (command === COMMAND_TOGGLE_LINE_NUMBERS) {
toggleLineNumbers(cm);
} else {
cm.execCommand(command);
}
}

export interface CommandDescription {
command: string;
icon?: string;
iconLeft?: string;
iconRight?: string;
label: string;
}

export function commandDescriptions(): CommandDescription[] {
export function commandDescriptions(cm: CodeMirror.Editor): CommandDescription[] {
const descriptions: CommandDescription[] = [
{ command: COMMAND_FORWARDSLASHES_TO_BACK, icon: "", label: "Forward Slashes to Backslashes" },
{ command: COMMAND_BACKSLASHES_TO_FORWARD, icon: "", label: "Backslashes to Forward Slashes" },
{ command: COMMAND_ESCAPE_SHELL_CHARS, icon: "", label: "Escape Shell Characters" },
{ command: COMMAND_UNESCAPE_SHELL_CHARS, icon: "", label: "Unescape Shell Characters" },
{ command: COMMAND_VERTICAL_MULTICURSOR, icon: "", label: "Selection to Multiple Cursors" },
{ command: COMMAND_FORWARDSLASHES_TO_BACK, iconRight: "", label: "Forward Slashes to Backslashes" },
{ command: COMMAND_BACKSLASHES_TO_FORWARD, iconRight: "", label: "Backslashes to Forward Slashes" },
{ command: COMMAND_ESCAPE_SHELL_CHARS, iconRight: "", label: "Escape Shell Characters" },
{ command: COMMAND_UNESCAPE_SHELL_CHARS, iconRight: "", label: "Unescape Shell Characters" },
{ command: COMMAND_VERTICAL_MULTICURSOR, iconRight: "", label: "Selection to Multiple Cursors" },
{ command: COMMAND_TOGGLE_LINE_NUMBERS, iconLeft: cm.getOption("lineNumbers") ? "check-square-o" : "square-o",
iconRight: "list-ol", label: "Line Numbers" },
];
return descriptions;
}
22 changes: 22 additions & 0 deletions src/themes/default/_terminal-default-colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,25 @@ $terminal-color-252: #d0d0d0;
$terminal-color-253: #dadada;
$terminal-color-254: #e4e4e4;
$terminal-color-255: #eeeeee;

@mixin text-general {
background: $terminal-background-color;
color: $terminal-foreground-color;
}

@mixin text-gutters {
background: #000000;
border-right: 1px solid #b2b2b2;
}

@mixin text-guttermarker {
color: #599eff;
}

@mixin text-guttermarker-subtle {
color: #b2b2b2;
}

@mixin text-linenumber {
color: #b2b2b2;
}
7 changes: 7 additions & 0 deletions src/themes/default/terminal-viewer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@
background: $terminal-selection-unfocused-background-color;
}

.cm-s-text.CodeMirror { @include text-general; }

.CodeMirror-focused .CodeMirror-selected, .terminal-focused .CodeMirror-selected {
background: $terminal-selection-background-color;
}

.CodeMirror-gutters { @include text-gutters; }
.CodeMirror-guttermarker { @include text-guttermarker; }
.CodeMirror-guttermarker-subtle { @include text-guttermarker-subtle; }
.CodeMirror-linenumber { @include text-linenumber; }

/* Character styles */

SPAN.terminal-bold {
Expand Down
9 changes: 6 additions & 3 deletions src/viewers/terminalviewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,11 @@ class EtTerminalViewer extends ViewerElement implements CommandPaletteRequestTyp

if (this._mode ===ViewerElementTypes.Mode.SELECTION) {
const cmCommandList: CommandPaletteRequestTypes.CommandEntry[] =
CodeMirrorCommands.commandDescriptions().map( (desc) => {
return { id: desc.command, iconRight: desc.icon !== undefined ? desc.icon : "", label: desc.label,
CodeMirrorCommands.commandDescriptions(this._codeMirror).map( (desc) => {
return { id: desc.command,
iconLeft: desc.iconLeft,
iconRight: desc.iconRight,
label: desc.label,
target: this };
});
commandList = [...commandList, ...cmCommandList];
Expand Down Expand Up @@ -1120,7 +1123,7 @@ class EtTerminalViewer extends ViewerElement implements CommandPaletteRequestTyp

default:
if (this._mode === ViewerElementTypes.Mode.SELECTION && CodeMirrorCommands.isCommand(command)) {
this._codeMirror.execCommand(command);
CodeMirrorCommands.executeCommand(this._codeMirror, command);
return true;
} else {
return false;
Expand Down
9 changes: 6 additions & 3 deletions src/viewers/textviewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,11 @@ class EtTextViewer extends ViewerElement implements CommandPaletteRequestTypes.C

if (this._mode ===ViewerElementTypes.Mode.SELECTION) {
const cmCommandList: CommandPaletteRequestTypes.CommandEntry[] =
CodeMirrorCommands.commandDescriptions().map( (desc) => {
return { id: desc.command, iconRight: desc.icon !== undefined ? desc.icon : "", label: desc.label,
CodeMirrorCommands.commandDescriptions(this._codeMirror).map( (desc) => {
return { id: desc.command,
iconLeft:desc.iconLeft,
iconRight: desc.iconRight,
label: desc.label,
target: this };
});
commandList = [...commandList, ...cmCommandList];
Expand Down Expand Up @@ -883,7 +886,7 @@ class EtTextViewer extends ViewerElement implements CommandPaletteRequestTypes.C

default:
if (this._mode === ViewerElementTypes.Mode.SELECTION && CodeMirrorCommands.isCommand(command)) {
this._codeMirror.execCommand(command);
CodeMirrorCommands.executeCommand(this._codeMirror, command);
return true;
} else {
return false;
Expand Down

0 comments on commit ee8e4ae

Please sign in to comment.