Merge pull request #3219 from marvinthepa/3216_onSelectionChange_on_right_click

fire onSelectionChange on right click select
This commit is contained in:
Daniel Imms
2021-01-19 10:24:55 -08:00
committed by GitHub
3 changed files with 12 additions and 6 deletions
+2 -2
View File
@@ -89,8 +89,8 @@ export function moveTextAreaUnderMouseCursor(ev: MouseEvent, textarea: HTMLTextA
export function rightClickHandler(ev: MouseEvent, textarea: HTMLTextAreaElement, screenElement: HTMLElement, selectionService: ISelectionService, shouldSelectWord: boolean): void { export function rightClickHandler(ev: MouseEvent, textarea: HTMLTextAreaElement, screenElement: HTMLElement, selectionService: ISelectionService, shouldSelectWord: boolean): void {
moveTextAreaUnderMouseCursor(ev, textarea, screenElement); moveTextAreaUnderMouseCursor(ev, textarea, screenElement);
if (shouldSelectWord && !selectionService.isClickInSelection(ev)) { if (shouldSelectWord) {
selectionService.selectWordAtCursor(ev); selectionService.rightClickSelect(ev);
} }
// Get textarea ready to copy from the context menu // Get textarea ready to copy from the context menu
+9 -2
View File
@@ -293,7 +293,7 @@ export class SelectionService extends Disposable implements ISelectionService {
* Checks if the current click was inside the current selection * Checks if the current click was inside the current selection
* @param event The mouse event * @param event The mouse event
*/ */
public isClickInSelection(event: MouseEvent): boolean { private _isClickInSelection(event: MouseEvent): boolean {
const coords = this._getMouseBufferCoords(event); const coords = this._getMouseBufferCoords(event);
const start = this._model.finalSelectionStart; const start = this._model.finalSelectionStart;
const end = this._model.finalSelectionEnd; const end = this._model.finalSelectionEnd;
@@ -316,7 +316,7 @@ export class SelectionService extends Disposable implements ISelectionService {
* Selects word at the current mouse event coordinates. * Selects word at the current mouse event coordinates.
* @param event The mouse event. * @param event The mouse event.
*/ */
public selectWordAtCursor(event: MouseEvent): void { private _selectWordAtCursor(event: MouseEvent): void {
const coords = this._getMouseBufferCoords(event); const coords = this._getMouseBufferCoords(event);
if (coords) { if (coords) {
this._selectWordAt(coords, false); this._selectWordAt(coords, false);
@@ -759,6 +759,13 @@ export class SelectionService extends Disposable implements ISelectionService {
this.refresh(); this.refresh();
} }
public rightClickSelect(ev: MouseEvent): void {
if (!this._isClickInSelection(ev)) {
this._selectWordAtCursor(ev);
this._fireIfSelectionChanged();
}
}
/** /**
* Gets positional information for the word at the coordinated specified. * Gets positional information for the word at the coordinated specified.
* @param coords The coordinates to get the word at. * @param coords The coordinates to get the word at.
+1 -2
View File
@@ -91,8 +91,7 @@ export interface ISelectionService {
selectAll(): void; selectAll(): void;
selectLines(start: number, end: number): void; selectLines(start: number, end: number): void;
clearSelection(): void; clearSelection(): void;
isClickInSelection(event: MouseEvent): boolean; rightClickSelect(event: MouseEvent): void;
selectWordAtCursor(event: MouseEvent): void;
shouldColumnSelect(event: KeyboardEvent | MouseEvent): boolean; shouldColumnSelect(event: KeyboardEvent | MouseEvent): boolean;
shouldForceSelection(event: MouseEvent): boolean; shouldForceSelection(event: MouseEvent): boolean;
refresh(isLinuxMouseSelection?: boolean): void; refresh(isLinuxMouseSelection?: boolean): void;