File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,8 @@ window.CPO = {
125125} ;
126126$ ( function ( ) {
127127 const CONTEXT_FOR_NEW_FILES = "use context starter2024\n" ;
128+ const CONTEXT_PREFIX = / ^ u s e c o n t e x t \s + / ;
129+
128130 function merge ( obj , extension ) {
129131 var newobj = { } ;
130132 Object . keys ( obj ) . forEach ( function ( k ) {
@@ -222,7 +224,7 @@ $(function() {
222224
223225 function firstLineIsNamespace ( ) {
224226 const firstline = CM . getLine ( 0 ) ;
225- const match = firstline . match ( / ^ u s e c o n t e x t . * / ) ;
227+ const match = firstline . match ( CONTEXT_PREFIX ) ;
226228 return match !== null ;
227229 }
228230
@@ -485,11 +487,14 @@ $(function() {
485487 } ) ;
486488 namespaceResult . show ( ( result ) => {
487489 if ( ! result ) { return ; }
488- if ( result . match ( / ^ u s e c o n t e x t * / ) ) { result = result . slice ( "use context " . length ) ; }
489- CPO . editor . setContextLine ( "use context " + result + "\n" ) ;
490+ CPO . editor . setContextLine ( "use context " + result . trim ( ) + "\n" ) ;
490491 } ) ;
491492 }
492- $ ( "#choose-context" ) . on ( "click" , function ( ) { showModal ( CPO . editor . cm . getLine ( 0 ) . slice ( "use context " . length ) ) ; } ) ;
493+ $ ( "#choose-context" ) . on ( "click" , function ( ) {
494+ const firstLine = CPO . editor . cm . getLine ( 0 ) ;
495+ const contextLen = firstLine . match ( CONTEXT_PREFIX ) ;
496+ showModal ( contextLen === null ? "" : firstLine . slice ( contextLen [ 0 ] . length ) ) ;
497+ } ) ;
493498
494499 var TRUNCATE_LENGTH = 20 ;
495500
You can’t perform that action at this time.
0 commit comments