Skip to content

Commit 1535ba5

Browse files
authored
Merge pull request #3848 from processing/autocomplete-ref-2.0
Update Autocomplete Hinter Reference URL to 2.x Docs on Version Change
2 parents 98864de + 0b46f7b commit 1535ba5

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

client/modules/IDE/components/Editor/index.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
/https:\/\/beta\.p5js\.org\b/i.test(html) || /\bp5(@|-)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+
747766
function mapStateToProps(state) {
748767
return {
749768
files: state.files,

client/modules/IDE/components/show-hint.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,12 @@ import CodeMirror from 'codemirror';
296296
}
297297

298298
// hintsElement is the parent for hints and el is the clicked element within that container
299-
function displayHint(name, type, p5, isBlacklistedFunction) {
299+
function displayHint(name, type, p5, isBlacklistedFunction, referenceBaseUrl) {
300+
const base = referenceBaseUrl || 'https://p5js.org';
301+
const refName = typeof p5 === 'string' ? p5 : name;
302+
300303
const linkOrPlaceholder = p5
301-
? `<a href="https://p5js.org/reference/p5/${
302-
typeof p5 === 'string' ? p5 : name
303-
}" role="link" onclick="event.stopPropagation()" target="_blank">
304+
? `<a href="${base}/reference/p5/${refName}" role="link" onclick="event.stopPropagation()" target="_blank">
304305
<span class="hint-hidden">open ${name} reference</span>
305306
<span aria-hidden="true" class="arrow-icon">➔</span>
306307
</a>`
@@ -400,6 +401,8 @@ import CodeMirror from 'codemirror';
400401
hints.className = 'CodeMirror-hints ' + theme;
401402
this.selectedHint = data.selectedHint || 0;
402403

404+
const referenceBaseUrl = completion.options.referenceBaseUrl || 'https://p5js.org';
405+
403406
// Show inline hint
404407
changeInlineHint(cm, data.list[this.selectedHint]);
405408

@@ -430,7 +433,8 @@ import CodeMirror from 'codemirror';
430433
name,
431434
cur.item.type,
432435
cur.item.p5,
433-
cur.isBlacklisted
436+
cur.isBlacklisted,
437+
referenceBaseUrl
434438
);
435439
}
436440

0 commit comments

Comments
 (0)