Skip to content

Commit

Permalink
fix: selecting terminal blocks should focus the split
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelEinbinder committed Apr 30, 2024
1 parent e5e8127 commit dd41ffa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion slug/protocol/pipeTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ class PipeTransport {
sendString(messageStr) {
if (this._closed)
throw new Error('Pipe has been closed');
this._pipeWrite.write(messageStr);
this._pipeWrite.write(messageStr, err => {
if (err) {
console.error('pipe write error', err);
console.error('trying to write', messageStr);
}
});
this._pipeWrite.write('\0');
}

Expand Down
12 changes: 12 additions & 0 deletions src/TerminalBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class TerminalBlock implements LogItem {
constructor(delegate: TerminalBlockDelegate) {

this.element = document.createElement('div');
this.element.classList.add('terminal-block');
this.element.style.height = '0px';
this.element.style.overflow = 'hidden';
this._terminal = new Terminal({
Expand Down Expand Up @@ -76,6 +77,17 @@ export class TerminalBlock implements LogItem {
callback: () => navigator.clipboard.writeText(this._terminal.getSelection()),
}], event);
});
this.element.addEventListener('mousedown', event => {
// xterm default prevents the mousedown to stop browser selection
// But this stops focus from moving to the disabled terminal, which is bad
if (!event.defaultPrevented || this._terminal.enabled)
return;
this.element.setAttribute('tabindex', '-1');
this.element.focus();
});
this.element.addEventListener('focusout', () => {
this.element.removeAttribute('tabindex');
});
this._terminal.open(this.element);
this._terminal.loadAddon(this._addon);

Expand Down
4 changes: 4 additions & 0 deletions src/shell.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,7 @@ body:not(.vscode-dark) iframe.fullscreen {
.terminal.xterm .xterm-viewport {
overflow: hidden;
}

.terminal-block:focus {
outline: none;
}

0 comments on commit dd41ffa

Please sign in to comment.