Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Version switcher #3334

Draft
wants to merge 16 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions client/components/Dropdown/DropdownMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import { DropdownWrapper } from '../Dropdown';

const DropdownMenu = forwardRef(
(
{ children, anchor, 'aria-label': ariaLabel, align, className, classes },
{
children,
anchor,
'aria-label': ariaLabel,
align,
className,
classes,
maxHeight
},
ref
) => {
// Note: need to use a ref instead of a state to avoid stale closures.
Expand All @@ -32,7 +40,7 @@ const DropdownMenu = forwardRef(
focusedRef.current = false;
setTimeout(() => {
if (!focusedRef.current) {
close();
// close();
}
}, 200);
};
Expand All @@ -59,6 +67,7 @@ const DropdownMenu = forwardRef(
}}
onBlur={handleBlur}
onFocus={handleFocus}
style={maxHeight && { maxHeight, overflowY: 'auto' }}
>
{children}
</DropdownWrapper>
Expand All @@ -84,14 +93,16 @@ DropdownMenu.propTypes = {
classes: PropTypes.shape({
button: PropTypes.string,
list: PropTypes.string
})
}),
maxHeight: PropTypes.string
};

DropdownMenu.defaultProps = {
anchor: null,
align: 'right',
className: '',
classes: {}
classes: {},
maxHeight: undefined
};

export default DropdownMenu;
1 change: 1 addition & 0 deletions client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const STOP_ACCESSIBLE_OUTPUT = 'STOP_ACCESSIBLE_OUTPUT';

export const OPEN_PREFERENCES = 'OPEN_PREFERENCES';
export const CLOSE_PREFERENCES = 'CLOSE_PREFERENCES';
export const SET_PREFERENCES_TAB = 'SET_PREFERENCES_TAB';
export const SET_FONT_SIZE = 'SET_FONT_SIZE';
export const SET_LINE_NUMBERS = 'SET_LINE_NUMBERS';

Expand Down
7 changes: 7 additions & 0 deletions client/modules/IDE/actions/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ function updatePreferences(formParams, dispatch) {
});
}

export function setPreferencesTab(value) {
return {
type: ActionTypes.SET_PREFERENCES_TAB,
value
};
}

export function setFontSize(value) {
return (dispatch, getState) => {
// eslint-disable-line
Expand Down
24 changes: 22 additions & 2 deletions client/modules/IDE/components/Editor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import UnsavedChangesIndicator from '../UnsavedChangesIndicator';
import { EditorContainer, EditorHolder } from './MobileEditor';
import { FolderIcon } from '../../../../common/icons';
import IconButton from '../../../../common/IconButton';
import VersionIndicator from '../VersionIndicator';

emmet(CodeMirror);

Expand Down Expand Up @@ -104,6 +105,7 @@ class Editor extends React.Component {
this.showFind = this.showFind.bind(this);
this.showReplace = this.showReplace.bind(this);
this.getContent = this.getContent.bind(this);
this.updateFileContent = this.updateFileContent.bind(this);
}

componentDidMount() {
Expand Down Expand Up @@ -223,7 +225,8 @@ class Editor extends React.Component {
tidyCode: this.tidyCode,
showFind: this.showFind,
showReplace: this.showReplace,
getContent: this.getContent
getContent: this.getContent,
updateFileContent: this.updateFileContent
});
}

Expand Down Expand Up @@ -257,6 +260,9 @@ class Editor extends React.Component {
if (!prevProps.unsavedChanges) {
setTimeout(() => this.props.setUnsavedChanges(false), 400);
}
} else if (this.getContent().content !== this.props.file.content) {
// TODO: make this not break regular edits!
// this._cm.setValue(this.props.file.content);
}
if (this.props.fontSize !== prevProps.fontSize) {
this._cm.getWrapperElement().style[
Expand Down Expand Up @@ -332,7 +338,8 @@ class Editor extends React.Component {
tidyCode: this.tidyCode,
showFind: this.showFind,
showReplace: this.showReplace,
getContent: this.getContent
getContent: this.getContent,
updateFileContent: this.updateFileContent
});
}

Expand Down Expand Up @@ -369,6 +376,16 @@ class Editor extends React.Component {
return updatedFile;
}

updateFileContent(id, src) {
const file = this._docs[id];
if (file) {
this._docs[id] = CodeMirror.Doc(src, this._docs[id].modeOption);
if (id === this.props.file.id) {
this._cm.swapDoc(this._docs[id]);
}
}
}

handleKeyUp = () => {
const lineNumber = parseInt(this._cm.getCursor().line + 1, 10);
this.setState({ currentLine: lineNumber });
Expand Down Expand Up @@ -562,6 +579,9 @@ class Editor extends React.Component {
</span>
<Timer />
</div>
<div className="editor__library-version">
<VersionIndicator />
</div>
</div>
<article
ref={(element) => {
Expand Down
Loading