From 131842233b5127d8d54c97e8b90f9a3383ec9b44 Mon Sep 17 00:00:00 2001 From: Dustin Runnells Date: Fri, 6 Sep 2024 22:06:19 -0400 Subject: [PATCH 1/3] feat(console-search): add search field with navigation and highlighting in console log This commit introduces a search functionality to the console log screen. re #81 --- lib/ui/console.jsx | 96 +++++++++++++++++++++++++++++++++++++++++++++- styles/appc.less | 12 ++++++ 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/lib/ui/console.jsx b/lib/ui/console.jsx index c2535e38..fa4fa8af 100644 --- a/lib/ui/console.jsx +++ b/lib/ui/console.jsx @@ -21,6 +21,7 @@ class ConsoleLog { constructor(opts) { this.children = []; this.autoScroll = opts.autoScroll; + this.HighlightText = ''; etch.initialize(this); } @@ -44,6 +45,59 @@ class ConsoleLog { ); } + /** + * Set highlighted text string + * + * @param {String} text Text that will be highlighted + */ + setHighlightText(text) { + this.highlightText = text; + } + + /** + * Highlight text in console from highlightText string + */ + highlightTextInLog() { + let origInnerHtml = this.refs.log.innerHTML; + let cleanInnerHtml = origInnerHtml.replace(/(.*?)<\/span>/gi, '$1'); + if (this.highlightText) { + this.refs.log.innerHTML = cleanInnerHtml.replaceAll(this.highlightText, '' + this.highlightText + ''); + } else { + this.refs.log.innerHTML = cleanInnerHtml; + } + } + + /** + * Jump to next highlighted text string + * + * @param {String} direction Direction to jump (up/down) + */ + jumpToHighlightedText(direction) { + let textElements = this.refs.log.querySelectorAll('.highlight'); + let consoleHeight = this.refs.log.offsetHeight; + let curScrollPosition = this.refs.log.scrollTop; + let nextAbovePosition = 0; + let nextBelowPosition = this.refs.log.scrollHeight; + + for (let nextElement = 0; nextElement < textElements.length; nextElement++) { + let elementOffset = textElements[nextElement].offsetTop; + let centeredOffset = elementOffset - (consoleHeight / 2); + + if (elementOffset < curScrollPosition + (consoleHeight / 2)) { + nextAbovePosition = Math.max(centeredOffset, 0); + } + if (elementOffset > curScrollPosition + (consoleHeight / 2) && centeredOffset < nextBelowPosition) { + nextBelowPosition = Math.min(centeredOffset, this.refs.log.scrollHeight - consoleHeight); + } + } + + if (direction === 'down') { + this.refs.log.scrollTop = nextBelowPosition; + } else { + this.refs.log.scrollTop = nextAbovePosition; + } + } + /** * Update component * @@ -82,6 +136,7 @@ class ConsoleLog { */ clear() { this.children = []; + this.childrenClean = []; this.update(); } } @@ -105,7 +160,8 @@ export default class Console { isHidden: true, logLevel: 'info', autoScroll: true, - showOnBuild: true + showOnBuild: true, + consoleHighlightText: '' }; opts && Object.assign(this.state, opts); @@ -161,6 +217,21 @@ export default class Console {
+
+ +
+
+ +
+
+