Skip to content

Commit

Permalink
feat: Add option to not use new lines under threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitcheljager committed Feb 11, 2024
1 parent 8692443 commit acb8a00
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/javascript/src/components/editor/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@
// Add apply values when selecting autocomplete, filling in default args
const lowercaseDefaults = Object.keys(defaults).map(k => k.toLowerCase())
const useParameterObject = $settings["autocomplete-parameter-objects"] && params.args_length >= $settings["autocomplete-min-parameter-size"]
const useNewlines = params.args_length >= $settings["autocomplete-min-parameter-newlines"]
const apply = v.args.map(a => {
let string = a.default?.toString().toLowerCase().replaceAll(",", "")
if (useParameterObject) string = `\n\t${ a.name }: ${ string }`
if (useParameterObject) string = `${ useNewlines ? "\n\t" : "" }${ a.name }: ${ string }`
if (lowercaseDefaults.includes(string)) return defaults[toCapitalize(string)]
Expand All @@ -102,7 +104,9 @@
params.parameter_defaults = apply
params.apply = useParameterObject ?
`${ v["en-US"] }({ ${ apply.join(", ") }\n})` :
useNewlines ?
`${ v["en-US"] }({ ${ apply.join(",") }\n})` :
`${ v["en-US"] }({ ${ apply.join(", ") } })` :
`${ v["en-US"] }(${ apply.join(", ") })`
// Add arguments to info box
Expand Down
13 changes: 13 additions & 0 deletions app/javascript/src/components/editor/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@
Only autocomplete when an action or value has equal or more than this value in parameters.
</div>
</div>

<div class="form-group mt-1/8 tooltip" transition:slide|local={{ duration: 100 }}>
<label for="" class="text-base nowrap">Minimum newline length</label>

<div class="flex align-center">
<input type="range" min=1 max=20 step=1 class="range mr-1/8" bind:value={$settings["autocomplete-min-parameter-newlines"]} />
{$settings["autocomplete-min-parameter-newlines"]}
</div>

<div class="tooltip__content bg-darker">
Place each parameter on a new line when the action or value has equal or more than this value in parameters.
</div>
</div>
{/if}

<hr />
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/src/stores/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,6 @@ export const settings = writable({
"show-indent-markers": true,
"word-wrap": false,
"autocomplete-parameter-objects": false,
"autocomplete-min-parameter-size": 2
"autocomplete-min-parameter-size": 2,
"autocomplete-min-parameter-newlines": 2
})

0 comments on commit acb8a00

Please sign in to comment.