Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a19735b

Browse files
committed
feature #40052 [ErrorHandler] Add button to copy the path where error is thrown (lmillucci)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [ErrorHandler] Add button to copy the path where error is thrown | Q | A | ------------- | --- | Branch? | 5.x for features | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | | License | MIT | Doc PR | As a developer I want to copy the path where an exception is thrown on my IDE to check what is the problem. At the moment I have to select the path on the error page and copy it. I think that this process could be simplified through a "copy path" button that copies the error path on the clipboard. I was thinking about something like this: ![Screenshot_2021-02-01 MyException (500 Internal Server Error)](https://user-images.githubusercontent.com/5730780/106430292-e3240900-646b-11eb-8f56-9cc0d4ecaa9b.png) (Page style should be improved) Let me know what you think. If you think it is a good idea I could improve this PR Commits ------- 5779f86 [ErrorHandler] Add button to copy the path where error is thrown
2 parents 7e28580 + 5779f86 commit a19735b

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ if (typeof Sfjs === 'undefined' || typeof Sfjs.loadToolbar === 'undefined') {
3838
};
3939
}
4040
41+
if (navigator.clipboard) {
42+
document.querySelectorAll('[data-clipboard-text]').forEach(function(element) {
43+
removeClass(element, 'hidden');
44+
element.addEventListener('click', function() {
45+
navigator.clipboard.writeText(element.getAttribute('data-clipboard-text'));
46+
})
47+
});
48+
}
49+
4150
var request = function(url, onSuccess, onError, payload, options, tries) {
4251
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
4352
options = options || {};
@@ -705,6 +714,14 @@ if (typeof Sfjs === 'undefined' || typeof Sfjs.loadToolbar === 'undefined') {
705714
});
706715
}
707716
717+
/* Prevents from disallowing clicks on "copy to clipboard" elements inside toggles */
718+
var copyToClipboardElements = toggles[i].querySelectorAll('span[data-clipboard-text]')
719+
for (var k = 0; k < copyToClipboardElements.length; k++) {
720+
addEventListener(copyToClipboardElements[k], 'click', function(e) {
721+
e.stopPropagation();
722+
});
723+
}
724+
708725
toggles[i].setAttribute('data-processed', 'true');
709726
}
710727
},

src/Symfony/Component/ErrorHandler/Resources/assets/css/exception.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ header .container { display: flex; justify-content: space-between; }
227227
.trace-line a { color: var(--base-6); }
228228
.trace-line .icon { opacity: .4; position: absolute; left: 10px; top: 11px; }
229229
.trace-line .icon svg { fill: var(--base-5); height: 16px; width: 16px; }
230+
.trace-line .icon.icon-copy { left: auto; top: auto; padding-left: 5px; display: none }
231+
.trace-line:hover .icon.icon-copy:not(.hidden) { display: inline-block }
230232
.trace-line-header { padding-left: 36px; padding-right: 10px; }
231233

232234
.trace-file-path, .trace-file-path a { color: var(--base-6); font-size: 13px; }
Lines changed: 1 addition & 0 deletions
Loading

src/Symfony/Component/ErrorHandler/Resources/assets/js/exception.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ if (typeof Sfjs === 'undefined') {
3030
};
3131
}
3232

33+
if (navigator.clipboard) {
34+
document.querySelectorAll('[data-clipboard-text]').forEach(function(element) {
35+
removeClass(element, 'hidden');
36+
element.addEventListener('click', function() {
37+
navigator.clipboard.writeText(element.getAttribute('data-clipboard-text'));
38+
})
39+
});
40+
}
41+
3342
return {
3443
addEventListener: addEventListener,
3544

@@ -166,6 +175,14 @@ if (typeof Sfjs === 'undefined') {
166175
});
167176
}
168177

178+
/* Prevents from disallowing clicks on "copy to clipboard" elements inside toggles */
179+
var copyToClipboardElements = toggles[i].querySelectorAll('span[data-clipboard-text]')
180+
for (var k = 0; k < copyToClipboardElements.length; k++) {
181+
addEventListener(copyToClipboardElements[k], 'click', function(e) {
182+
e.stopPropagation();
183+
});
184+
}
185+
169186
toggles[i].setAttribute('data-processed', 'true');
170187
}
171188
},

src/Symfony/Component/ErrorHandler/Resources/views/trace.html.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
<span class="trace-method"><?= $trace['function']; ?></span>
2626
<?php } ?>
2727
(line <?= $lineNumber; ?>)
28+
<span class="icon icon-copy hidden" data-clipboard-text="<?php echo implode(\DIRECTORY_SEPARATOR, $filePathParts).':'.$lineNumber; ?>">
29+
<?php echo $this->include('assets/images/icon-copy.svg'); ?>
30+
</span>
2831
</span>
2932
<?php } ?>
3033
</div>

0 commit comments

Comments
 (0)