@@ -53,6 +53,17 @@ document.addEventListener("DOMContentLoaded", function () {
5353 vimModeElement . classList . add ( "unknown" ) ;
5454 }
5555 }
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+ }
5667
5768 var editor = CodeMirror . fromTextArea ( document . getElementById ( "code" ) , {
5869 lineNumbers : true ,
@@ -64,60 +75,7 @@ document.addEventListener("DOMContentLoaded", function () {
6475 lineWrapping : true , // Optional: enable line wrapping if desired
6576 } ) ;
6677
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 ) ;
12179
12280 editor . focus ( ) ;
12381
@@ -162,7 +120,7 @@ document.addEventListener("DOMContentLoaded", function () {
162120 } catch ( error ) {
163121 status = "Error saving: " + error . message ;
164122 }
165- document . getElementById ( "vim-command-line " ) . innerText = status ;
123+ document . getElementById ( "status " ) . innerText = status ;
166124 } ;
167125
168126 // Listen for changes in the prefers-color-scheme media query
0 commit comments