Skip to content

Commit

Permalink
feat(cc-logs): add Home and End keystrokes
Browse files Browse the repository at this point in the history
- `Home`: move focus on first line
- `End`: move focus on last line
- `Ctrl` + `Shift` + `Home`: expands the selection from the first line
- `Ctrl` + `Shift` + `End`: expands the selection to the last line

Fixes #1009
  • Loading branch information
pdesoyres-cc committed Jun 20, 2024
1 parent b993c9c commit 42cf9fe
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/components/cc-logs/cc-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,42 @@ export class CcLogs extends LitElement {
this._logsCtrl.moveFocus(direction, this._visibleRange);
}

/**
* This function is wired through `this._inputCtrl`.
*
* It is called when `Home` key is pressed
* It asks the logs controller to move the focus on the first log.
* If `withCtrlShift` is enabled, it asks the logs controller to expand the selection to the first log.
*
* @param {boolean} withCtrlShift
*/
_onHome (withCtrlShift) {
if (withCtrlShift) {
this._logsCtrl.extendSelection(0, 'replace');
}
else {
this._logsCtrl.focus(0);
}
}

/**
* This function is wired through `this._inputCtrl`.
*
* It is called when `End` key is pressed
* It asks the logs controller to move the focus on the last log.
* If `withCtrlShift` is enabled, it asks the logs controller to expand the selection to the last log.
*
* @param {boolean} withCtrlShift
*/
_onEnd (withCtrlShift) {
if (withCtrlShift) {
this._logsCtrl.extendSelection(this._logsCtrl.listLength - 1, 'replace');
}
else {
this._logsCtrl.focus(this._logsCtrl.listLength - 1);
}
}

/**
* This event handler is called whenever the virtualizer adds child elements to the DOM, or removes child elements from the DOM.
*
Expand Down
3 changes: 3 additions & 0 deletions src/components/cc-logs/logs-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ export class LogsController {
* @param {boolean} [notifyHost = true] Whether to notify the host when the focused index has changed
*/
focus (filteredIndex, notifyHost = true) {
if (filteredIndex < 0 || filteredIndex > this._logsFiltered.length - 1) {
return;
}
if (this._focusedIndex !== filteredIndex) {
this._focusedIndex = filteredIndex;
if (notifyHost) {
Expand Down
6 changes: 6 additions & 0 deletions src/components/cc-logs/logs-input-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ export class LogsInputController {
e.preventDefault();
this._host._onSelectAll();
}
else if (e.key === 'Home') {
this._host._onHome(this._keyModifiers.ctrl && this._keyModifiers.shift);
}
else if (e.key === 'End') {
this._host._onEnd(this._keyModifiers.ctrl && this._keyModifiers.shift);
}
}

onKeyUp (e) {
Expand Down

0 comments on commit 42cf9fe

Please sign in to comment.