Skip to content

Commit f99da26

Browse files
committed
Show full argument by click
1 parent 0c98e85 commit f99da26

File tree

4 files changed

+64
-12
lines changed

4 files changed

+64
-12
lines changed

src/Renderer/HtmlRenderer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function renderCallStack(Throwable $t): string
276276
*
277277
* @return string The string representation of the arguments array.
278278
*/
279-
public function argumentsToString(array $args): string
279+
public function argumentsToString(array $args, bool $truncate): string
280280
{
281281
$count = 0;
282282
$isAssoc = $args !== array_values($args);
@@ -287,7 +287,7 @@ public function argumentsToString(array $args): string
287287
foreach ($args as $key => $value) {
288288
$count++;
289289

290-
if ($count >= 5) {
290+
if ($truncate && $count >= 5) {
291291
if ($count > 5) {
292292
unset($args[$key]);
293293
} else {
@@ -302,15 +302,15 @@ public function argumentsToString(array $args): string
302302
$args[$key] = '<span class="keyword">' . ($value ? 'true' : 'false') . '</span>';
303303
} elseif (is_string($value)) {
304304
$fullValue = $this->htmlEncode($value);
305-
if (mb_strlen($value, 'UTF-8') > 32) {
305+
if ($truncate && mb_strlen($value, 'UTF-8') > 32) {
306306
$displayValue = $this->htmlEncode(mb_substr($value, 0, 32, 'UTF-8')) . '...';
307307
$args[$key] = "<span class=\"string\" title=\"$fullValue\">'$displayValue'</span>";
308308
} else {
309309
$args[$key] = "<span class=\"string\">'$fullValue'</span>";
310310
}
311311
} elseif (is_array($value)) {
312312
unset($args[$key]);
313-
$args[$key] = '[' . $this->argumentsToString($value) . ']';
313+
$args[$key] = '[' . $this->argumentsToString($value, $truncate) . ']';
314314
} elseif ($value === null) {
315315
$args[$key] = '<span class="keyword">null</span>';
316316
} 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}." : '&ndash;';
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
@@ -383,6 +383,10 @@ main {
383383
}
384384
}
385385

386+
.hidden {
387+
display: none;
388+
}
389+
386390
.flex-1 {
387391
flex: 1;
388392
}
@@ -453,11 +457,15 @@ main {
453457
color: var(--element-wrap-text-color);
454458
}
455459

456-
.call-stack ul li .element-wrap:hover .file-name,
460+
.call-stack ul li .element-wrap .file-name:hover,
457461
.call-stack ul li .element-code-wrap .code-wrap .lines-item:hover {
458462
color: var(--element-wrap-hover-text-color);
459463
}
460464

465+
.call-stack ul li .arguments:hover {
466+
color: var(--element-wrap-hover-text-color);
467+
}
468+
461469
.call-stack ul li .element-wrap .function-info {
462470
display: inline-block;
463471
}

templates/development.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@
161161
</script>
162162
<script>
163163
window.onload = function() {
164-
var codeBlocks = document.querySelectorAll('.solution pre code,.codeBlock'),
165-
callStackItems = document.getElementsByClassName('call-stack-item');
164+
const codeBlocks = document.querySelectorAll('.solution pre code,.codeBlock');
165+
const callStackItems = document.getElementsByClassName('call-stack-item');
166166

167167
// If there are grouped vendor package files
168168
var vendorCollapse = document.getElementsByClassName('call-stack-vendor-collapse');
@@ -221,13 +221,49 @@
221221
};
222222

223223
for (var i = 0, imax = callStackItems.length; i < imax; ++i) {
224-
refreshCallStackItemCode(callStackItems[i]);
224+
let stackItem = callStackItems[i];
225+
refreshCallStackItemCode(stackItem);
225226

226227
// toggle code block visibility
227-
callStackItems[i].getElementsByClassName('element-wrap')[0].addEventListener('click', function (event) {
228+
stackItem.querySelector('.show-arguments-toggle')?.addEventListener('click', function (e) {
229+
e.stopPropagation()
230+
console.log('click')
231+
// function-arguments-wrap
232+
233+
stackItem.getElementsByClassName('function-arguments-wrap')[0].classList.toggle('hidden')
234+
});
235+
236+
// toggle code block visibility
237+
const arguments = stackItem.querySelector('.arguments');
238+
arguments?.addEventListener('select', function (e) {
239+
e.stopPropagation()
240+
e.stopImmediatePropagation()
241+
242+
})
243+
arguments?.addEventListener('click', function (e) {
244+
e.stopPropagation()
245+
// stop click event on selecting text
246+
if (document.getSelection()?.type === 'Range') {
247+
return
248+
}
249+
250+
const fullArguments = stackItem.querySelector('.full-arguments');
251+
const shortArguments = stackItem.querySelector('.short-arguments');
252+
if (fullArguments) {
253+
fullArguments.classList.toggle('hidden')
254+
shortArguments.classList.toggle('hidden')
255+
}
256+
});
257+
258+
// toggle code block visibility
259+
stackItem.getElementsByClassName('element-wrap')[0].addEventListener('click', function (event) {
228260
if (event.target.nodeName.toLowerCase() === 'a') {
229261
return;
230262
}
263+
// stop click event on selecting text
264+
if (document.getSelection()?.type === 'Range') {
265+
return
266+
}
231267

232268
var callStackItem = this.parentNode,
233269
code = callStackItem.getElementsByClassName('code-wrap')[0];
@@ -245,6 +281,7 @@
245281
refreshCallStackItemCode(callStackItem);
246282
}
247283
});
284+
248285
}
249286

250287
// handle copy stacktrace action on clipboard button

0 commit comments

Comments
 (0)