blob: b4fd6f03d7aef64d40e3b017aa07180ccf6e68fb [file] [log] [blame]
Philip Zeyliger3cde2822025-06-21 09:32:38 -07001<!doctype html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8" />
5 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6 <title>Monaco Comment Test</title>
7 <style>
8 body {
9 font-family:
10 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
11 Arial, sans-serif;
12 max-width: 1200px;
13 margin: 0 auto;
14 padding: 2rem;
15 }
16
17 h1 {
18 color: #333;
19 margin-bottom: 2rem;
20 }
21
22 .test-container {
23 border: 2px solid #ddd;
24 border-radius: 4px;
25 padding: 20px;
26 margin: 20px 0;
27 height: 400px;
28 }
29
30 .event-log {
31 background: #f5f5f5;
32 border: 1px solid #ccc;
33 border-radius: 4px;
34 padding: 10px;
35 margin: 20px 0;
36 max-height: 200px;
37 overflow-y: auto;
38 font-family: monospace;
39 font-size: 12px;
40 }
41
42 .event-log .event {
43 margin-bottom: 5px;
44 padding: 2px 0;
45 border-bottom: 1px solid #eee;
46 }
47
48 .instruction {
49 background: #e8f4f8;
50 border: 1px solid #bee5eb;
51 border-radius: 4px;
52 padding: 10px;
53 margin: 10px 0;
54 }
55 </style>
56 </head>
57 <body>
58 <h1>Monaco Comment Test</h1>
59
60 <div class="instruction">
61 <strong>Instructions:</strong>
62 <ol>
63 <li>Hover over a line to see the comment glyph (💬) appear</li>
64 <li>Click on the glyph to open a comment box for that line</li>
65 <li>
66 Try clicking and dragging from one glyph to another to select multiple
67 lines
68 </li>
69 <li>
70 <strong>NEW:</strong> Make a text selection in the editor, then click
71 a glyph - it will use your selection instead of the line
72 </li>
73 <li>Fill out the comment and click "Add" to test the event dispatch</li>
74 </ol>
75 </div>
76
77 <div class="test-container">
78 <sketch-monaco-view id="testEditor"></sketch-monaco-view>
79 </div>
80
81 <div class="event-log" id="eventLog">
82 <strong>Event Log:</strong>
83 </div>
84
85 <script type="module">
86 // Load the Monaco component
87 import "../../dist/web-components/sketch-monaco-view.js";
88
89 document.addEventListener("DOMContentLoaded", () => {
90 const editor = document.getElementById("testEditor");
91 const eventLog = document.getElementById("eventLog");
92
93 // Set up test content
94 editor.originalCode = `function calculateTotal(items) {
95 return items
96 .map(item => item.price * item.quantity)
97 .reduce((a, b) => a + b, 0);
98}`;
99
100 editor.modifiedCode = `function calculateTotal(items) {
101 // Apply discount if available
102 return items
103 .map(item => {
104 const price = item.discount ?
105 item.price * (1 - item.discount) :
106 item.price;
107 return price * item.quantity;
108 })
109 .reduce((a, b) => a + b, 0);
110}`;
111
112 editor.originalFilename = "original.js";
113 editor.modifiedFilename = "modified.js";
114
115 // Log events
116 function logEvent(message) {
117 const eventDiv = document.createElement("div");
118 eventDiv.className = "event";
119 eventDiv.textContent = `${new Date().toLocaleTimeString()}: ${message}`;
120 eventLog.appendChild(eventDiv);
121 eventLog.scrollTop = eventLog.scrollHeight;
122 }
123
124 // Listen for comment events
125 editor.addEventListener("monaco-comment", (event) => {
126 logEvent("Monaco comment event received");
127 logEvent(`File: ${event.detail.fileContext}`);
128 logEvent(`Editor: ${event.detail.activeEditor}`);
129 logEvent(
130 `Lines: ${event.detail.selectionRange.startLineNumber}-${event.detail.selectionRange.endLineNumber}`,
131 );
132 logEvent(
133 `Selected text: ${event.detail.selectedText.substring(0, 50)}...`,
134 );
135 logEvent(`Comment: ${event.detail.commentText}`);
136 console.log("Full comment event:", event.detail);
137 });
138
139 logEvent("Test page loaded. Monaco component initialized.");
140 });
141 </script>
142 </body>
143</html>