mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-17 08:34:54 -04:00
feat(settings): add editor settings for indentation
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
3bc9708871
commit
395305dcb7
14 changed files with 852 additions and 15 deletions
|
@ -10,7 +10,9 @@ import type {
|
|||
SetEditorLineWrappingAction,
|
||||
SetEditorSmartPasteAction,
|
||||
SetEditorSyncScrollAction,
|
||||
SetEditorSpellCheckAction
|
||||
SetEditorSpellCheckAction,
|
||||
SetEditorIndentWithTabsAction,
|
||||
SetEditorIndentSpacesAction
|
||||
} from './types'
|
||||
import { EditorConfigActionType } from './types'
|
||||
|
||||
|
@ -54,6 +56,22 @@ export const setEditorSpellCheck = (spellCheck: boolean): void => {
|
|||
store.dispatch(action)
|
||||
}
|
||||
|
||||
export const setEditorIndentWithTabs = (indentWithTabs: boolean): void => {
|
||||
const action: SetEditorIndentWithTabsAction = {
|
||||
type: EditorConfigActionType.SET_INDENT_WITH_TABS,
|
||||
indentWithTabs
|
||||
}
|
||||
store.dispatch(action)
|
||||
}
|
||||
|
||||
export const setEditorIndentSpaces = (indentSpaces: number): void => {
|
||||
const action: SetEditorIndentSpacesAction = {
|
||||
type: EditorConfigActionType.SET_INDENT_SPACES,
|
||||
indentSpaces
|
||||
}
|
||||
store.dispatch(action)
|
||||
}
|
||||
|
||||
export const loadFromLocalStorage = (): void => {
|
||||
const action: LoadFromLocalStorageAction = {
|
||||
type: EditorConfigActionType.LOAD_FROM_LOCAL_STORAGE
|
||||
|
|
|
@ -15,7 +15,9 @@ export const initialState: EditorConfig = {
|
|||
syncScroll: true,
|
||||
smartPaste: true,
|
||||
spellCheck: true,
|
||||
lineWrapping: true
|
||||
lineWrapping: true,
|
||||
indentWithTabs: false,
|
||||
indentSpaces: 2
|
||||
}
|
||||
|
||||
export const EditorConfigReducer: Reducer<EditorConfig, EditorConfigActions> = (
|
||||
|
@ -61,6 +63,20 @@ export const EditorConfigReducer: Reducer<EditorConfig, EditorConfigActions> = (
|
|||
}
|
||||
saveToLocalStorage(newState)
|
||||
return newState
|
||||
case EditorConfigActionType.SET_INDENT_WITH_TABS:
|
||||
newState = {
|
||||
...state,
|
||||
indentWithTabs: action.indentWithTabs
|
||||
}
|
||||
saveToLocalStorage(newState)
|
||||
return newState
|
||||
case EditorConfigActionType.SET_INDENT_SPACES:
|
||||
newState = {
|
||||
...state,
|
||||
indentSpaces: action.indentSpaces
|
||||
}
|
||||
saveToLocalStorage(newState)
|
||||
return newState
|
||||
default:
|
||||
return state
|
||||
}
|
||||
|
@ -72,13 +88,15 @@ export const loadFromLocalStorage = (): EditorConfig | undefined => {
|
|||
if (!stored) {
|
||||
return undefined
|
||||
}
|
||||
const storedConfiguration = JSON.parse(stored) as Record<string, boolean>
|
||||
const storedConfiguration = JSON.parse(stored) as Partial<EditorConfig>
|
||||
return {
|
||||
ligatures: storedConfiguration?.ligatures === true ?? true,
|
||||
syncScroll: storedConfiguration?.syncScroll === true ?? true,
|
||||
smartPaste: storedConfiguration?.smartPaste === true ?? true,
|
||||
spellCheck: storedConfiguration?.spellCheck === true ?? false,
|
||||
lineWrapping: storedConfiguration?.lineWrapping === true ?? true
|
||||
spellCheck: storedConfiguration?.spellCheck === true ?? true,
|
||||
lineWrapping: storedConfiguration?.lineWrapping === true ?? true,
|
||||
indentWithTabs: storedConfiguration?.indentWithTabs === true ?? false,
|
||||
indentSpaces: storedConfiguration?.indentSpaces ?? 2
|
||||
}
|
||||
} catch (_) {
|
||||
return undefined
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
import type { Action } from 'redux'
|
||||
|
||||
export enum EditorConfigActionType {
|
||||
SET_EDITOR_VIEW_MODE = 'editor/view-mode/set',
|
||||
SET_SYNC_SCROLL = 'editor/syncScroll/set',
|
||||
LOAD_FROM_LOCAL_STORAGE = 'editor/preferences/load',
|
||||
SET_LIGATURES = 'editor/preferences/setLigatures',
|
||||
SET_LINE_WRAPPING = 'editor/preferences/setLineWrapping',
|
||||
SET_SMART_PASTE = 'editor/preferences/setSmartPaste',
|
||||
SET_SPELL_CHECK = 'editor/preferences/setSpellCheck'
|
||||
SET_SPELL_CHECK = 'editor/preferences/setSpellCheck',
|
||||
SET_INDENT_WITH_TABS = 'editor/preferences/setIndentWithTabs',
|
||||
SET_INDENT_SPACES = 'editor/preferences/setIndentSpaces'
|
||||
}
|
||||
|
||||
export interface EditorConfig {
|
||||
|
@ -21,6 +22,8 @@ export interface EditorConfig {
|
|||
smartPaste: boolean
|
||||
spellCheck: boolean
|
||||
lineWrapping: boolean
|
||||
indentWithTabs: boolean
|
||||
indentSpaces: number
|
||||
}
|
||||
|
||||
export type EditorConfigActions =
|
||||
|
@ -29,6 +32,8 @@ export type EditorConfigActions =
|
|||
| SetEditorSmartPasteAction
|
||||
| SetEditorLineWrappingAction
|
||||
| SetEditorSpellCheckAction
|
||||
| SetEditorIndentWithTabsAction
|
||||
| SetEditorIndentSpacesAction
|
||||
| LoadFromLocalStorageAction
|
||||
|
||||
export interface LoadFromLocalStorageAction extends Action<EditorConfigActionType> {
|
||||
|
@ -59,3 +64,13 @@ export interface SetEditorSpellCheckAction extends Action<EditorConfigActionType
|
|||
type: EditorConfigActionType.SET_SPELL_CHECK
|
||||
spellCheck: boolean
|
||||
}
|
||||
|
||||
export interface SetEditorIndentWithTabsAction extends Action<EditorConfigActionType> {
|
||||
type: EditorConfigActionType.SET_INDENT_WITH_TABS
|
||||
indentWithTabs: boolean
|
||||
}
|
||||
|
||||
export interface SetEditorIndentSpacesAction extends Action<EditorConfigActionType> {
|
||||
type: EditorConfigActionType.SET_INDENT_SPACES
|
||||
indentSpaces: number
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue