Skip to content

Commit

Permalink
Merge pull request #2279 from Tyriar/selection_manager_browser
Browse files Browse the repository at this point in the history
Make SelectionManager a service and move into browser
  • Loading branch information
Tyriar authored Jun 30, 2019
2 parents 73be720 + 47b6756 commit d691327
Show file tree
Hide file tree
Showing 16 changed files with 690 additions and 644 deletions.
16 changes: 8 additions & 8 deletions src/Clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @license MIT
*/

import { ISelectionManager } from 'browser/selection/Types';
import { ISelectionService } from 'browser/services/Services';

/**
* Prepares text to be pasted into the terminal by normalizing the line endings
Expand All @@ -28,8 +28,8 @@ export function bracketTextForPaste(text: string, bracketedPasteMode: boolean):
* Binds copy functionality to the given terminal.
* @param ev The original copy event to be handled
*/
export function copyHandler(ev: ClipboardEvent, selectionManager: ISelectionManager): void {
ev.clipboardData.setData('text/plain', selectionManager.selectionText);
export function copyHandler(ev: ClipboardEvent, selectionService: ISelectionService): void {
ev.clipboardData.setData('text/plain', selectionService.selectionText);
// Prevent or the original text will be copied.
ev.preventDefault();
}
Expand Down Expand Up @@ -95,17 +95,17 @@ export function moveTextAreaUnderMouseCursor(ev: MouseEvent, textarea: HTMLTextA
* Bind to right-click event and allow right-click copy and paste.
* @param ev The original right click event to be handled.
* @param textarea The terminal's textarea.
* @param selectionManager The terminal's selection manager.
* @param selectionService The terminal's selection manager.
* @param shouldSelectWord If true and there is no selection the current word will be selected
*/
export function rightClickHandler(ev: MouseEvent, textarea: HTMLTextAreaElement, screenElement: HTMLElement, selectionManager: ISelectionManager, shouldSelectWord: boolean): void {
export function rightClickHandler(ev: MouseEvent, textarea: HTMLTextAreaElement, screenElement: HTMLElement, selectionService: ISelectionService, shouldSelectWord: boolean): void {
moveTextAreaUnderMouseCursor(ev, textarea, screenElement);

if (shouldSelectWord && !selectionManager.isClickInSelection(ev)) {
selectionManager.selectWordAtCursor(ev);
if (shouldSelectWord && !selectionService.isClickInSelection(ev)) {
selectionService.selectWordAtCursor(ev);
}

// Get textarea ready to copy from the context menu
textarea.value = selectionManager.selectionText;
textarea.value = selectionService.selectionText;
textarea.select();
}
24 changes: 16 additions & 8 deletions src/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { C0, C1 } from 'common/data/EscapeSequences';
import { CHARSETS, DEFAULT_CHARSET } from 'common/data/Charsets';
import { wcwidth } from 'common/CharWidth';
import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
import { IDisposable } from 'xterm';
import { Disposable } from 'common/Lifecycle';
import { concat } from 'common/TypedArrayUtils';
import { StringToUtf32, stringFromCodePoint, utf32ToString, Utf8ToUtf32 } from 'common/input/TextDecoder';
Expand All @@ -20,6 +19,8 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags } from 'c
import { CellData } from 'common/buffer/CellData';
import { AttributeData } from 'common/buffer/AttributeData';
import { ICoreService } from 'common/services/Services';
import { ISelectionService } from 'browser/services/Services';
import { IDisposable } from 'common/Types';

/**
* Map collect to glevel. Used in `selectCharset`.
Expand Down Expand Up @@ -112,6 +113,8 @@ export class InputHandler extends Disposable implements IInputHandler {
private _utf8Decoder: Utf8ToUtf32 = new Utf8ToUtf32();
private _workCell: CellData = new CellData();

private _selectionService: ISelectionService | undefined;

private _onCursorMove = new EventEmitter<void>();
public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
private _onLineFeed = new EventEmitter<void>();
Expand Down Expand Up @@ -297,6 +300,11 @@ export class InputHandler extends Disposable implements IInputHandler {
this._terminal = null;
}

// TODO: When InputHandler moves into common, browser dependencies need to move out
public setBrowserServices(selectionService: ISelectionService): void {
this._selectionService = selectionService;
}

public parse(data: string): void {
// Ensure the terminal is not disposed
if (!this._terminal) {
Expand Down Expand Up @@ -1299,7 +1307,7 @@ export class InputHandler extends Disposable implements IInputHandler {
} else if (collect === '?') {
switch (params[0]) {
case 1:
this._terminal.applicationCursor = true;
this._coreService.decPrivateModes.applicationCursorKeys = true;
break;
case 2:
this._terminal.setgCharset(0, DEFAULT_CHARSET);
Expand Down Expand Up @@ -1347,8 +1355,8 @@ export class InputHandler extends Disposable implements IInputHandler {
if (this._terminal.element) {
this._terminal.element.classList.add('enable-mouse-events');
}
if (this._terminal.selectionManager) {
this._terminal.selectionManager.disable();
if (this._selectionService) {
this._selectionService.disable();
}
this._terminal.log('Binding to mouse events.');
break;
Expand Down Expand Up @@ -1504,7 +1512,7 @@ export class InputHandler extends Disposable implements IInputHandler {
} else if (collect === '?') {
switch (params[0]) {
case 1:
this._terminal.applicationCursor = false;
this._coreService.decPrivateModes.applicationCursorKeys = false;
break;
case 3:
if (this._terminal.cols === 132 && this._terminal.savedCols) {
Expand Down Expand Up @@ -1539,8 +1547,8 @@ export class InputHandler extends Disposable implements IInputHandler {
if (this._terminal.element) {
this._terminal.element.classList.remove('enable-mouse-events');
}
if (this._terminal.selectionManager) {
this._terminal.selectionManager.enable();
if (this._selectionService) {
this._selectionService.enable();
}
break;
case 1004: // send focusin/focusout events
Expand Down Expand Up @@ -1852,7 +1860,7 @@ export class InputHandler extends Disposable implements IInputHandler {
if (this._terminal.viewport) {
this._terminal.viewport.syncScrollArea();
}
this._terminal.applicationCursor = false;
this._coreService.decPrivateModes.applicationCursorKeys = false;
this._terminal.buffer.scrollTop = 0;
this._terminal.buffer.scrollBottom = this._terminal.rows - 1;
this._terminal.curAttrData = DEFAULT_ATTR_DATA.clone();
Expand Down
Loading

0 comments on commit d691327

Please sign in to comment.