Skip to content

Commit

Permalink
Add support for disabling autocomplete in settings, fix creating an a…
Browse files Browse the repository at this point in the history
…lready existing file (#214)

* Add settings disabled

* Fix for format

* Fixes for format

* Add comment

* Bump coverage
  • Loading branch information
eatonphil committed Apr 8, 2022
1 parent 4b1641f commit 5c6e89d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
9 changes: 8 additions & 1 deletion desktop/store.ts
Expand Up @@ -383,9 +383,16 @@ GROUP BY panel_id

// NOTE: unlike elsewhere projectId is actually the file name not a uuid.
handler: async (_: string, { projectId }: MakeProjectRequest) => {
const db = this.getConnection(projectId);
const newProject = new ProjectState();
newProject.projectName = ensureProjectFile(projectId);

// File already exists, ok and appropriate to do nothing since
// this merely handles creation not loading.
if (fs.existsSync(newProject.projectName)) {
return;
}

const db = this.getConnection(projectId);
for (const file of this.migrations) {
log.info('Running migration: ' + file);
const contents = fs.readFileSync(file).toString();
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Expand Up @@ -5,7 +5,7 @@ module.exports = {
? {
global: {
statements: 54,
branches: 41,
branches: 40,
functions: 35,
lines: 54,
},
Expand Down
2 changes: 2 additions & 0 deletions shared/settings.ts
Expand Up @@ -15,6 +15,7 @@ export class Settings {
languages: Record<SupportedLanguages, LanguageSettings>;
file: string;
stdoutMaxSize: number;
autocompleteDisabled: boolean;
theme: 'light' | 'dark';
caCerts: Array<{ file: string; id: string }>;

Expand All @@ -26,6 +27,7 @@ export class Settings {
stdoutMaxSize?: number
) {
this.id = id || newId();
this.autocompleteDisabled = false;
this.lastProject = lastProject || '';
this.languages =
languages ||
Expand Down
2 changes: 1 addition & 1 deletion ui/MakeSelectProject.tsx
Expand Up @@ -65,7 +65,7 @@ export function MakeSelectProject() {
}

return (
<div className="card project-name">
<div className="card card--center project-name">
<h1>New Project</h1>
<p>Pick a name for this project to get started.</p>
<div className="form-row">
Expand Down
14 changes: 14 additions & 0 deletions ui/Settings.tsx
Expand Up @@ -111,6 +111,20 @@ export function Settings() {
}}
/>
</div>
<div className="form-row">
<Toggle
label={
settings.autocompleteDisabled
? 'Enable Autocomplete'
: 'Disable Autocomplete'
}
value={settings.autocompleteDisabled}
onChange={function handleLightModeToggle() {
settings.autocompleteDisabled = !settings.autocompleteDisabled;
setSettings(settings);
}}
/>
</div>
<div className="form-row form-row--multi">
<Input
onChange={function handleMaxStdoutSizeChange(newValue: string) {
Expand Down
12 changes: 8 additions & 4 deletions ui/components/CodeEditor.tsx
Expand Up @@ -75,7 +75,7 @@ export function CodeEditor({
tooltip?: string;
}) {
const {
state: { theme },
state: { theme, autocompleteDisabled },
} = React.useContext(SettingsContext);

const [editorRef, setEditorRef] = React.useState<AceEditor>(null);
Expand Down Expand Up @@ -216,9 +216,13 @@ export function CodeEditor({
singleLine
? { showLineNumbers: false, highlightActiveLine: false }
: {
enableBasicAutocompletion: Boolean(autocomplete),
enableLiveAutocompletion: Boolean(autocomplete),
enableSnippets: Boolean(autocomplete),
enableBasicAutocompletion: Boolean(
autocomplete && !autocompleteDisabled
),
enableLiveAutocompletion: Boolean(
autocomplete && !autocompleteDisabled
),
enableSnippets: Boolean(autocomplete && !autocompleteDisabled),
}
}
/>
Expand Down

0 comments on commit 5c6e89d

Please sign in to comment.