@@ -3,7 +3,7 @@ import { highlightActiveLine, keymap, Decoration, DecorationSet,
33 ViewPlugin , ViewUpdate , WidgetType , drawSelection } from '@codemirror/view' ;
44import { javascript } from '@codemirror/lang-javascript' ;
55import { xml } from '@codemirror/lang-xml' ;
6- import { Vim , vim } from "../src/index"
6+ import { Vim , vim } from "../src/index" // "@replit/codemirror-vim"
77
88import * as commands from "@codemirror/commands" ;
99import { Annotation , Compartment , EditorState , Extension , Transaction , Range } from '@codemirror/state' ;
@@ -25,7 +25,8 @@ new EditorView({
2525
2626` ;
2727
28- function addOption ( name , description ?, onclick ?) {
28+ function addOption ( name : "wrap" | "html" | "status" | "jj" | "split" | "readOnly" ,
29+ description ?: string , onclick ?: ( value : boolean ) => void ) {
2930 let checkbox = document . createElement ( "input" ) ;
3031 checkbox . type = "checkbox" ;
3132 checkbox . id = name ;
@@ -49,16 +50,16 @@ class TestWidget extends WidgetType {
4950 constructor ( private side : number ) {
5051 super ( ) ;
5152 }
52- eq ( other ) {
53- return ( true ) ;
53+ override eq ( other : TestWidget ) {
54+ return other == this ;
5455 }
5556 toDOM ( ) {
5657 const wrapper = document . createElement ( 'span' ) ;
5758 wrapper . textContent = " widget" + this . side + " "
5859 wrapper . style . opacity = '0.4' ;
5960 return wrapper ;
6061 }
61- ignoreEvent ( ) {
62+ override ignoreEvent ( ) {
6263 return false ;
6364 }
6465}
@@ -73,7 +74,7 @@ function widgets(view: EditorView) {
7374 } )
7475 widgets . push ( deco . range ( 200 + 10 * i ) )
7576 }
76- console . log ( widgets )
77+ console . log ( widgets , view )
7778 return Decoration . set ( widgets )
7879}
7980
@@ -93,6 +94,7 @@ const testWidgetPlugin = ViewPlugin.fromClass(class {
9394
9495 eventHandlers : {
9596 mousedown : ( e , view ) => {
97+ console . log ( "mousedown" , e , view )
9698 }
9799 }
98100} )
@@ -117,10 +119,12 @@ var options = {
117119
118120
119121Vim . defineOption ( 'wrap' , false , 'boolean' , null , function ( val , cm ) {
122+ if ( ! cm ) console . log ( "should set global option" ) ;
120123 if ( val == undefined ) return options . wrap ;
121- var checkbox = document . getElementById ( "wrap" ) ;
124+ var checkbox = document . getElementById ( "wrap" ) as HTMLInputElement ;
122125 if ( checkbox ) {
123126 checkbox . checked = val ;
127+ //@ts -ignore
124128 checkbox . onclick ( ) ;
125129 }
126130} ) ;
@@ -166,21 +170,22 @@ var defaultExtensions = [
166170 ] ) ,
167171]
168172
169- function saveTab ( name ) {
173+ function saveTab ( name : string ) {
170174 return EditorView . updateListener . of ( ( v ) => {
171175 tabs [ name ] = v . state ;
172176 } )
173177}
174178
175- var tabs = {
179+
180+ var tabs : Record < string , EditorState > = {
176181 js : EditorState . create ( {
177182 doc : doc ,
178183 extensions : [ ...defaultExtensions , javascript ( ) , saveTab ( "js" ) ]
179184 } ) ,
180185 html : EditorState . create ( {
181186 doc : document . documentElement . outerHTML ,
182187 extensions : [ ...defaultExtensions , testWidgetPlugin , xml ( ) , saveTab ( "html" ) ]
183- } )
188+ } ) ,
184189}
185190
186191function updateView ( ) {
@@ -204,17 +209,25 @@ function updateView() {
204209 } )
205210}
206211
212+ declare global {
213+ interface Window {
214+ blinkRate ?: number ;
215+ }
216+ }
217+
207218function selectTab ( tab : string ) {
208- if ( view ) view . setState ( tabs [ tab ] )
209- if ( view2 ) view2 . setState ( tabs [ tab ] )
219+ let state = tabs [ tab ] ;
220+ if ( ! state ) return ;
221+ if ( view ) view . setState ( state )
222+ if ( view2 ) view2 . setState ( state )
210223 addLogListeners ( ) ;
211224}
212225
213226Vim . defineEx ( "tabnext" , "tabn" , ( ) => {
214- tabs [ " scratch" ] = EditorState . create ( {
227+ tabs . scratch = EditorState . create ( {
215228 doc : "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ,
216229 extensions : [ defaultExtensions , saveTab ( "scratch" ) ] ,
217- } )
230+ } ) ;
218231 selectTab ( "scratch" )
219232} ) ;
220233
@@ -304,7 +317,7 @@ updateView()
304317// save and restor search history
305318
306319
307- function saveHistory ( name ) {
320+ function saveHistory ( name : "exCommandHistoryController" | "searchHistoryController" ) {
308321 var controller = Vim . getVimGlobalState_ ( ) [ name ] ;
309322 var json = JSON . stringify ( controller ) ;
310323 if ( json . length > 10000 ) {
@@ -315,11 +328,11 @@ function saveHistory(name) {
315328 }
316329 localStorage [ name ] = json ;
317330}
318- function restoreHistory ( name ) {
331+ function restoreHistory ( name : "exCommandHistoryController" | "searchHistoryController" ) {
319332 try {
320333 var json = JSON . parse ( localStorage [ name ] ) ;
321334 var controller = Vim . getVimGlobalState_ ( ) [ name ] ;
322- controller . historyBuffer = json . historyBuffer . filter ( x => typeof x == "string" && x )
335+ controller . historyBuffer = json . historyBuffer . filter ( ( x : unknown ) => typeof x == "string" && x )
323336 controller . iterator = Math . min ( parseInt ( json . iterator ) || Infinity , controller . historyBuffer . length )
324337 } catch ( e ) {
325338
@@ -333,3 +346,7 @@ window.onunload = function() {
333346 saveHistory ( 'exCommandHistoryController' ) ;
334347 saveHistory ( 'searchHistoryController' ) ;
335348}
349+
350+ Vim . defineEx ( "write" , "w" , ( cm ) => {
351+ console . log ( "called" , cm ) ;
352+ } )
0 commit comments