8
8
font-family : monospace;
9
9
padding : 20px ;
10
10
background-color : # f5f5f5 ;
11
- max-width : 1200 px ;
11
+ max-width : 2000 px ;
12
12
margin : 0 auto;
13
13
}
14
14
18
18
}
19
19
20
20
# input-area {
21
+ display : flex;
22
+ gap : 20px ;
21
23
margin-bottom : 20px ;
22
24
}
23
25
24
26
# input-area textarea {
25
- width : 100 % ;
27
+ flex : 1 ;
26
28
height : 150px ;
27
29
margin-bottom : 10px ;
28
30
font-family : monospace;
29
31
padding : 10px ;
30
32
}
31
33
32
34
button {
35
+ display : block;
36
+ width : 200px ;
37
+ margin : 0 auto 20px ;
33
38
padding : 8px 16px ;
34
39
background-color : # 4CAF50 ;
35
40
color : white;
36
41
border : none;
37
42
border-radius : 4px ;
38
43
cursor : pointer;
39
- margin-bottom : 20px ;
40
44
}
41
45
42
46
button : hover {
57
61
box-shadow : 0 2px 4px rgba (0 , 0 , 0 , 0.1 );
58
62
white-space : pre;
59
63
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 ;
60
83
}
61
84
62
85
.function-block {
@@ -126,8 +149,8 @@ <h1>Text Comparison Tool</h1>
126
149
< div id ="input-area ">
127
150
< textarea id ="input1 " placeholder ="Enter first trace... "> </ textarea >
128
151
< textarea id ="input2 " placeholder ="Enter second trace... "> </ textarea >
129
- < button onclick ="compareTraces() "> Compare</ button >
130
152
</ div >
153
+ < button onclick ="compareTraces() "> Compare</ button >
131
154
132
155
< div id ="result-area ">
133
156
< div id ="result1 "> </ div >
@@ -138,49 +161,51 @@ <h1>Text Comparison Tool</h1>
138
161
function processTrace ( trace , otherTrace , resultId ) {
139
162
const lines = trace . trim ( ) . split ( '\n' ) ;
140
163
const otherLines = otherTrace . trim ( ) . split ( '\n' ) ;
141
- let html = '' ;
164
+ let contentHtml = '' ;
165
+ let lineNumbersHtml = '' ;
142
166
let indentLevel = 0 ;
143
167
let blockStartLine = - 1 ;
144
168
169
+ // Generate line numbers
170
+ for ( let i = 1 ; i <= lines . length ; i ++ ) {
171
+ lineNumbersHtml += `${ i } \n` ;
172
+ }
173
+
145
174
for ( let i = 0 ; i < lines . length ; i ++ ) {
146
175
const line = lines [ i ] . trim ( ) ;
147
176
const shouldHighlight = ! otherLines . some ( otherLine => otherLine . trim ( ) === line ) ;
148
177
const highlightClass = shouldHighlight ? 'highlight' : '' ;
149
178
150
- // Check if this line is the start of a block that has content
151
179
const isBlockStart = line . endsWith ( '{' ) && i < lines . length - 1 ;
152
180
153
181
if ( isBlockStart ) {
154
182
blockStartLine = i ;
155
- // Start of a function block with content
156
183
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">
158
185
<div class="function-header ${ highlightClass } ">
159
186
<span class="toggle-btn">▼</span>
160
187
<span class="function-name">${ functionName } </span>
161
188
</div>
162
189
<div class="function-content">` ;
163
190
indentLevel ++ ;
164
191
} else if ( line . includes ( '}' ) ) {
165
- // End of a block
166
192
if ( indentLevel > 0 ) {
167
193
indentLevel -- ;
168
- html += `</div><span class="function-end ${ highlightClass } ">${ line } </span></div>` ;
194
+ contentHtml += `</div><span class="function-end ${ highlightClass } ">${ line } </span></div>` ;
169
195
} else {
170
- html += `<div class="line ${ highlightClass } ">${ line } </div>` ;
196
+ contentHtml += `<div class="line ${ highlightClass } ">${ line } </div>` ;
171
197
}
172
198
} else {
173
- // Regular line or a line ending with { at the end of input
174
199
const isLastLineBlock = line . endsWith ( '{' ) && i === lines . length - 1 ;
175
200
if ( isLastLineBlock ) {
176
- html += `<div class="line ${ highlightClass } ">${ line } </div>` ;
201
+ contentHtml += `<div class="line ${ highlightClass } ">${ line } </div>` ;
177
202
} else {
178
- html += `<div class="line ${ highlightClass } ">${ line } </div>` ;
203
+ contentHtml += `<div class="line ${ highlightClass } ">${ line } </div>` ;
179
204
}
180
205
}
181
206
}
182
207
183
- return html ;
208
+ return `<div class="line-numbers"> ${ lineNumbersHtml } </div><div class="content-area"> ${ contentHtml } </div>` ;
184
209
}
185
210
186
211
function initializeCollapsible ( containerId ) {
0 commit comments