Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add terminal scroll commands. #7179

Merged
merged 1 commit into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A breaking change note is required (changelog) for these new abstract methods.
Anyone currently implementing TerminalWidget will be broken by the following changes.

Copy link
Member

@akosyakov akosyakov Feb 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nobody should implement TerminalWidget, we should rather get rid of boilerplate interface later: https://github.com/eclipse-theia/theia/wiki/Coding-Guidelines#classes-over-interfaces

In other words it looks fine if it is not optional.


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, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndrienkoAleksandr are we missing the keybinding for the opposite Scroll To Bottom?
It looks like it works by using End

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello. I don't know how, but it already works by End... Strange... That's why I didn't apply this command.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello. I don't know how, but it already works by End... Strange... That's why I didn't apply this command.

That's what I noticed as well, End already worked correctly, perhaps we can omit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I think we can omit it. If somebody will report issue, we can fix it easily.

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