mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
Allow to choose space as a indentation character (#1177)
This commit is contained in:
parent
9413481b2e
commit
48dd56fe2b
@ -11,6 +11,7 @@ type BaseSettings = {
|
|||||||
editorIndentSize: number,
|
editorIndentSize: number,
|
||||||
editorLineWrapping: boolean,
|
editorLineWrapping: boolean,
|
||||||
editorKeyMap: string,
|
editorKeyMap: string,
|
||||||
|
editorIndentWithTabs: boolean,
|
||||||
httpProxy: string,
|
httpProxy: string,
|
||||||
httpsProxy: string,
|
httpsProxy: string,
|
||||||
noProxy: string,
|
noProxy: string,
|
||||||
@ -45,6 +46,7 @@ export function init(): BaseSettings {
|
|||||||
editorIndentSize: 2,
|
editorIndentSize: 2,
|
||||||
editorLineWrapping: true,
|
editorLineWrapping: true,
|
||||||
editorKeyMap: 'default',
|
editorKeyMap: 'default',
|
||||||
|
editorIndentWithTabs: true,
|
||||||
httpProxy: '',
|
httpProxy: '',
|
||||||
httpsProxy: '',
|
httpsProxy: '',
|
||||||
noProxy: '',
|
noProxy: '',
|
||||||
|
@ -288,7 +288,7 @@ class CodeEditor extends React.Component {
|
|||||||
if (!this.codeMirror.getOption('indentWithTabs')) {
|
if (!this.codeMirror.getOption('indentWithTabs')) {
|
||||||
this.codeMirror.setOption('extraKeys', {
|
this.codeMirror.setOption('extraKeys', {
|
||||||
Tab: cm => {
|
Tab: cm => {
|
||||||
const spaces = new Array(this.codeMirror.getOption('indentUnit') + 1).join(' ');
|
const spaces = this._indentChars();
|
||||||
cm.replaceSelection(spaces);
|
cm.replaceSelection(spaces);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -353,6 +353,10 @@ class CodeEditor extends React.Component {
|
|||||||
return mode.indexOf('xml') !== -1;
|
return mode.indexOf('xml') !== -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_indentChars() {
|
||||||
|
return this.codeMirror.getOption('indentWithTabs') ? '\t' : new Array(this.codeMirror.getOption('indentUnit') + 1).join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
_handleBeautify() {
|
_handleBeautify() {
|
||||||
this._prettify(this.codeMirror.getValue());
|
this._prettify(this.codeMirror.getValue());
|
||||||
}
|
}
|
||||||
@ -375,7 +379,7 @@ class CodeEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return prettify.json(jsonString, '\t', this.props.autoPrettify);
|
return prettify.json(jsonString, this._indentChars(), this.props.autoPrettify);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// That's Ok, just leave it
|
// That's Ok, just leave it
|
||||||
return code;
|
return code;
|
||||||
@ -394,7 +398,7 @@ class CodeEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return vkBeautify.xml(code, '\t');
|
return vkBeautify.xml(code, this._indentChars());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Failed to parse so just return original
|
// Failed to parse so just return original
|
||||||
return code;
|
return code;
|
||||||
@ -422,6 +426,7 @@ class CodeEditor extends React.Component {
|
|||||||
noStyleActiveLine,
|
noStyleActiveLine,
|
||||||
noLint,
|
noLint,
|
||||||
indentSize,
|
indentSize,
|
||||||
|
indentWithTabs,
|
||||||
dynamicHeight,
|
dynamicHeight,
|
||||||
hintOptions,
|
hintOptions,
|
||||||
infoOptions,
|
infoOptions,
|
||||||
@ -448,6 +453,7 @@ class CodeEditor extends React.Component {
|
|||||||
lineNumbers: !hideGutters && !hideLineNumbers,
|
lineNumbers: !hideGutters && !hideLineNumbers,
|
||||||
foldGutter: !hideGutters && !hideLineNumbers,
|
foldGutter: !hideGutters && !hideLineNumbers,
|
||||||
lineWrapping: lineWrapping,
|
lineWrapping: lineWrapping,
|
||||||
|
indentWithTabs: indentWithTabs,
|
||||||
matchBrackets: !noMatchBrackets,
|
matchBrackets: !noMatchBrackets,
|
||||||
lint: !noLint && !readOnly,
|
lint: !noLint && !readOnly,
|
||||||
gutters: []
|
gutters: []
|
||||||
|
@ -182,6 +182,7 @@ class BodyEditor extends React.PureComponent<Props> {
|
|||||||
indentSize={settings.editorIndentSize}
|
indentSize={settings.editorIndentSize}
|
||||||
keyMap={settings.editorKeyMap}
|
keyMap={settings.editorKeyMap}
|
||||||
lineWrapping={settings.editorLineWrapping}
|
lineWrapping={settings.editorLineWrapping}
|
||||||
|
indentWithTabs={settings.editorIndentWithTabs}
|
||||||
contentType={contentType || 'text/plain'}
|
contentType={contentType || 'text/plain'}
|
||||||
content={request.body.text || ''}
|
content={request.body.text || ''}
|
||||||
render={handleRender}
|
render={handleRender}
|
||||||
|
@ -15,6 +15,7 @@ class RawEditor extends PureComponent {
|
|||||||
indentSize,
|
indentSize,
|
||||||
keyMap,
|
keyMap,
|
||||||
lineWrapping,
|
lineWrapping,
|
||||||
|
indentWithTabs,
|
||||||
nunjucksPowerUserMode,
|
nunjucksPowerUserMode,
|
||||||
onChange,
|
onChange,
|
||||||
render,
|
render,
|
||||||
@ -27,6 +28,7 @@ class RawEditor extends PureComponent {
|
|||||||
uniquenessKey={uniquenessKey}
|
uniquenessKey={uniquenessKey}
|
||||||
fontSize={fontSize}
|
fontSize={fontSize}
|
||||||
indentSize={indentSize}
|
indentSize={indentSize}
|
||||||
|
indentWithTabs={indentWithTabs}
|
||||||
keyMap={keyMap}
|
keyMap={keyMap}
|
||||||
defaultValue={content}
|
defaultValue={content}
|
||||||
className={className}
|
className={className}
|
||||||
@ -57,7 +59,8 @@ RawEditor.propTypes = {
|
|||||||
// Optional
|
// Optional
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
render: PropTypes.func,
|
render: PropTypes.func,
|
||||||
getRenderContext: PropTypes.func
|
getRenderContext: PropTypes.func,
|
||||||
|
indentWithTabs: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
||||||
export default RawEditor;
|
export default RawEditor;
|
||||||
|
@ -144,6 +144,18 @@ class General extends React.PureComponent<Props> {
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="form-control form-control--thin">
|
||||||
|
<label className="inline-block">
|
||||||
|
Indent With Tabs
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="editorIndentWithTabs"
|
||||||
|
checked={settings.editorIndentWithTabs}
|
||||||
|
onChange={this._handleUpdateSetting}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="form-control form-control--outlined pad-top-sm">
|
<div className="form-control form-control--outlined pad-top-sm">
|
||||||
<label>
|
<label>
|
||||||
Environment Highlight Color Style{' '}
|
Environment Highlight Color Style{' '}
|
||||||
|
Loading…
Reference in New Issue
Block a user