Skip to content

Commit a960ba5

Browse files
authored
Merge pull request #114 from yiisoft/full-arguments
Show full argument by click (+bugfix)
2 parents 4ceaf19 + f9bd5d4 commit a960ba5

File tree

5 files changed

+64
-12
lines changed

5 files changed

+64
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 3.2.2 under development
44

5+
- Bug #114: Stop `click` event on text selection (@xepozz)
6+
- Enh #114: Show full argument by click (@xepozz)
57
- Enh #113: Simplify error log (@xepozz)
68
- Enh #112: Add copy cURL button, sort request headers, fix UI (@xepozz)
79

src/Renderer/HtmlRenderer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public function renderCallStack(Throwable $t, array $trace = []): string
281281
*
282282
* @return string The string representation of the arguments array.
283283
*/
284-
public function argumentsToString(array $args): string
284+
public function argumentsToString(array $args, bool $truncate = true): string
285285
{
286286
$count = 0;
287287
$isAssoc = $args !== array_values($args);
@@ -292,7 +292,7 @@ public function argumentsToString(array $args): string
292292
foreach ($args as $key => $value) {
293293
$count++;
294294

295-
if ($count >= 5) {
295+
if ($truncate && $count >= 5) {
296296
if ($count > 5) {
297297
unset($args[$key]);
298298
} else {
@@ -307,15 +307,15 @@ public function argumentsToString(array $args): string
307307
$args[$key] = '<span class="keyword">' . ($value ? 'true' : 'false') . '</span>';
308308
} elseif (is_string($value)) {
309309
$fullValue = $this->htmlEncode($value);
310-
if (mb_strlen($value, 'UTF-8') > 32) {
310+
if ($truncate && mb_strlen($value, 'UTF-8') > 32) {
311311
$displayValue = $this->htmlEncode(mb_substr($value, 0, 32, 'UTF-8')) . '...';
312312
$args[$key] = "<span class=\"string\" title=\"$fullValue\">'$displayValue'</span>";
313313
} else {
314314
$args[$key] = "<span class=\"string\">'$fullValue'</span>";
315315
}
316316
} elseif (is_array($value)) {
317317
unset($args[$key]);
318-
$args[$key] = '[' . $this->argumentsToString($value) . ']';
318+
$args[$key] = '[' . $this->argumentsToString($value, $truncate) . ']';
319319
} elseif ($value === null) {
320320
$args[$key] = '<span class="keyword">null</span>';
321321
} elseif (is_resource($value)) {

templates/_call-stack-item.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@
3333

3434
<?php if ($function !== null): ?>
3535
<span class="function-info">
36-
<?= $file === null ? "{$index}." : '&ndash;' ?>
37-
<?php $function = $class === null ? $function : "$class::$function" ?>
38-
<?= "{$this->htmlEncode($function)}({$this->argumentsToString($args)})" ?>
36+
<?php
37+
echo $file === null ? "{$index}." : '&mdash;&nbsp;';
38+
$function = $class === null ? $function : "$class::$function";
39+
40+
echo '<span class="function">' . $this->htmlEncode($function) . '</span>';
41+
echo '<span class="arguments">(';
42+
echo '<span class="short-arguments">' . $this->argumentsToString($args, true) . '</span>';
43+
echo '<span class="full-arguments hidden">' . $this->argumentsToString($args, false) . '</span>';
44+
echo ')</span>';
45+
?>
3946
</span>
4047
<?php endif ?>
4148
</div>

templates/development.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ main {
377377
}
378378
}
379379

380+
.hidden {
381+
display: none;
382+
}
383+
380384
.flex-1 {
381385
flex: 1;
382386
}
@@ -451,11 +455,15 @@ main {
451455
color: var(--element-wrap-text-color);
452456
}
453457

454-
.call-stack ul li .element-wrap:hover .file-name,
458+
.call-stack ul li .element-wrap .file-name:hover,
455459
.call-stack ul li .element-code-wrap .code-wrap .lines-item:hover {
456460
color: var(--element-wrap-hover-text-color);
457461
}
458462

463+
.call-stack ul li .arguments:hover {
464+
color: var(--element-wrap-hover-text-color);
465+
}
466+
459467
.call-stack ul li .element-wrap .function-info {
460468
display: inline-block;
461469
line-break: normal;

templates/development.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ class="copy-clipboard"
189189
</script>
190190
<script>
191191
window.onload = function() {
192-
var codeBlocks = document.querySelectorAll('.solution pre code,.codeBlock'),
193-
callStackItems = document.getElementsByClassName('call-stack-item');
192+
const codeBlocks = document.querySelectorAll('.solution pre code,.codeBlock');
193+
const callStackItems = document.getElementsByClassName('call-stack-item');
194194

195195
// If there are grouped vendor package files
196196
var vendorCollapse = document.getElementsByClassName('call-stack-vendor-collapse');
@@ -249,13 +249,47 @@ class="copy-clipboard"
249249
};
250250

251251
for (var i = 0, imax = callStackItems.length; i < imax; ++i) {
252-
refreshCallStackItemCode(callStackItems[i]);
252+
let stackItem = callStackItems[i];
253+
refreshCallStackItemCode(stackItem);
253254

254255
// toggle code block visibility
255-
callStackItems[i].getElementsByClassName('element-wrap')[0].addEventListener('click', function (event) {
256+
stackItem.querySelector('.show-arguments-toggle')?.addEventListener('click', function (e) {
257+
e.stopPropagation()
258+
259+
stackItem.getElementsByClassName('function-arguments-wrap')[0].classList.toggle('hidden')
260+
});
261+
262+
// toggle code block visibility
263+
const arguments = stackItem.querySelector('.arguments');
264+
arguments?.addEventListener('select', function (e) {
265+
e.stopPropagation()
266+
e.stopImmediatePropagation()
267+
})
268+
269+
arguments?.addEventListener('click', function (e) {
270+
e.stopPropagation()
271+
// stop click event on selecting text
272+
if (document.getSelection()?.type === 'Range') {
273+
return
274+
}
275+
276+
const fullArguments = stackItem.querySelector('.full-arguments');
277+
const shortArguments = stackItem.querySelector('.short-arguments');
278+
if (fullArguments) {
279+
fullArguments.classList.toggle('hidden')
280+
shortArguments.classList.toggle('hidden')
281+
}
282+
});
283+
284+
// toggle code block visibility
285+
stackItem.getElementsByClassName('element-wrap')[0].addEventListener('click', function (event) {
256286
if (event.target.nodeName.toLowerCase() === 'a') {
257287
return;
258288
}
289+
// stop click event on selecting text
290+
if (document.getSelection()?.type === 'Range') {
291+
return
292+
}
259293

260294
var callStackItem = this.parentNode,
261295
code = callStackItem.getElementsByClassName('code-wrap')[0];
@@ -273,6 +307,7 @@ class="copy-clipboard"
273307
refreshCallStackItemCode(callStackItem);
274308
}
275309
});
310+
276311
}
277312

278313
// handle copy stacktrace action on clipboard button

0 commit comments

Comments
 (0)