@@ -421,6 +421,17 @@ class Editor extends React.Component {
421421 this . _cm . execCommand ( 'findPersistent' ) ;
422422 }
423423
424+ // temporary until p5.js 2.0 becomes default
425+ // checks if sketch is using p5.js 2.0 to pass correct base url for autocomplete hinter reference
426+ getReferenceBaseUrl = ( ) => {
427+ const html = this . props . htmlFile ?. content || '' ;
428+
429+ const isV2 =
430+ / h t t p s : \/ \/ b e t a \. p 5 j s \. o r g \b / i. test ( html ) || / \b p 5 ( @ | - ) 2 \. / i. test ( html ) ;
431+
432+ return isV2 ? 'https://beta.p5js.org' : 'https://p5js.org' ;
433+ } ;
434+
424435 showHint ( _cm ) {
425436 if ( ! _cm ) return ;
426437
@@ -460,6 +471,7 @@ class Editor extends React.Component {
460471
461472 const hintOptions = {
462473 _fontSize : this . props . fontSize ,
474+ referenceBaseUrl : this . getReferenceBaseUrl ( ) ,
463475 completeSingle : false ,
464476 extraKeys : {
465477 'Shift-Right' : ( cm , e ) => {
@@ -731,6 +743,9 @@ Editor.propTypes = {
731743 content : PropTypes . string . isRequired
732744 } )
733745 ) . isRequired ,
746+ htmlFile : PropTypes . shape ( {
747+ content : PropTypes . string
748+ } ) ,
734749 isExpanded : PropTypes . bool . isRequired ,
735750 collapseSidebar : PropTypes . func . isRequired ,
736751 closeProjectOptions : PropTypes . func . isRequired ,
@@ -744,6 +759,10 @@ Editor.propTypes = {
744759 expandConsole : PropTypes . func . isRequired
745760} ;
746761
762+ Editor . defaultProps = {
763+ htmlFile : null
764+ } ;
765+
747766function mapStateToProps ( state ) {
748767 return {
749768 files : state . files ,
0 commit comments