Skip to content

Commit dd4424a

Browse files
committed
仮想スクロールバー高さ調整
1 parent f1f0416 commit dd4424a

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

RemoteLogViewer.WinUI/Assets/Web/src/assets/styles/logs.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
left: 0;
2525
cursor: pointer;
2626
color: #003E92;
27+
z-index: 9999;
2728
}
2829

2930
.line-content {

RemoteLogViewer.WinUI/Assets/Web/src/components/TextFileViewer.vue

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</div>
1313
</div>
1414
<div class="scroll-area" ref="scrollArea" @scroll="onVirtualScroll" v-show="!isDisconnected">
15-
<div class="scroll-virtual-content"></div>
15+
<div class="scroll-virtual-content" ref="virtualScrollContent"></div>
1616
</div>
1717
</div>
1818
<div class="tab-area">
@@ -51,6 +51,7 @@ const maxLogLines = 1000;
5151
// テンプレート参照
5252
const logArea = ref<HTMLElement>();
5353
const scrollArea = ref<HTMLElement>();
54+
const virtualScrollContent = ref<HTMLElement>();
5455
const tabArea = ref<InstanceType<typeof TabArea>>();
5556
const row = ref<HTMLElement[]>([]);
5657
@@ -284,13 +285,42 @@ const grepLineClicked = (lineNumber: number) => {
284285
jumpLine(lineNumber);
285286
};
286287
288+
// 仮想スクロールサイズ変更
289+
const updateScrollAreaHeight = () => {
290+
if(!virtualScrollContent.value) {
291+
return;
292+
}
293+
if (row.value.length === 0) {
294+
virtualScrollContent.value.style.height = '0';
295+
return;
296+
}
297+
const averageHeight = row.value.map(x => x.clientHeight).reduce((a, b) => a + b) / row.value.length;
298+
if (isNaN(averageHeight)) {
299+
return;
300+
}
301+
virtualScrollContent.value.style.height = averageHeight * totalLines.value + 'px';
302+
}
303+
287304
// ウォッチャー
288305
watch(logs, () => {
289306
minLineNumber.value = logs.value[0]?.lineNumber ?? 0;
290307
maxLineNumber.value = logs.value[logs.value.length - 1]?.lineNumber ?? 0;
291308
setupObserverForLogScroll();
309+
nextTick(() => {
310+
updateScrollAreaHeight();
311+
});
292312
}, { deep: true });
293313
314+
watch(totalLines, () => {
315+
updateScrollAreaHeight();
316+
});
317+
318+
watch(() => props.wrapLines, () =>{
319+
nextTick(() => {
320+
updateScrollAreaHeight();
321+
});
322+
});
323+
294324
onMounted(() => {
295325
// テスト用
296326
if (!window.chrome?.webview) {
@@ -345,7 +375,7 @@ onMounted(() => {
345375
white-space: pre;
346376
border-collapse: collapse;
347377
flex: 1;
348-
overflow: scroll;
378+
overflow: auto;
349379
width: 100%;
350380
}
351381
/* 右:スクロールバー */

0 commit comments

Comments
 (0)