From 0e210dc271d579ef38c5bee3011c5627eb41cf9d Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Mon, 20 May 2019 09:51:57 +0200 Subject: [PATCH] Explore: Fix selection/copy of log lines (#17121) This adds some logic to identify if the user is selecting text and if so disables parsing of log messages on hover. This should resolve the issue of selecting log lines to be copied and the selection is truncated. Fixes #17072 --- public/app/features/explore/LogRow.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/public/app/features/explore/LogRow.tsx b/public/app/features/explore/LogRow.tsx index 37229ee5b75..b3616330368 100644 --- a/public/app/features/explore/LogRow.tsx +++ b/public/app/features/explore/LogRow.tsx @@ -130,7 +130,7 @@ export class LogRow extends PureComponent { }; onMouseOverMessage = () => { - if (this.state.showContext) { + if (this.state.showContext || this.isTextSelected()) { // When showing context we don't want to the LogRow rerender as it will mess up state of context block // making the "after" context to be scrolled to the top, what is desired only on open // The log row message needs to be refactored to separate component that encapsulates parsing and parsed message state @@ -161,6 +161,20 @@ export class LogRow extends PureComponent { } }; + isTextSelected() { + if (!window.getSelection) { + return false; + } + + const selection = window.getSelection(); + + if (!selection) { + return false; + } + + return selection.anchorNode !== null && selection.isCollapsed === false; + } + toggleContext = () => { this.setState(state => { return {