@@ -53,6 +53,7 @@ document.addEventListener("DOMContentLoaded", function () {
53
53
vimModeElement . classList . add ( "unknown" ) ;
54
54
}
55
55
}
56
+
56
57
// Function to show relative line numbers
57
58
function showRelativeLines ( cm ) {
58
59
const lineNum = cm . getCursor ( ) . line + 1 ;
@@ -65,25 +66,8 @@ document.addEventListener("DOMContentLoaded", function () {
65
66
) ;
66
67
}
67
68
68
- var editor = CodeMirror . fromTextArea ( document . getElementById ( "code" ) , {
69
- lineNumbers : true ,
70
- mode : "text/x-csrc" ,
71
- keyMap : "vim" ,
72
- matchBrackets : true ,
73
- showCursorWhenSelecting : true ,
74
- theme : getPreferredTheme ( ) ,
75
- lineWrapping : true , // Optional: enable line wrapping if desired
76
- } ) ;
77
-
78
- editor . on ( "cursorActivity" , showRelativeLines ) ;
79
- editor . focus ( ) ;
80
-
81
- var vimMode = document . getElementById ( "vim-mode" ) ;
82
- CodeMirror . on ( editor , "vim-mode-change" , function ( e ) {
83
- updateVimMode ( e , vimMode ) ;
84
- } ) ;
85
-
86
- CodeMirror . commands . save = async function ( ) {
69
+ // Function to save the content
70
+ async function saveContent ( ) {
87
71
let status = "No changes were made." ;
88
72
89
73
try {
@@ -120,7 +104,32 @@ document.addEventListener("DOMContentLoaded", function () {
120
104
status = "Error saving: " + error . message ;
121
105
}
122
106
document . getElementById ( "status" ) . innerText = status ;
123
- } ;
107
+ }
108
+
109
+ var editor = CodeMirror . fromTextArea ( document . getElementById ( "code" ) , {
110
+ lineNumbers : true ,
111
+ mode : "text/x-csrc" ,
112
+ keyMap : "vim" ,
113
+ matchBrackets : true ,
114
+ showCursorWhenSelecting : true ,
115
+ theme : getPreferredTheme ( ) ,
116
+ lineWrapping : true , // Optional: enable line wrapping if desired
117
+ } ) ;
118
+
119
+ editor . on ( "cursorActivity" , showRelativeLines ) ;
120
+ editor . focus ( ) ;
121
+
122
+ // Custom vim Ex commands
123
+ CodeMirror . Vim . defineEx ( "x" , "" , function ( ) {
124
+ saveContent ( ) ;
125
+ } ) ;
126
+
127
+ var vimMode = document . getElementById ( "vim-mode" ) ;
128
+ CodeMirror . on ( editor , "vim-mode-change" , function ( e ) {
129
+ updateVimMode ( e , vimMode ) ;
130
+ } ) ;
131
+
132
+ CodeMirror . commands . save = saveContent ;
124
133
125
134
// Listen for changes in the prefers-color-scheme media query
126
135
window . matchMedia ( "(prefers-color-scheme: dark)" ) . addListener ( ( e ) => {
0 commit comments