Skip to content

Commit

Permalink
New setting terminal.integrated.rightClickBehavior
Browse files Browse the repository at this point in the history
Supercedes terminal.integrated.rightClickCopyPaste

Fixes #42777
  • Loading branch information
Tyriar committed Feb 5, 2018
1 parent afac134 commit 9af8e5c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/typings/vscode-xterm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ declare module 'vscode-xterm' {
*/
macOptionIsMeta?: boolean;

/**
* Whether to select the word under the cursor on right click, this is
* standard behavior in a lot of macOS applications.
*/
rightClickSelectsWord?: boolean;

/**
* The number of rows in the terminal.
*/
Expand Down Expand Up @@ -469,7 +475,7 @@ declare module 'vscode-xterm' {
* Retrieves an option's value from the terminal.
* @param key The option key.
*/
getOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'macOptionIsMeta' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell'): boolean;
getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell'): boolean;
/**
* Retrieves an option's value from the terminal.
* @param key The option key.
Expand Down Expand Up @@ -514,7 +520,7 @@ declare module 'vscode-xterm' {
* @param key The option key.
* @param value The option value.
*/
setOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'macOptionIsMeta' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell', value: boolean): void;
setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'macOptionIsMeta' | 'popOnBell' | 'rightClickSelectsWord' | 'screenKeys' | 'useFlowControl' | 'visualBell', value: boolean): void;
/**
* Sets an option on the terminal.
* @param key The option key.
Expand Down
5 changes: 1 addition & 4 deletions src/vs/workbench/parts/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
'use strict';

import Event from 'vs/base/common/event';
import platform = require('vs/base/common/platform');
import { IDisposable } from 'vs/base/common/lifecycle';
import { RawContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { TPromise } from 'vs/base/common/winjs.base';
Expand All @@ -15,8 +14,6 @@ export const TERMINAL_PANEL_ID = 'workbench.panel.terminal';

export const TERMINAL_SERVICE_ID = 'terminalService';

export const TERMINAL_DEFAULT_RIGHT_CLICK_COPY_PASTE = platform.isWindows;

/** A context key that is set when the integrated terminal has focus. */
export const KEYBINDING_CONTEXT_TERMINAL_FOCUS = new RawContextKey<boolean>('terminalFocus', undefined);
/** A context key that is set when the integrated terminal does not have focus. */
Expand Down Expand Up @@ -63,7 +60,7 @@ export interface ITerminalConfiguration {
windows: string[];
};
macOptionIsMeta: boolean;
rightClickCopyPaste: boolean;
rightClickBehavior: 'default' | 'copyPaste' | 'selectWord';
cursorBlinking: boolean;
cursorStyle: string;
fontFamily: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as panel from 'vs/workbench/browser/panel';
import * as platform from 'vs/base/common/platform';
import * as terminalCommands from 'vs/workbench/parts/terminal/electron-browser/terminalCommands';
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { ITerminalService, KEYBINDING_CONTEXT_TERMINAL_FOCUS, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_INPUT_FOCUSED, KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED, TERMINAL_PANEL_ID, TERMINAL_DEFAULT_RIGHT_CLICK_COPY_PASTE, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_VISIBLE, TerminalCursorStyle } from 'vs/workbench/parts/terminal/common/terminal';
import { ITerminalService, KEYBINDING_CONTEXT_TERMINAL_FOCUS, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_INPUT_FOCUSED, KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED, TERMINAL_PANEL_ID, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_VISIBLE, TerminalCursorStyle } from 'vs/workbench/parts/terminal/common/terminal';
import { TERMINAL_DEFAULT_SHELL_UNIX_LIKE, TERMINAL_DEFAULT_SHELL_WINDOWS } from 'vs/workbench/parts/terminal/electron-browser/terminal';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
Expand Down Expand Up @@ -120,11 +120,6 @@ configurationRegistry.registerConfiguration({
'type': 'boolean',
'default': false
},
'terminal.integrated.rightClickCopyPaste': {
'description': nls.localize('terminal.integrated.rightClickCopyPaste', "When set, this will prevent the context menu from appearing when right clicking within the terminal, instead it will copy when there is a selection and paste when there is no selection."),
'type': 'boolean',
'default': TERMINAL_DEFAULT_RIGHT_CLICK_COPY_PASTE
},
'terminal.integrated.copyOnSelection': {
'description': nls.localize('terminal.integrated.copyOnSelection', "When set, text selected in the terminal will be copied to the clipboard."),
'type': 'boolean',
Expand Down Expand Up @@ -182,6 +177,12 @@ configurationRegistry.registerConfiguration({
'type': 'boolean',
'default': platform.isMacintosh
},
'terminal.integrated.rightClickBehavior': {
'type': 'string',
'enum': ['default', 'copyPaste', 'selectWord'],
default: platform.isMacintosh ? 'selectWord' : platform.isWindows ? 'copyPaste' : 'default',
description: nls.localize('terminal.integrated.rightClickBehavior', "Controls how terminal reacts to right click, possibilities are 'default', 'copyPaste', and 'selectWord'. 'default' will show the context menu, 'copyPaste' will copy when there is a selection otherwise paste, 'selectWord' will select the word under the cursor and show the context menu.")
},
'terminal.integrated.cwd': {
'description': nls.localize('terminal.integrated.cwd', "An explicit start path where the terminal will be launched, this is used as the current working directory (cwd) for the shell process. This may be particularly useful in workspace settings if the root directory is not a convenient cwd."),
'type': 'string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ export class TerminalInstance implements ITerminalInstance {
lineHeight: font.lineHeight,
bellStyle: this._configHelper.config.enableBell ? 'sound' : 'none',
screenReaderMode: accessibilitySupport === 'on',
macOptionIsMeta: this._configHelper.config.macOptionIsMeta
macOptionIsMeta: this._configHelper.config.macOptionIsMeta,
rightClickSelectsWord: this._configHelper.config.rightClickBehavior === 'selectWord'
});
if (this._shellLaunchConfig.initialText) {
this._xterm.writeln(this._shellLaunchConfig.initialText);
Expand Down Expand Up @@ -988,6 +989,7 @@ export class TerminalInstance implements ITerminalInstance {
this._setScrollback(this._configHelper.config.scrollback);
this._setEnableBell(this._configHelper.config.enableBell);
this._setMacOptionIsMeta(this._configHelper.config.macOptionIsMeta);
this._setRightClickSelectsWord(this._configHelper.config.rightClickBehavior === 'selectWord');
}

public updateAccessibilitySupport(): void {
Expand Down Expand Up @@ -1026,6 +1028,12 @@ export class TerminalInstance implements ITerminalInstance {
}
}

private _setRightClickSelectsWord(value: boolean): void {
if (this._xterm && this._xterm.getOption('rightClickSelectsWord') !== value) {
this._xterm.setOption('rightClickSelectsWord', value);
}
}

private _setEnableBell(isEnabled: boolean): void {
if (this._xterm) {
if (this._xterm.getOption('bellStyle') === 'sound') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class TerminalPanel extends Panel {
// occurs on the selection itself.
this._terminalService.getActiveInstance().focus();
} else if (event.which === 3) {
if (this._terminalService.configHelper.config.rightClickCopyPaste) {
if (this._terminalService.configHelper.config.rightClickBehavior === 'copyPaste') {
let terminal = this._terminalService.getActiveInstance();
if (terminal.hasSelection()) {
terminal.copySelection();
Expand Down

0 comments on commit 9af8e5c

Please sign in to comment.