Skip to content

Commit

Permalink
Add terminal scroll commands.
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>
  • Loading branch information
AndrienkoAleksandr committed Feb 26, 2020
1 parent 02d6964 commit 46ad80f
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Breaking changes:

- [core] fixed typo (highligh -> highlight) in caption highlight fragment [#7050](https://github.com/eclipse-theia/theia/pull/7050)
- [terminal] added new abstract methods to the TerminalWidget[#7179]: `scrollLineUp`, `scrollLineDown`, `scrollToTop`, `scrollPageUp`, `scrollPageDown`

## v0.15.0

Expand Down
10 changes: 10 additions & 0 deletions packages/terminal/src/browser/base/terminal-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ export abstract class TerminalWidget extends BaseWidget {

abstract onDidOpen: Event<void>;

abstract scrollLineUp(): void;

abstract scrollLineDown(): void;

abstract scrollToTop(): void;

abstract scrollPageUp(): void;

abstract scrollPageDown(): void;

/**
* Event which fires when terminal did closed. Event value contains closed terminal widget definition.
*/
Expand Down
89 changes: 88 additions & 1 deletion packages/terminal/src/browser/terminal-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@ export namespace TerminalCommands {
category: TERMINAL_CATEGORY,
label: 'Hide find widget'
};

export const SCROLL_LINE_UP: Command = {
id: 'terminal:scroll:line:up',
category: TERMINAL_CATEGORY,
label: 'Scroll line up'
};
export const SCROLL_LINE_DOWN: Command = {
id: 'terminal:scroll:line:down',
category: TERMINAL_CATEGORY,
label: 'Scroll line down'
};
export const SCROLL_TO_TOP: Command = {
id: 'terminal:scroll:top',
category: TERMINAL_CATEGORY,
label: 'Scroll to top'
};
export const SCROLL_PAGE_UP: Command = {
id: 'terminal:scroll:page:up',
category: TERMINAL_CATEGORY,
label: 'Scroll page up'
};
export const SCROLL_PAGE_DOWN: Command = {
id: 'terminal:scroll:page:down',
category: TERMINAL_CATEGORY,
label: 'Scroll page down'
};

/**
* Command that displays all terminals that are currently opened
*/
Expand Down Expand Up @@ -244,6 +271,42 @@ export class TerminalFrontendContribution implements TerminalService, CommandCon
terminalSearchBox.hide();
}
});

commands.registerCommand(TerminalCommands.SCROLL_LINE_UP, {
isEnabled: () => this.shell.activeWidget instanceof TerminalWidget,
isVisible: () => false,
execute: () => {
(this.shell.activeWidget as TerminalWidget).scrollLineUp();
}
});
commands.registerCommand(TerminalCommands.SCROLL_LINE_DOWN, {
isEnabled: () => this.shell.activeWidget instanceof TerminalWidget,
isVisible: () => false,
execute: () => {
(this.shell.activeWidget as TerminalWidget).scrollLineDown();
}
});
commands.registerCommand(TerminalCommands.SCROLL_TO_TOP, {
isEnabled: () => this.shell.activeWidget instanceof TerminalWidget,
isVisible: () => false,
execute: () => {
(this.shell.activeWidget as TerminalWidget).scrollToTop();
}
});
commands.registerCommand(TerminalCommands.SCROLL_PAGE_UP, {
isEnabled: () => this.shell.activeWidget instanceof TerminalWidget,
isVisible: () => false,
execute: () => {
(this.shell.activeWidget as TerminalWidget).scrollPageUp();
}
});
commands.registerCommand(TerminalCommands.SCROLL_PAGE_DOWN, {
isEnabled: () => this.shell.activeWidget instanceof TerminalWidget,
isVisible: () => false,
execute: () => {
(this.shell.activeWidget as TerminalWidget).scrollPageDown();
}
});
}

registerMenus(menus: MenuModelRegistry): void {
Expand Down Expand Up @@ -291,12 +354,36 @@ export class TerminalFrontendContribution implements TerminalService, CommandCon
keybinding: 'ctrlcmd+f',
context: TerminalKeybindingContexts.terminalActive
});

keybindings.registerKeybinding({
command: TerminalCommands.TERMINAL_FIND_TEXT_CANCEL.id,
keybinding: 'esc',
context: TerminalKeybindingContexts.terminalHideSearch
});
keybindings.registerKeybinding({
command: TerminalCommands.SCROLL_LINE_UP.id,
keybinding: 'ctrl+shift+up',
context: TerminalKeybindingContexts.terminalActive
});
keybindings.registerKeybinding({
command: TerminalCommands.SCROLL_LINE_DOWN.id,
keybinding: 'ctrl+shift+down',
context: TerminalKeybindingContexts.terminalActive
});
keybindings.registerKeybinding({
command: TerminalCommands.SCROLL_TO_TOP.id,
keybinding: 'home',
context: TerminalKeybindingContexts.terminalActive
});
keybindings.registerKeybinding({
command: TerminalCommands.SCROLL_PAGE_UP.id,
keybinding: 'pageUp',
context: TerminalKeybindingContexts.terminalActive
});
keybindings.registerKeybinding({
command: TerminalCommands.SCROLL_PAGE_DOWN.id,
keybinding: 'pageDown',
context: TerminalKeybindingContexts.terminalActive
});

/* Register passthrough keybindings for combinations recognized by
xterm.js and converted to control characters.
Expand Down
20 changes: 20 additions & 0 deletions packages/terminal/src/browser/terminal-widget-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,26 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
}
}

scrollLineUp(): void {
this.term.scrollLines(-1);
}

scrollLineDown(): void {
this.term.scrollLines(1);
}

scrollToTop(): void {
this.term.scrollToTop();
}

scrollPageUp(): void {
this.term.scrollPages(-1);
}

scrollPageDown(): void {
this.term.scrollPages(1);
}

get onTerminalDidClose(): Event<TerminalWidget> {
return this.onTermDidClose.event;
}
Expand Down

0 comments on commit 46ad80f

Please sign in to comment.