include space and tab
This commit is contained in:
parent
3bdd02e859
commit
65bd8c2e63
9 changed files with 103 additions and 9 deletions
|
@ -12,6 +12,8 @@ export const UPDATE_FONTSIZE = 'UPDATE_FONTSIZE';
|
||||||
export const INCREASE_INDENTATION = 'INCREASE_INDENTATION';
|
export const INCREASE_INDENTATION = 'INCREASE_INDENTATION';
|
||||||
export const DECREASE_INDENTATION = 'DECREASE_INDENTATION';
|
export const DECREASE_INDENTATION = 'DECREASE_INDENTATION';
|
||||||
export const UPDATE_INDENTATION = 'UPDATE_INDENTATION';
|
export const UPDATE_INDENTATION = 'UPDATE_INDENTATION';
|
||||||
|
export const INDENT_WITH_SPACE = 'INDENT_WITH_SPACE';
|
||||||
|
export const INDENT_WITH_TAB = 'INDENT_WITH_TAB';
|
||||||
|
|
||||||
export const AUTH_USER = 'AUTH_USER';
|
export const AUTH_USER = 'AUTH_USER';
|
||||||
export const UNAUTH_USER = 'UNAUTH_USER';
|
export const UNAUTH_USER = 'UNAUTH_USER';
|
||||||
|
|
|
@ -51,3 +51,15 @@ export function updateIndentation() {
|
||||||
value
|
value
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function indentWithTab() {
|
||||||
|
return {
|
||||||
|
type: ActionTypes.INDENT_WITH_TAB
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function indentWithSpace() {
|
||||||
|
return {
|
||||||
|
type: ActionTypes.INDENT_WITH_SPACE
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,10 @@ class Editor extends React.Component {
|
||||||
this.props.updateFile('sketch.js', this._cm.getValue());
|
this.props.updateFile('sketch.js', this._cm.getValue());
|
||||||
});
|
});
|
||||||
this._cm.getWrapperElement().style['font-size'] = `${this.props.fontSize}px`;
|
this._cm.getWrapperElement().style['font-size'] = `${this.props.fontSize}px`;
|
||||||
|
|
||||||
|
this._cm.setOption('indentWithTabs', this.props.indentWithTab);
|
||||||
this._cm.setOption('tabSize', this.props.indentationAmount);
|
this._cm.setOption('tabSize', this.props.indentationAmount);
|
||||||
|
this._cm.setOption('indentUnit', this.props.indentationAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
|
@ -48,7 +51,8 @@ Editor.propTypes = {
|
||||||
content: PropTypes.string.isRequired,
|
content: PropTypes.string.isRequired,
|
||||||
updateFile: PropTypes.func.isRequired,
|
updateFile: PropTypes.func.isRequired,
|
||||||
fontSize: PropTypes.number.isRequired,
|
fontSize: PropTypes.number.isRequired,
|
||||||
indentationAmount: PropTypes.number.isRequired
|
indentationAmount: PropTypes.number.isRequired,
|
||||||
|
isTabIndent: PropTypes.bool.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Editor;
|
export default Editor;
|
||||||
|
|
|
@ -11,6 +11,14 @@ function Preferences(props) {
|
||||||
preferences: true,
|
preferences: true,
|
||||||
'preferences--selected': props.isVisible
|
'preferences--selected': props.isVisible
|
||||||
});
|
});
|
||||||
|
let preferencesTabOptionClass = classNames({
|
||||||
|
preference__option: true,
|
||||||
|
'preference__option--selected': props.isTabIndent
|
||||||
|
});
|
||||||
|
let preferencesSpaceOptionClass = classNames({
|
||||||
|
preference__option: true,
|
||||||
|
'preference__option--selected': !props.isTabIndent
|
||||||
|
});
|
||||||
return (
|
return (
|
||||||
<div className={preferencesContainerClass} tabIndex="0">
|
<div className={preferencesContainerClass} tabIndex="0">
|
||||||
<div className="preferences__heading">
|
<div className="preferences__heading">
|
||||||
|
@ -24,22 +32,33 @@ function Preferences(props) {
|
||||||
<h4 className="preference__title">Text Size</h4>
|
<h4 className="preference__title">Text Size</h4>
|
||||||
<button className="preference__plus-button" onClick={props.decreaseFont}>
|
<button className="preference__plus-button" onClick={props.decreaseFont}>
|
||||||
<Isvg src={minusUrl} alt="Decrease Font Size" />
|
<Isvg src={minusUrl} alt="Decrease Font Size" />
|
||||||
|
<h6 className="preference__label">Decrease</h6>
|
||||||
</button>
|
</button>
|
||||||
<input className="preference__value" defaultValue={props.fontSize} value={props.fontSize} onChange={props.updateFont}></input>
|
|
||||||
|
<input className="preference__value" value={props.fontSize} onChange={props.updateFont}></input>
|
||||||
<button className="preference__minus-button" onClick={props.increaseFont}>
|
<button className="preference__minus-button" onClick={props.increaseFont}>
|
||||||
<Isvg src={plusUrl} alt="Increase Font Size" />
|
<Isvg src={plusUrl} alt="Increase Font Size" />
|
||||||
|
<h6 className="preference__label">Increase</h6>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="preference">
|
<div className="preference">
|
||||||
<h4 className="preference__title">Indentation Amount</h4>
|
<h4 className="preference__title">Indentation Amount</h4>
|
||||||
<button className="preference__plus-button" onClick={props.decreaseIndentation}>
|
<button className="preference__plus-button" onClick={props.decreaseIndentation}>
|
||||||
<Isvg src={minusUrl} alt="DecreaseIndentation Amount" />
|
<Isvg src={minusUrl} alt="DecreaseIndentation Amount" />
|
||||||
|
<h6 className="preference__label">Decrease</h6>
|
||||||
</button>
|
</button>
|
||||||
<input className="preference__value" defaultValue={props.indentationAmount} value={props.indentationAmount} onChange={props.updateIndentation}></input>
|
<input className="preference__value" value={props.indentationAmount} onChange={props.updateIndentation}></input>
|
||||||
<button className="preference__minus-button" onClick={props.increaseIndentation}>
|
<button className="preference__minus-button" onClick={props.increaseIndentation}>
|
||||||
<Isvg src={plusUrl} alt="IncreaseIndentation Amount" />
|
<Isvg src={plusUrl} alt="IncreaseIndentation Amount" />
|
||||||
|
<h6 className="preference__label">Increase</h6>
|
||||||
</button>
|
</button>
|
||||||
|
<ul>
|
||||||
|
<li className={preferencesSpaceOptionClass} onClick={props.indentWithSpace}>Spaces</li>
|
||||||
|
<li className={preferencesTabOptionClass} onClick={props.indentWithTab}>Tabs</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -56,7 +75,10 @@ Preferences.propTypes = {
|
||||||
indentationAmount: PropTypes.number.isRequired,
|
indentationAmount: PropTypes.number.isRequired,
|
||||||
decreaseIndentation: PropTypes.func.isRequired,
|
decreaseIndentation: PropTypes.func.isRequired,
|
||||||
increaseIndentation: PropTypes.func.isRequired,
|
increaseIndentation: PropTypes.func.isRequired,
|
||||||
updateIndentation: PropTypes.func.isRequired
|
updateIndentation: PropTypes.func.isRequired,
|
||||||
|
indentWithSpace: PropTypes.func.isRequired,
|
||||||
|
indentWithTab: PropTypes.func.isRequired,
|
||||||
|
isTabIndent: PropTypes.bool.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Preferences;
|
export default Preferences;
|
||||||
|
|
|
@ -48,12 +48,16 @@ class IDEView extends React.Component {
|
||||||
decreaseIndentation={this.props.decreaseIndentation}
|
decreaseIndentation={this.props.decreaseIndentation}
|
||||||
updateIndentation={this.props.updateIndentation}
|
updateIndentation={this.props.updateIndentation}
|
||||||
indentationAmount={this.props.preferences.indentationAmount}
|
indentationAmount={this.props.preferences.indentationAmount}
|
||||||
|
isTabIndent={this.props.preferences.isTabIndent}
|
||||||
|
indentWithSpace={this.props.indentWithSpace}
|
||||||
|
indentWithTab={this.props.indentWithTab}
|
||||||
/>
|
/>
|
||||||
<Editor
|
<Editor
|
||||||
content={this.props.file.content}
|
content={this.props.file.content}
|
||||||
updateFile={this.props.updateFile}
|
updateFile={this.props.updateFile}
|
||||||
fontSize={this.props.preferences.fontSize}
|
fontSize={this.props.preferences.fontSize}
|
||||||
indentationAmount={this.props.preferences.indentationAmount}
|
indentationAmount={this.props.preferences.indentationAmount}
|
||||||
|
isTabIndent={this.props.preferences.isTabIndent}
|
||||||
/>
|
/>
|
||||||
<PreviewFrame
|
<PreviewFrame
|
||||||
content={this.props.file.content}
|
content={this.props.file.content}
|
||||||
|
@ -88,7 +92,8 @@ IDEView.propTypes = {
|
||||||
preferences: PropTypes.shape({
|
preferences: PropTypes.shape({
|
||||||
isVisible: PropTypes.bool.isRequired,
|
isVisible: PropTypes.bool.isRequired,
|
||||||
fontSize: PropTypes.number.isRequired,
|
fontSize: PropTypes.number.isRequired,
|
||||||
indentationAmount: PropTypes.number.isRequired
|
indentationAmount: PropTypes.number.isRequired,
|
||||||
|
isTabIndent: PropTypes.bool.isRequired
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
closePreferences: PropTypes.func.isRequired,
|
closePreferences: PropTypes.func.isRequired,
|
||||||
increaseFont: PropTypes.func.isRequired,
|
increaseFont: PropTypes.func.isRequired,
|
||||||
|
@ -97,6 +102,8 @@ IDEView.propTypes = {
|
||||||
increaseIndentation: PropTypes.func.isRequired,
|
increaseIndentation: PropTypes.func.isRequired,
|
||||||
decreaseIndentation: PropTypes.func.isRequired,
|
decreaseIndentation: PropTypes.func.isRequired,
|
||||||
updateIndentation: PropTypes.func.isRequired,
|
updateIndentation: PropTypes.func.isRequired,
|
||||||
|
indentWithSpace: PropTypes.func.isRequired,
|
||||||
|
indentWithTab: PropTypes.func.isRequired,
|
||||||
file: PropTypes.shape({
|
file: PropTypes.shape({
|
||||||
content: PropTypes.string.isRequired
|
content: PropTypes.string.isRequired
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
|
|
|
@ -3,7 +3,8 @@ import * as ActionTypes from '../../../constants';
|
||||||
const initialState = {
|
const initialState = {
|
||||||
isVisible: false,
|
isVisible: false,
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
indentationAmount: 4
|
indentationAmount: 4,
|
||||||
|
isTabIndent: true
|
||||||
};
|
};
|
||||||
|
|
||||||
const preferences = (state = initialState, action) => {
|
const preferences = (state = initialState, action) => {
|
||||||
|
@ -40,6 +41,14 @@ const preferences = (state = initialState, action) => {
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
indentationAmount: action.value
|
indentationAmount: action.value
|
||||||
});
|
});
|
||||||
|
case ActionTypes.INDENT_WITH_TAB:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
isTabIndent: true
|
||||||
|
});
|
||||||
|
case ActionTypes.INDENT_WITH_SPACE:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
isTabIndent: false
|
||||||
|
});
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@
|
||||||
@extend %toolbar-button;
|
@extend %toolbar-button;
|
||||||
color: $light-primary-text-color;
|
color: $light-primary-text-color;
|
||||||
background-color: $light-modal-button-background-color;
|
background-color: $light-modal-button-background-color;
|
||||||
|
padding: 0;
|
||||||
& g {
|
& g {
|
||||||
fill: $light-primary-text-color;
|
fill: $light-primary-text-color;
|
||||||
}
|
}
|
||||||
|
@ -88,3 +89,17 @@
|
||||||
color: $light-primary-text-color;
|
color: $light-primary-text-color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%preference-option {
|
||||||
|
color: $light-secondary-text-color;
|
||||||
|
font-size: #{14 / $base-font-size}rem;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
|
margin-bottom: #{5 / $base-font-size}rem;
|
||||||
|
&:hover {
|
||||||
|
color: $light-primary-text-color;
|
||||||
|
}
|
||||||
|
&--selected {
|
||||||
|
color: $light-primary-text-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -50,3 +50,7 @@ h3 {
|
||||||
h4 {
|
h4 {
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h6 {
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: #{66 / $base-font-size}rem;
|
top: #{66 / $base-font-size}rem;
|
||||||
right: #{40 / $base-font-size}rem;
|
right: #{40 / $base-font-size}rem;
|
||||||
width: #{276 / $base-font-size}rem;
|
width: #{300 / $base-font-size}rem;
|
||||||
background-color: $light-button-background-color;
|
background-color: $light-button-background-color;
|
||||||
display: none;
|
display: none;
|
||||||
padding: #{16 / $base-font-size}rem #{26 / $base-font-size}rem;
|
padding: #{16 / $base-font-size}rem #{26 / $base-font-size}rem;
|
||||||
|
@ -35,8 +35,7 @@
|
||||||
.preference {
|
.preference {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-content: space-between;
|
padding-bottom: #{40 / $base-font-size}rem;
|
||||||
padding-bottom: #{20 / $base-font-size}rem;
|
|
||||||
border-bottom: 2px dashed $light-button-border-color;
|
border-bottom: 2px dashed $light-button-border-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,5 +48,25 @@
|
||||||
border: 1px solid $light-button-border-color;
|
border: 1px solid $light-button-border-color;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
width: #{48 / $base-font-size}rem;
|
width: #{48 / $base-font-size}rem;
|
||||||
|
height: #{48 / $base-font-size}rem;
|
||||||
|
margin: 0 #{20 / $base-font-size}rem;
|
||||||
background-color: $light-button-background-color;
|
background-color: $light-button-background-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.preference__label {
|
||||||
|
margin: 0;
|
||||||
|
line-height: #{20 / $base-font-size}rem;
|
||||||
|
color: $light-button-border-color;
|
||||||
|
&:hover {
|
||||||
|
color: $light-button-border-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.preference__option {
|
||||||
|
@extend %preference-option;
|
||||||
|
list-style-type: none;
|
||||||
|
padding-left: #{12 / $base-font-size}rem;
|
||||||
|
&--selected {
|
||||||
|
@extend %preference-option--selected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue