mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-03 01:18:32 +00:00
Compare commits
3 Commits
dependabot
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c58e007b3 | ||
|
|
3dc84f46e5 | ||
|
|
884fa77bac |
@@ -13,6 +13,7 @@ import * as jsonlint from '@prantlf/jsonlint';
|
||||
import { JSHINT } from 'jshint';
|
||||
import stripJsonComments from 'strip-json-comments';
|
||||
import { getAllVariables } from 'utils/collections';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
let CodeMirror;
|
||||
const SERVER_RENDERED = typeof window === 'undefined' || global['PREVENT_CODEMIRROR_RENDER'] === true;
|
||||
@@ -117,7 +118,7 @@ if (!SERVER_RENDERED) {
|
||||
};
|
||||
}
|
||||
|
||||
export default class CodeEditor extends React.Component {
|
||||
class CodeEditor extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
@@ -142,7 +143,7 @@ export default class CodeEditor extends React.Component {
|
||||
lineWrapping: true,
|
||||
tabSize: TAB_SIZE,
|
||||
mode: this.props.mode || 'application/ld+json',
|
||||
keyMap: 'sublime',
|
||||
keyMap: this.props.editorPrefs?.keymap || 'sublime',
|
||||
autoCloseBrackets: true,
|
||||
matchBrackets: true,
|
||||
showCursorWhenSelecting: true,
|
||||
@@ -424,3 +425,7 @@ export default class CodeEditor extends React.Component {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({ editorPrefs: state.app?.preferences?.editor });
|
||||
|
||||
export default connect(mapStateToProps)(CodeEditor);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import styled from 'styled-components';
|
||||
|
||||
const StyledWrapper = styled.div`
|
||||
color: ${(props) => props.theme.text};
|
||||
`;
|
||||
|
||||
export default StyledWrapper;
|
||||
@@ -0,0 +1,56 @@
|
||||
import React, { useState } from 'react';
|
||||
import get from 'lodash/get';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { savePreferences } from 'providers/ReduxStore/slices/app';
|
||||
import StyledWrapper from './StyledWrapper';
|
||||
|
||||
// https://codemirror.net/5/keymap/
|
||||
const codemirrorKeymaps = [
|
||||
{ value: 'sublime', label: 'Sublime' },
|
||||
{ value: 'vim', label: 'Vim' },
|
||||
{ value: 'emacs', label: 'Emacs' },
|
||||
];
|
||||
|
||||
const EditorKeymapSettings = ({ close }) => {
|
||||
const dispatch = useDispatch();
|
||||
const preferences = useSelector((state) => state.app.preferences);
|
||||
const editorPreferences = preferences.editor || {};
|
||||
const keymap = editorPreferences.keymap || 'sublime';
|
||||
|
||||
const handleKeymapChange = (e) => {
|
||||
dispatch(
|
||||
savePreferences({
|
||||
...preferences,
|
||||
editor: { ...editorPreferences, keymap: e.target.value }
|
||||
})
|
||||
).catch(console.error);
|
||||
};
|
||||
|
||||
return (
|
||||
<StyledWrapper>
|
||||
<div className="bruno-form">
|
||||
<label className="block">Keymap</label>
|
||||
<div className="flex items-center mt-2">
|
||||
{codemirrorKeymaps.map(({ value, label }) => (
|
||||
<>
|
||||
<input
|
||||
id={label}
|
||||
className="cursor-pointer ml-4 first:ml-0"
|
||||
type="radio"
|
||||
name="keymap"
|
||||
onChange={handleKeymapChange}
|
||||
value={value}
|
||||
checked={keymap === value}
|
||||
/>
|
||||
<label htmlFor={label} className="ml-1 cursor-pointer select-none">
|
||||
{label}
|
||||
</label>
|
||||
</>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</StyledWrapper>
|
||||
);
|
||||
};
|
||||
|
||||
export default EditorKeymapSettings;
|
||||
@@ -37,9 +37,9 @@ const Font = ({ close }) => {
|
||||
|
||||
return (
|
||||
<StyledWrapper>
|
||||
<div className="flex flex-row gap-2 w-full">
|
||||
<div className="flex flex-row gap-2 w-fit">
|
||||
<div className="w-4/5">
|
||||
<label className="block">Code Editor Font</label>
|
||||
<label className="block">Font Family</label>
|
||||
<input
|
||||
type="text"
|
||||
className="block textbox mt-2 w-full"
|
||||
@@ -63,10 +63,7 @@ const Font = ({ close }) => {
|
||||
defaultValue={codeFontSize}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-10">
|
||||
<button type="submit" className="submit btn btn-sm btn-secondary" onClick={handleSave}>
|
||||
<button type="submit" className="submit btn btn-md btn-secondary self-end" onClick={handleSave}>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
import React from 'react';
|
||||
import Font from './Font/index';
|
||||
import Theme from './Theme/index';
|
||||
import EditorKeymapSettings from './EditorKeymapSettings/index';
|
||||
|
||||
const Display = ({ close }) => {
|
||||
return (
|
||||
<div className="flex flex-col my-2 gap-10 w-full">
|
||||
<div className='w-full flex flex-col gap-2'>
|
||||
<span>
|
||||
<span className="font-semibold">
|
||||
Theme
|
||||
</span>
|
||||
<Theme close={close} />
|
||||
</div>
|
||||
<div className='h-[1px] bg-[#aaa5] w-full'></div>
|
||||
<div className='w-fit flex flex-col gap-2'>
|
||||
<div className='w-full flex flex-col gap-2'>
|
||||
<span className="font-semibold">
|
||||
Code Editor
|
||||
</span>
|
||||
<EditorKeymapSettings />
|
||||
<div className='w-full'></div>
|
||||
<Font close={close} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -33,6 +33,8 @@ if (!SERVER_RENDERED) {
|
||||
require('codemirror/addon/search/searchcursor');
|
||||
require('codemirror/addon/display/placeholder');
|
||||
require('codemirror/keymap/sublime');
|
||||
require('codemirror/keymap/vim');
|
||||
require('codemirror/keymap/emacs');
|
||||
|
||||
require('codemirror-graphql/hint');
|
||||
require('codemirror-graphql/info');
|
||||
|
||||
@@ -97,6 +97,7 @@ export const {
|
||||
updateSystemProxyEnvVariables
|
||||
} = appSlice.actions;
|
||||
|
||||
// TODO: Need a equivalent method which allows setting preferences for individual sub-section
|
||||
export const savePreferences = (preferences) => (dispatch, getState) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { ipcRenderer } = window;
|
||||
|
||||
@@ -58,6 +58,9 @@ const preferencesSchema = Yup.object().shape({
|
||||
codeFont: Yup.string().nullable(),
|
||||
codeFontSize: Yup.number().min(1).max(32).nullable()
|
||||
}),
|
||||
editor: Yup.object().shape({
|
||||
keymap: Yup.string().oneOf(['sublime', 'vim', 'emacs']).nullable(),
|
||||
}),
|
||||
proxy: Yup.object({
|
||||
mode: Yup.string().oneOf(['off', 'on', 'system']),
|
||||
protocol: Yup.string().oneOf(['http', 'https', 'socks4', 'socks5']),
|
||||
|
||||
Reference in New Issue
Block a user