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 = {
125
125
} ;
126
126
$ ( function ( ) {
127
127
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
+
128
130
function merge ( obj , extension ) {
129
131
var newobj = { } ;
130
132
Object . keys ( obj ) . forEach ( function ( k ) {
@@ -222,7 +224,7 @@ $(function() {
222
224
223
225
function firstLineIsNamespace ( ) {
224
226
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 ) ;
226
228
return match !== null ;
227
229
}
228
230
@@ -485,11 +487,14 @@ $(function() {
485
487
} ) ;
486
488
namespaceResult . show ( ( result ) => {
487
489
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" ) ;
490
491
} ) ;
491
492
}
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
+ } ) ;
493
498
494
499
var TRUNCATE_LENGTH = 20 ;
495
500
You can’t perform that action at this time.
0 commit comments