1- import { EditorView , keymap , lineNumbers , highlightActiveLine , highlightActiveLineGutter } from '@codemirror/view' ;
2- import { EditorState , Compartment } from '@codemirror/state' ;
3- import { defaultKeymap , history , historyKeymap } from '@codemirror/commands' ;
4- import { bracketMatching , indentOnInput , foldGutter , foldKeymap } from '@codemirror/language' ;
5- import { closeBrackets , closeBracketsKeymap } from '@codemirror/autocomplete' ;
6- import { vim , Vim } from '@replit/codemirror-vim' ;
7-
8- import { themeRegistry , getTheme , getDefaultTheme , type McTheme } from './themes/index' ;
9- import { languageRegistry , getLanguage , detectPattern , type McLanguage } from './languages/index' ;
10- import { getPreset } from './presets/index' ;
11- import { initAudio , setMusicConfig , playKeySound , playBackspace , playMelodyNote , playPatternSound , isAudioInitialized , setVolume , getVolume } from './music' ;
1+ import {
2+ EditorView ,
3+ keymap ,
4+ lineNumbers ,
5+ highlightActiveLine ,
6+ highlightActiveLineGutter ,
7+ } from "@codemirror/view" ;
8+ import { EditorState , Compartment } from "@codemirror/state" ;
9+ import { defaultKeymap , history , historyKeymap } from "@codemirror/commands" ;
10+ import {
11+ bracketMatching ,
12+ indentOnInput ,
13+ foldGutter ,
14+ foldKeymap ,
15+ } from "@codemirror/language" ;
16+ import { closeBrackets , closeBracketsKeymap } from "@codemirror/autocomplete" ;
17+ import { vim , Vim } from "@replit/codemirror-vim" ;
18+
19+ import {
20+ themeRegistry ,
21+ getTheme ,
22+ getDefaultTheme ,
23+ type McTheme ,
24+ } from "./themes/index" ;
25+ import {
26+ languageRegistry ,
27+ getLanguage ,
28+ detectPattern ,
29+ type McLanguage ,
30+ } from "./languages/index" ;
31+ import { getPreset } from "./presets/index" ;
32+ import {
33+ initAudio ,
34+ setMusicConfig ,
35+ playKeySound ,
36+ playBackspace ,
37+ playMelodyNote ,
38+ playPatternSound ,
39+ isAudioInitialized ,
40+ setVolume ,
41+ getVolume ,
42+ } from "./music" ;
1243
1344let editorView : EditorView | null = null ;
1445let currentTheme : McTheme ;
@@ -19,20 +50,20 @@ const themeCompartment = new Compartment();
1950const languageCompartment = new Compartment ( ) ;
2051const vimCompartment = new Compartment ( ) ;
2152
22- let lastCode = '' ;
53+ let lastCode = "" ;
2354let keystrokeCount = 0 ;
2455
2556// Language to filename mapping
2657const languageFileNames : Record < string , string > = {
27- javascript : ' main.js' ,
28- python : ' main.py' ,
29- rust : ' main.rs' ,
30- zig : ' main.zig' ,
58+ javascript : " main.js" ,
59+ python : " main.py" ,
60+ rust : " main.rs" ,
61+ zig : " main.zig" ,
3162} ;
3263
3364export async function initEditor ( container : HTMLElement ) : Promise < EditorView > {
3465 // Set defaults based on system preference
35- const isDark = window . matchMedia ( ' (prefers-color-scheme: dark)' ) . matches ;
66+ const isDark = window . matchMedia ( " (prefers-color-scheme: dark)" ) . matches ;
3667 currentTheme = getDefaultTheme ( isDark ) ;
3768 currentLanguage = languageRegistry [ 0 ] ;
3869
@@ -72,7 +103,7 @@ export async function initEditor(container: HTMLElement): Promise<EditorView> {
72103 handleKeystroke ( event . key ) ;
73104
74105 // Enable vim mode with Ctrl + [
75- if ( ! vimEnabled && event . key === '[' && event . ctrlKey ) {
106+ if ( ! vimEnabled && event . key === "[" && event . ctrlKey ) {
76107 event . preventDefault ( ) ;
77108 enableVim ( ) ;
78109 }
@@ -91,7 +122,7 @@ export async function initEditor(container: HTMLElement): Promise<EditorView> {
91122
92123 // Initialize statusline
93124 updateStatuslineFile ( currentLanguage . id , currentLanguage . name ) ;
94- updateStatuslineMode ( ' edit' ) ;
125+ updateStatuslineMode ( " edit" ) ;
95126 updateStatuslinePosition ( editorView ) ;
96127
97128 // Set up vim mode change listener
@@ -102,27 +133,27 @@ export async function initEditor(container: HTMLElement): Promise<EditorView> {
102133
103134function applyThemeColors ( theme : McTheme ) : void {
104135 const root = document . documentElement ;
105- root . style . setProperty ( ' --bg-primary' , theme . colors . bgPrimary ) ;
106- root . style . setProperty ( ' --bg-secondary' , theme . colors . bgSecondary ) ;
107- root . style . setProperty ( ' --text-primary' , theme . colors . textPrimary ) ;
108- root . style . setProperty ( ' --text-secondary' , theme . colors . textSecondary ) ;
109- root . style . setProperty ( ' --accent' , theme . colors . accent ) ;
110- root . style . setProperty ( ' --border' , theme . colors . border ) ;
136+ root . style . setProperty ( " --bg-primary" , theme . colors . bgPrimary ) ;
137+ root . style . setProperty ( " --bg-secondary" , theme . colors . bgSecondary ) ;
138+ root . style . setProperty ( " --text-primary" , theme . colors . textPrimary ) ;
139+ root . style . setProperty ( " --text-secondary" , theme . colors . textSecondary ) ;
140+ root . style . setProperty ( " --accent" , theme . colors . accent ) ;
141+ root . style . setProperty ( " --border" , theme . colors . border ) ;
111142}
112143
113144async function handleKeystroke ( key : string ) : Promise < void > {
114145 if ( ! isAudioInitialized ( ) ) {
115146 await initAudio ( ) ;
116147 setMusicConfig ( currentTheme . music ) ;
117148 // Update audio indicator
118- const indicator = document . getElementById ( ' audio-indicator' ) ;
149+ const indicator = document . getElementById ( " audio-indicator" ) ;
119150 if ( indicator ) {
120- indicator . classList . add ( ' active' ) ;
121- indicator . title = ' Audio active' ;
151+ indicator . classList . add ( " active" ) ;
152+ indicator . title = " Audio active" ;
122153 }
123154 }
124155
125- const isBackspace = key === ' Backspace' || key === ' Delete' ;
156+ const isBackspace = key === " Backspace" || key === " Delete" ;
126157
127158 if ( isBackspace ) {
128159 playBackspace ( ) ;
@@ -151,7 +182,11 @@ function handleCodeChange(code: string): void {
151182 hasConditional : patterns . hasConditional && ! lastPatterns . hasConditional ,
152183 } ;
153184
154- if ( newPatterns . hasFunction || newPatterns . hasLoop || newPatterns . hasConditional ) {
185+ if (
186+ newPatterns . hasFunction ||
187+ newPatterns . hasLoop ||
188+ newPatterns . hasConditional
189+ ) {
155190 playPatternSound ( newPatterns ) ;
156191 }
157192
@@ -207,7 +242,7 @@ export function toggleVim(): boolean {
207242 } ) ;
208243
209244 // Update statusline mode
210- updateStatuslineMode ( vimEnabled ? ' normal' : ' edit' ) ;
245+ updateStatuslineMode ( vimEnabled ? " normal" : " edit" ) ;
211246
212247 return vimEnabled ;
213248}
@@ -221,13 +256,13 @@ function enableVim(): void {
221256 } ) ;
222257
223258 // Update statusline mode
224- updateStatuslineMode ( ' normal' ) ;
259+ updateStatuslineMode ( " normal" ) ;
225260
226261 // Sync the toggle button in settings
227- const vimToggle = document . getElementById ( ' vim-toggle' ) ;
262+ const vimToggle = document . getElementById ( " vim-toggle" ) ;
228263 if ( vimToggle ) {
229- vimToggle . setAttribute ( ' aria-pressed' , ' true' ) ;
230- vimToggle . classList . add ( ' active' ) ;
264+ vimToggle . setAttribute ( " aria-pressed" , " true" ) ;
265+ vimToggle . classList . add ( " active" ) ;
231266 }
232267}
233268
@@ -253,36 +288,42 @@ function updateStatuslinePosition(view: EditorView): void {
253288 const line = view . state . doc . lineAt ( pos ) ;
254289 const col = pos - line . from + 1 ;
255290
256- const positionEl = document . getElementById ( ' statusline-position' ) ;
291+ const positionEl = document . getElementById ( " statusline-position" ) ;
257292 if ( positionEl ) {
258293 positionEl . textContent = `${ line . number } :${ col } ` ;
259294 }
260295}
261296
262297export function updateStatuslineMode ( mode : string ) : void {
263- const modeEl = document . getElementById ( ' statusline-mode' ) ;
298+ const modeEl = document . getElementById ( " statusline-mode" ) ;
264299 if ( ! modeEl ) return ;
265300
266301 // Remove all mode classes
267- modeEl . classList . remove ( ' mode-normal' , ' mode-insert' , ' mode-edit' ) ;
302+ modeEl . classList . remove ( " mode-normal" , " mode-insert" , " mode-edit" ) ;
268303
269304 // Only normal and insert modes supported
270305 const modeMap : Record < string , { class : string ; text : string } > = {
271- normal : { class : ' mode-normal' , text : ' NORMAL' } ,
272- insert : { class : ' mode-insert' , text : ' INSERT' } ,
306+ normal : { class : " mode-normal" , text : " NORMAL" } ,
307+ insert : { class : " mode-insert" , text : " INSERT" } ,
273308 } ;
274309
275- const modeInfo = modeMap [ mode . toLowerCase ( ) ] || { class : 'mode-edit' , text : mode . toUpperCase ( ) } ;
310+ const modeInfo = modeMap [ mode . toLowerCase ( ) ] || {
311+ class : "mode-edit" ,
312+ text : mode . toUpperCase ( ) ,
313+ } ;
276314 modeEl . classList . add ( modeInfo . class ) ;
277315 modeEl . textContent = modeInfo . text ;
278316}
279317
280- export function updateStatuslineFile ( languageId : string , languageName : string ) : void {
318+ export function updateStatuslineFile (
319+ languageId : string ,
320+ languageName : string ,
321+ ) : void {
281322 const fileName = languageFileNames [ languageId ] || `main.${ languageId } ` ;
282323
283- const bufferNameEl = document . getElementById ( ' buffer-name' ) ;
284- const fileEl = document . getElementById ( ' statusline-file' ) ;
285- const langEl = document . getElementById ( ' statusline-language' ) ;
324+ const bufferNameEl = document . getElementById ( " buffer-name" ) ;
325+ const fileEl = document . getElementById ( " statusline-file" ) ;
326+ const langEl = document . getElementById ( " statusline-language" ) ;
286327
287328 if ( bufferNameEl ) bufferNameEl . textContent = fileName ;
288329 if ( fileEl ) fileEl . textContent = fileName ;
@@ -300,13 +341,13 @@ function setupVimModeListener(): void {
300341 vimListenerSetup = true ;
301342
302343 // Disable visual, replace, and command modes - keep only normal and insert
303- Vim . unmap ( 'v' , ' normal' ) ;
304- Vim . unmap ( 'V' , ' normal' ) ;
305- Vim . unmap ( ' <C-v>' , ' normal' ) ;
306- Vim . unmap ( 'R' , ' normal' ) ;
307- Vim . unmap ( ':' , ' normal' ) ;
344+ Vim . unmap ( "v" , " normal" ) ;
345+ Vim . unmap ( "V" , " normal" ) ;
346+ Vim . unmap ( " <C-v>" , " normal" ) ;
347+ Vim . unmap ( "R" , " normal" ) ;
348+ Vim . unmap ( ":" , " normal" ) ;
308349
309- Vim . on ( ' vim-mode-change' , ( e : { mode : string ; subMode ?: string } ) => {
350+ Vim . on ( " vim-mode-change" , ( e : { mode : string ; subMode ?: string } ) => {
310351 if ( ! vimEnabled ) return ;
311352 updateStatuslineMode ( e . mode ) ;
312353 } ) ;
0 commit comments