@@ -53,6 +53,17 @@ document.addEventListener("DOMContentLoaded", function () {
53
53
vimModeElement . classList . add ( "unknown" ) ;
54
54
}
55
55
}
56
+ // Function to show relative line numbers
57
+ function showRelativeLines ( cm ) {
58
+ const lineNum = cm . getCursor ( ) . line + 1 ;
59
+ if ( cm . state . curLineNum === lineNum ) {
60
+ return ;
61
+ }
62
+ cm . state . curLineNum = lineNum ;
63
+ cm . setOption ( "lineNumberFormatter" , ( l ) =>
64
+ l === lineNum ? lineNum : Math . abs ( lineNum - l ) ,
65
+ ) ;
66
+ }
56
67
57
68
var editor = CodeMirror . fromTextArea ( document . getElementById ( "code" ) , {
58
69
lineNumbers : true ,
@@ -64,60 +75,7 @@ document.addEventListener("DOMContentLoaded", function () {
64
75
lineWrapping : true , // Optional: enable line wrapping if desired
65
76
} ) ;
66
77
67
- editor . setOption ( "extraKeys" , {
68
- "Ctrl-Y" : function ( ) {
69
- const selectedText = editor . getSelection ( ) ;
70
-
71
- if ( ! selectedText ) {
72
- document . getElementById ( "vim-command-line" ) . innerText =
73
- "No text selected to yank" ;
74
- setClearMessageTimer ( ) ;
75
- return ;
76
- }
77
-
78
- navigator . clipboard
79
- . writeText ( selectedText )
80
- . then ( function ( ) {
81
- document . getElementById ( "vim-command-line" ) . innerText =
82
- "Yanked to clipboard" ;
83
- } )
84
- . catch ( function ( error ) {
85
- document . getElementById ( "vim-command-line" ) . innerText =
86
- "Error yanking to clipboard: " + error . message ;
87
- } ) ;
88
-
89
- setClearMessageTimer ( ) ;
90
- editor . focus ( ) ;
91
- } ,
92
- "Ctrl-P" : function ( ) {
93
- navigator . clipboard
94
- . readText ( )
95
- . then ( function ( clipboardText ) {
96
- if ( clipboardText ) {
97
- const cursor = editor . getCursor ( ) ;
98
- editor . replaceRange ( clipboardText , cursor ) ;
99
- document . getElementById ( "vim-command-line" ) . innerText =
100
- "Pasted from clipboard" ;
101
- } else {
102
- document . getElementById ( "vim-command-line" ) . innerText =
103
- "Clipboard is empty" ;
104
- }
105
- } )
106
- . catch ( function ( error ) {
107
- document . getElementById ( "vim-command-line" ) . innerText =
108
- "Error pasting from clipboard: " + error . message ;
109
- } ) ;
110
-
111
- setClearMessageTimer ( ) ;
112
- editor . focus ( ) ;
113
- } ,
114
- } ) ;
115
-
116
- function setClearMessageTimer ( ) {
117
- setTimeout ( function ( ) {
118
- document . getElementById ( "vim-command-line" ) . innerText = "" ;
119
- } , 3000 ) ;
120
- }
78
+ editor . on ( "cursorActivity" , showRelativeLines ) ;
121
79
122
80
editor . focus ( ) ;
123
81
@@ -162,7 +120,7 @@ document.addEventListener("DOMContentLoaded", function () {
162
120
} catch ( error ) {
163
121
status = "Error saving: " + error . message ;
164
122
}
165
- document . getElementById ( "vim-command-line " ) . innerText = status ;
123
+ document . getElementById ( "status " ) . innerText = status ;
166
124
} ;
167
125
168
126
// Listen for changes in the prefers-color-scheme media query
0 commit comments