From 8a829f8a60f8f01bd93556821bea6ec6337a2b7a Mon Sep 17 00:00:00 2001 From: Pierre DE SOYRES Date: Thu, 20 Jun 2024 14:11:17 +0200 Subject: [PATCH] feat(cc-logs): add `Home` and `End` keystrokes - `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 --- src/components/cc-logs/cc-logs.js | 36 +++++++++++++++++++ src/components/cc-logs/logs-controller.js | 3 ++ .../cc-logs/logs-input-controller.js | 6 ++++ 3 files changed, 45 insertions(+) diff --git a/src/components/cc-logs/cc-logs.js b/src/components/cc-logs/cc-logs.js index e3738a6c7..5ab52f200 100644 --- a/src/components/cc-logs/cc-logs.js +++ b/src/components/cc-logs/cc-logs.js @@ -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. * diff --git a/src/components/cc-logs/logs-controller.js b/src/components/cc-logs/logs-controller.js index 594683e1a..d68d39828 100644 --- a/src/components/cc-logs/logs-controller.js +++ b/src/components/cc-logs/logs-controller.js @@ -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 != null && (filteredIndex < 0 || filteredIndex > this._logsFiltered.length - 1)) { + return; + } if (this._focusedIndex !== filteredIndex) { this._focusedIndex = filteredIndex; if (notifyHost) { diff --git a/src/components/cc-logs/logs-input-controller.js b/src/components/cc-logs/logs-input-controller.js index b880b08bb..97c46de08 100644 --- a/src/components/cc-logs/logs-input-controller.js +++ b/src/components/cc-logs/logs-input-controller.js @@ -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) {