clean up code
Hunter
Thursday, July 24th, 2025 at 3:56 PM
70 height: 100%;
71 font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
72 font-size: 21px;
- tab-size: 2;
73 }
74
75 /* CodeMirror styling */
78 height: 100%;
79 background: var(--editor-bg);
80 color: var(--text-color);
- tab-size: 2;
81 }
82
83 .cm-placeholder {
89 padding: 15px;
90 font-size: 21px;
91 line-height: 1.5;
- tab-size: 2;
92 }
93
94 .cm-focused {
192 // Store scroll position before updating
193 let scrollX = 0, scrollY = 0;
194 try {
- if (preview.contentWindow && preview.contentDocument) {
195 + if (preview.contentWindow?.scrollX !== undefined) {
196 scrollX = preview.contentWindow.scrollX;
197 scrollY = preview.contentWindow.scrollY;
198 }
241 // Restore scroll position
242 setTimeout(() => {
243 try {
- if (preview.contentWindow) {
- preview.contentWindow.scrollTo(scrollX, scrollY);
- }
244 + preview.contentWindow?.scrollTo(scrollX, scrollY);
245 } catch (e) {
246 // Ignore cross-origin errors
247 }
257
258 function saveToStorage() {
259 try {
- const code = editorView.state.doc.toString();
- localStorage.setItem(storageKey, code);
260 + localStorage.setItem(storageKey, editorView.state.doc.toString());
261 } catch (e) {
- // Handle localStorage errors silently
262 console.warn('Could not save to localStorage:', e);
263 }
264 }
265
266 function loadFromStorage() {
267 try {
- const saved = localStorage.getItem(storageKey);
- if (saved !== null) {
- // Handle old format that might be JSON
- try {
- const data = JSON.parse(saved);
- return data.text || data.html || saved;
- } catch (parseError) {
- return saved;
- }
- }
268 + return localStorage.getItem(storageKey) || '';
269 } catch (e) {
- // Handle localStorage errors silently
270 console.warn('Could not load from localStorage:', e);
271 + return '';
272 }
- return '';
273 }
274
- // Simple file operations
275 + // File operations
276 window.saveFile = function() {
- const code = editorView.state.doc.toString();
- const blob = new Blob([code], { type: 'text/html' });
277 + const blob = new Blob([editorView.state.doc.toString()], { type: 'text/html' });
278 const url = URL.createObjectURL(blob);
279 const a = document.createElement('a');
280 a.href = url;