Merge branch 'master' into fix_1879
This commit is contained in:
+3
-3
@@ -566,12 +566,12 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
|||||||
// Firefox doesn't appear to fire the contextmenu event on right click
|
// Firefox doesn't appear to fire the contextmenu event on right click
|
||||||
this.register(addDisposableDomListener(this.element, 'mousedown', (event: MouseEvent) => {
|
this.register(addDisposableDomListener(this.element, 'mousedown', (event: MouseEvent) => {
|
||||||
if (event.button === 2) {
|
if (event.button === 2) {
|
||||||
rightClickHandler(event, this.textarea, this.selectionManager, this.options.rightClickSelectsWord);
|
rightClickHandler(event, this, this.selectionManager, this.options.rightClickSelectsWord);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
this.register(addDisposableDomListener(this.element, 'contextmenu', (event: MouseEvent) => {
|
this.register(addDisposableDomListener(this.element, 'contextmenu', (event: MouseEvent) => {
|
||||||
rightClickHandler(event, this.textarea, this.selectionManager, this.options.rightClickSelectsWord);
|
rightClickHandler(event, this, this.selectionManager, this.options.rightClickSelectsWord);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -583,7 +583,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
|||||||
// that the regular click event doesn't fire for the middle mouse button.
|
// that the regular click event doesn't fire for the middle mouse button.
|
||||||
this.register(addDisposableDomListener(this.element, 'auxclick', (event: MouseEvent) => {
|
this.register(addDisposableDomListener(this.element, 'auxclick', (event: MouseEvent) => {
|
||||||
if (event.button === 1) {
|
if (event.button === 1) {
|
||||||
moveTextAreaUnderMouseCursor(event, this.textarea);
|
moveTextAreaUnderMouseCursor(event, this);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-19
@@ -85,26 +85,32 @@ export function pasteHandler(ev: ClipboardEvent, term: ITerminal): void {
|
|||||||
* @param ev The original right click event to be handled.
|
* @param ev The original right click event to be handled.
|
||||||
* @param textarea The terminal's textarea.
|
* @param textarea The terminal's textarea.
|
||||||
*/
|
*/
|
||||||
export function moveTextAreaUnderMouseCursor(ev: MouseEvent, textarea: HTMLTextAreaElement): void {
|
export function moveTextAreaUnderMouseCursor(ev: MouseEvent, term: ITerminal): void {
|
||||||
// Bring textarea at the cursor position
|
|
||||||
textarea.style.position = 'fixed';
|
|
||||||
textarea.style.width = '20px';
|
|
||||||
textarea.style.height = '20px';
|
|
||||||
textarea.style.left = (ev.clientX - 10) + 'px';
|
|
||||||
textarea.style.top = (ev.clientY - 10) + 'px';
|
|
||||||
textarea.style.zIndex = '1000';
|
|
||||||
|
|
||||||
textarea.focus();
|
// Calculate textarea position relative to the screen element
|
||||||
|
const pos = term.screenElement.getBoundingClientRect();
|
||||||
|
const left = ev.clientX - pos.left - 10;
|
||||||
|
const top = ev.clientY - pos.top - 10;
|
||||||
|
|
||||||
|
// Bring textarea at the cursor position
|
||||||
|
term.textarea.style.position = 'absolute';
|
||||||
|
term.textarea.style.width = '20px';
|
||||||
|
term.textarea.style.height = '20px';
|
||||||
|
term.textarea.style.left = `${left}px`;
|
||||||
|
term.textarea.style.top = `${top}px`;
|
||||||
|
term.textarea.style.zIndex = '1000';
|
||||||
|
|
||||||
|
term.textarea.focus();
|
||||||
|
|
||||||
// Reset the terminal textarea's styling
|
// Reset the terminal textarea's styling
|
||||||
// Timeout needs to be long enough for click event to be handled.
|
// Timeout needs to be long enough for click event to be handled.
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
textarea.style.position = null;
|
term.textarea.style.position = null;
|
||||||
textarea.style.width = null;
|
term.textarea.style.width = null;
|
||||||
textarea.style.height = null;
|
term.textarea.style.height = null;
|
||||||
textarea.style.left = null;
|
term.textarea.style.left = null;
|
||||||
textarea.style.top = null;
|
term.textarea.style.top = null;
|
||||||
textarea.style.zIndex = null;
|
term.textarea.style.zIndex = null;
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,14 +121,14 @@ export function moveTextAreaUnderMouseCursor(ev: MouseEvent, textarea: HTMLTextA
|
|||||||
* @param selectionManager The terminal's selection manager.
|
* @param selectionManager The terminal's selection manager.
|
||||||
* @param shouldSelectWord If true and there is no selection the current word will be selected
|
* @param shouldSelectWord If true and there is no selection the current word will be selected
|
||||||
*/
|
*/
|
||||||
export function rightClickHandler(ev: MouseEvent, textarea: HTMLTextAreaElement, selectionManager: ISelectionManager, shouldSelectWord: boolean): void {
|
export function rightClickHandler(ev: MouseEvent, term: ITerminal, selectionManager: ISelectionManager, shouldSelectWord: boolean): void {
|
||||||
moveTextAreaUnderMouseCursor(ev, textarea);
|
moveTextAreaUnderMouseCursor(ev, term);
|
||||||
|
|
||||||
if (shouldSelectWord && !selectionManager.isClickInSelection(ev)) {
|
if (shouldSelectWord && !selectionManager.isClickInSelection(ev)) {
|
||||||
selectionManager.selectWordAtCursor(ev);
|
selectionManager.selectWordAtCursor(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get textarea ready to copy from the context menu
|
// Get textarea ready to copy from the context menu
|
||||||
textarea.value = selectionManager.selectionText;
|
term.textarea.value = selectionManager.selectionText;
|
||||||
textarea.select();
|
term.textarea.select();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user