Skip to content

Commit 36aa6f0

Browse files
authored
improve smart_diff_utrace.html
Signed-off-by: Anton-4 <[email protected]>
1 parent 8b759f8 commit 36aa6f0

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

devtools/smart_diff_utrace.html

+40-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
font-family: monospace;
99
padding: 20px;
1010
background-color: #f5f5f5;
11-
max-width: 1200px;
11+
max-width: 2000px;
1212
margin: 0 auto;
1313
}
1414

@@ -18,25 +18,29 @@
1818
}
1919

2020
#input-area {
21+
display: flex;
22+
gap: 20px;
2123
margin-bottom: 20px;
2224
}
2325

2426
#input-area textarea {
25-
width: 100%;
27+
flex: 1;
2628
height: 150px;
2729
margin-bottom: 10px;
2830
font-family: monospace;
2931
padding: 10px;
3032
}
3133

3234
button {
35+
display: block;
36+
width: 200px;
37+
margin: 0 auto 20px;
3338
padding: 8px 16px;
3439
background-color: #4CAF50;
3540
color: white;
3641
border: none;
3742
border-radius: 4px;
3843
cursor: pointer;
39-
margin-bottom: 20px;
4044
}
4145

4246
button:hover {
@@ -57,6 +61,25 @@
5761
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
5862
white-space: pre;
5963
overflow-x: auto;
64+
position: relative;
65+
}
66+
67+
.line-numbers {
68+
position: absolute;
69+
left: 0;
70+
top: 0;
71+
bottom: 0;
72+
width: 30px;
73+
background-color: #f0f0f0;
74+
border-right: 1px solid #ddd;
75+
text-align: right;
76+
padding: 5px 5px 5px 0;
77+
color: #666;
78+
user-select: none;
79+
}
80+
81+
.content-area {
82+
margin-left: 35px;
6083
}
6184

6285
.function-block {
@@ -126,8 +149,8 @@ <h1>Text Comparison Tool</h1>
126149
<div id="input-area">
127150
<textarea id="input1" placeholder="Enter first trace..."></textarea>
128151
<textarea id="input2" placeholder="Enter second trace..."></textarea>
129-
<button onclick="compareTraces()">Compare</button>
130152
</div>
153+
<button onclick="compareTraces()">Compare</button>
131154

132155
<div id="result-area">
133156
<div id="result1"></div>
@@ -138,49 +161,51 @@ <h1>Text Comparison Tool</h1>
138161
function processTrace(trace, otherTrace, resultId) {
139162
const lines = trace.trim().split('\n');
140163
const otherLines = otherTrace.trim().split('\n');
141-
let html = '';
164+
let contentHtml = '';
165+
let lineNumbersHtml = '';
142166
let indentLevel = 0;
143167
let blockStartLine = -1;
144168

169+
// Generate line numbers
170+
for (let i = 1; i <= lines.length; i++) {
171+
lineNumbersHtml += `${i}\n`;
172+
}
173+
145174
for (let i = 0; i < lines.length; i++) {
146175
const line = lines[i].trim();
147176
const shouldHighlight = !otherLines.some(otherLine => otherLine.trim() === line);
148177
const highlightClass = shouldHighlight ? 'highlight' : '';
149178

150-
// Check if this line is the start of a block that has content
151179
const isBlockStart = line.endsWith('{') && i < lines.length - 1;
152180

153181
if (isBlockStart) {
154182
blockStartLine = i;
155-
// Start of a function block with content
156183
const functionName = line;
157-
html += `<div class="function-block" style="margin-left: ${indentLevel * 20}px">
184+
contentHtml += `<div class="function-block" style="margin-left: ${indentLevel * 20}px">
158185
<div class="function-header ${highlightClass}">
159186
<span class="toggle-btn">▼</span>
160187
<span class="function-name">${functionName}</span>
161188
</div>
162189
<div class="function-content">`;
163190
indentLevel++;
164191
} else if (line.includes('}')) {
165-
// End of a block
166192
if (indentLevel > 0) {
167193
indentLevel--;
168-
html += `</div><span class="function-end ${highlightClass}">${line}</span></div>`;
194+
contentHtml += `</div><span class="function-end ${highlightClass}">${line}</span></div>`;
169195
} else {
170-
html += `<div class="line ${highlightClass}">${line}</div>`;
196+
contentHtml += `<div class="line ${highlightClass}">${line}</div>`;
171197
}
172198
} else {
173-
// Regular line or a line ending with { at the end of input
174199
const isLastLineBlock = line.endsWith('{') && i === lines.length - 1;
175200
if (isLastLineBlock) {
176-
html += `<div class="line ${highlightClass}">${line}</div>`;
201+
contentHtml += `<div class="line ${highlightClass}">${line}</div>`;
177202
} else {
178-
html += `<div class="line ${highlightClass}">${line}</div>`;
203+
contentHtml += `<div class="line ${highlightClass}">${line}</div>`;
179204
}
180205
}
181206
}
182207

183-
return html;
208+
return `<div class="line-numbers">${lineNumbersHtml}</div><div class="content-area">${contentHtml}</div>`;
184209
}
185210

186211
function initializeCollapsible(containerId) {

0 commit comments

Comments
 (0)