Skip to content

Commit 74ea558

Browse files
authored
Merge pull request #3219 from marvinthepa/3216_onSelectionChange_on_right_click
fire onSelectionChange on right click select
2 parents 8a4772c + c6f9370 commit 74ea558

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/browser/Clipboard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ export function moveTextAreaUnderMouseCursor(ev: MouseEvent, textarea: HTMLTextA
8989
export function rightClickHandler(ev: MouseEvent, textarea: HTMLTextAreaElement, screenElement: HTMLElement, selectionService: ISelectionService, shouldSelectWord: boolean): void {
9090
moveTextAreaUnderMouseCursor(ev, textarea, screenElement);
9191

92-
if (shouldSelectWord && !selectionService.isClickInSelection(ev)) {
93-
selectionService.selectWordAtCursor(ev);
92+
if (shouldSelectWord) {
93+
selectionService.rightClickSelect(ev);
9494
}
9595

9696
// Get textarea ready to copy from the context menu

src/browser/services/SelectionService.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export class SelectionService extends Disposable implements ISelectionService {
293293
* Checks if the current click was inside the current selection
294294
* @param event The mouse event
295295
*/
296-
public isClickInSelection(event: MouseEvent): boolean {
296+
private _isClickInSelection(event: MouseEvent): boolean {
297297
const coords = this._getMouseBufferCoords(event);
298298
const start = this._model.finalSelectionStart;
299299
const end = this._model.finalSelectionEnd;
@@ -316,7 +316,7 @@ export class SelectionService extends Disposable implements ISelectionService {
316316
* Selects word at the current mouse event coordinates.
317317
* @param event The mouse event.
318318
*/
319-
public selectWordAtCursor(event: MouseEvent): void {
319+
private _selectWordAtCursor(event: MouseEvent): void {
320320
const coords = this._getMouseBufferCoords(event);
321321
if (coords) {
322322
this._selectWordAt(coords, false);
@@ -759,6 +759,13 @@ export class SelectionService extends Disposable implements ISelectionService {
759759
this.refresh();
760760
}
761761

762+
public rightClickSelect(ev: MouseEvent): void {
763+
if (!this._isClickInSelection(ev)) {
764+
this._selectWordAtCursor(ev);
765+
this._fireIfSelectionChanged();
766+
}
767+
}
768+
762769
/**
763770
* Gets positional information for the word at the coordinated specified.
764771
* @param coords The coordinates to get the word at.

src/browser/services/Services.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ export interface ISelectionService {
9191
selectAll(): void;
9292
selectLines(start: number, end: number): void;
9393
clearSelection(): void;
94-
isClickInSelection(event: MouseEvent): boolean;
95-
selectWordAtCursor(event: MouseEvent): void;
94+
rightClickSelect(event: MouseEvent): void;
9695
shouldColumnSelect(event: KeyboardEvent | MouseEvent): boolean;
9796
shouldForceSelection(event: MouseEvent): boolean;
9897
refresh(isLinuxMouseSelection?: boolean): void;

0 commit comments

Comments
 (0)