From f54c0db1a4e3b19f9980ba73739711349e59b9a1 Mon Sep 17 00:00:00 2001 From: Daniel Hoffens Date: Sun, 7 Jul 2024 12:42:46 -0400 Subject: [PATCH] fix: set results col width in settings, solves #98 (#128) * fix: set results col width in settings, solves #98 * add new default setting to constants test --- src/constants.test.ts | 6 ++++-- src/constants.ts | 4 +++- src/main/framework/runtime-events.ts | 8 +++++++- src/renderer/src/runner/runner.tsx | 8 ++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/constants.test.ts b/src/constants.test.ts index a5bf2f8..55afda4 100644 --- a/src/constants.test.ts +++ b/src/constants.test.ts @@ -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', () => { @@ -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 } }) }) diff --git a/src/constants.ts b/src/constants.ts index c2ca49c..ba6c953 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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 = { @@ -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 } } diff --git a/src/main/framework/runtime-events.ts b/src/main/framework/runtime-events.ts index d42186f..4364cd3 100644 --- a/src/main/framework/runtime-events.ts +++ b/src/main/framework/runtime-events.ts @@ -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' @@ -204,6 +205,11 @@ export function attach({ app, workspace }: BootstrapContext): void { ) }) + // TODO: this doesnt do anything + ipcMain.handle('runner.resultColWidth', async (): Promise => { + return workspace.settings.get('runner.resultColWidth', DEFAULT_SETTING_RESULTCOLWIDTH) + }) + ipcMain.handle('runner.theme', async (_, profile): Promise => { const theme = workspace.theme.get(profile) const extensionTheme = await workspace.extensions.run(ExtensionHook.RUNNER_THEME_CSS) diff --git a/src/renderer/src/runner/runner.tsx b/src/renderer/src/runner/runner.tsx index 49dc744..c5f4f45 100644 --- a/src/renderer/src/runner/runner.tsx +++ b/src/renderer/src/runner/runner.tsx @@ -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([]) const [pendingTitles, setPendingTitles] = useState({}) @@ -18,6 +19,7 @@ export default function Runner(): ReactElement { list: [] }) const [suggestionSelection, setSuggestionSelection] = useState(0) + const [resultColWidth, setResultColWidth] = useState('50%') const inputRef = useRef(null) const textAreaRef = useRef(null) @@ -28,10 +30,11 @@ export default function Runner(): ReactElement { const reloadRuntimesFromBackend = async (): Promise => { 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') @@ -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() }) @@ -571,7 +575,7 @@ export default function Runner(): ReactElement { + -
+