Skip to content

Commit

Permalink
fix: set results col width in settings, solves #98 (#128)
Browse files Browse the repository at this point in the history
* fix: set results col width in settings, solves #98

* add new default setting to constants test
  • Loading branch information
dhoffens committed Jul 7, 2024
1 parent aabc215 commit f54c0db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
DEFAULT_SETTING_IS_COMMANDER_MODE,
DEFAULT_SETTING_COMMANDER_MODE_BOUNDS,
DEFAULT_SETTING_RUNNER_BOUNDS,
DEFAULT_SETTINGS
DEFAULT_SETTINGS,
DEFAULT_SETTING_RESULTCOLWIDTH
} from './constants'

describe('constants', () => {
Expand Down Expand Up @@ -111,7 +112,8 @@ describe('constants', () => {
bounds: DEFAULT_SETTING_RUNNER_BOUNDS,
commanderModeShortcut: DEFAULT_SETTING_COMMANDER_MODE_TOGGLE_SHORTCUT,
commanderMode: DEFAULT_SETTING_IS_COMMANDER_MODE,
commanderModeBounds: DEFAULT_SETTING_COMMANDER_MODE_BOUNDS
commanderModeBounds: DEFAULT_SETTING_COMMANDER_MODE_BOUNDS,
resultColWidth: DEFAULT_SETTING_RESULTCOLWIDTH
}
})
})
Expand Down
4 changes: 3 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const DEFAULT_HISTORY_ENABLED = true
export const DEFAULT_HISTORY_MAX_ITEMS = 1000
export const DEFAULT_HISTORY_SAVE_RESULT = true
export const DEFAULT_SETTING_RUNNER_SHORTCUT = '`+CommandOrControl'
export const DEFAULT_SETTING_RESULTCOLWIDTH = '50%'
export const DEFAULT_SETTING_COMMANDER_MODE_TOGGLE_SHORTCUT = '`+Shift+CommandOrControl'
export const DEFAULT_SETTING_IS_COMMANDER_MODE = false
export const DEFAULT_SETTING_COMMANDER_MODE_BOUNDS = {
Expand Down Expand Up @@ -61,6 +62,7 @@ export const DEFAULT_SETTINGS = {
bounds: DEFAULT_SETTING_RUNNER_BOUNDS,
commanderModeShortcut: DEFAULT_SETTING_COMMANDER_MODE_TOGGLE_SHORTCUT,
commanderMode: DEFAULT_SETTING_IS_COMMANDER_MODE,
commanderModeBounds: DEFAULT_SETTING_COMMANDER_MODE_BOUNDS
commanderModeBounds: DEFAULT_SETTING_COMMANDER_MODE_BOUNDS,
resultColWidth: DEFAULT_SETTING_RESULTCOLWIDTH
}
}
8 changes: 7 additions & 1 deletion src/main/framework/runtime-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
DEFAULT_HISTORY_SAVE_RESULT,
DEFAULT_PROFILE,
DEFAULT_PROFILES,
DEFAULT_SETTING_IS_COMMANDER_MODE
DEFAULT_SETTING_IS_COMMANDER_MODE,
DEFAULT_SETTING_RESULTCOLWIDTH
} from '../../constants'
import { HistoricalExecution } from './history'
import { writeFile } from 'fs-extra'
Expand Down Expand Up @@ -204,6 +205,11 @@ export function attach({ app, workspace }: BootstrapContext): void {
)
})

// TODO: this doesnt do anything
ipcMain.handle('runner.resultColWidth', async (): Promise<string> => {
return workspace.settings.get<string>('runner.resultColWidth', DEFAULT_SETTING_RESULTCOLWIDTH)
})

ipcMain.handle('runner.theme', async (_, profile): Promise<string> => {
const theme = workspace.theme.get(profile)
const extensionTheme = await workspace.extensions.run(ExtensionHook.RUNNER_THEME_CSS)
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/src/runner/runner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { hyperLink } from '@uiw/codemirror-extensions-hyper-link'
import { javascript } from '@codemirror/lang-javascript'
import RunnerAC from './runner-ac'
import { Suggestion } from './autocomplete'

export default function Runner(): ReactElement {
const [runtimeList, setRuntimes] = useState<Runtime[]>([])
const [pendingTitles, setPendingTitles] = useState<object>({})
Expand All @@ -18,6 +19,7 @@ export default function Runner(): ReactElement {
list: []
})
const [suggestionSelection, setSuggestionSelection] = useState<number>(0)
const [resultColWidth, setResultColWidth] = useState<string>('50%')

const inputRef = useRef<HTMLInputElement>(null)
const textAreaRef = useRef<HTMLTextAreaElement>(null)
Expand All @@ -28,10 +30,11 @@ export default function Runner(): ReactElement {

const reloadRuntimesFromBackend = async (): Promise<void> => {
const isCommanderMode = await window.electron.ipcRenderer.invoke('runner.isCommanderMode')
const getResultColWidth = await window.electron.ipcRenderer.invoke('runner.resultColWidth')
const runtimesFetch: Runtime[] = await window.electron.ipcRenderer.invoke('runtimes')

setRuntimes(runtimesFetch)
setCommanderMode(isCommanderMode)
setResultColWidth(getResultColWidth)
}

window.electron.ipcRenderer.removeAllListeners('runtime.commandEvent')
Expand Down Expand Up @@ -355,6 +358,7 @@ export default function Runner(): ReactElement {
}
const onEditFileKeyDown = (runtimeId: string, commandId: string, e): void => {
if (e.code === 'KeyS' && e.ctrlKey) {
// this happens when we save settings.json
window.electron.ipcRenderer.invoke('runtime.save-edit', runtimeId, commandId).then(() => {
return reloadRuntimesFromBackend()
})
Expand Down Expand Up @@ -571,7 +575,7 @@ export default function Runner(): ReactElement {
+
</div>
</div>
<div className="runner-main">
<div className="runner-main" style={{ gridTemplateColumns: `1fr ${resultColWidth}` }}>
<div className="runner-input-container">
<div className="runner-input">
<div className={isMultiLine ? 'multiline-input-container' : ''}>
Expand Down

0 comments on commit f54c0db

Please sign in to comment.