-
-
+
+
+
-
+
)
}
diff --git a/src/components/editor-page/editor-pane/key-map.ts b/src/components/editor-page/editor-pane/key-map.ts
index 423c5df66..9432df858 100644
--- a/src/components/editor-page/editor-pane/key-map.ts
+++ b/src/components/editor-page/editor-pane/key-map.ts
@@ -15,7 +15,7 @@ import {
underlineSelection
} from './tool-bar/utils/toolbarButtonUtils'
-const isVim = (keyMapName?: string) => (keyMapName?.substr(0, 3) === 'vim')
+const isVim = (keyMapName?: string) => keyMapName?.substr(0, 3) === 'vim'
const f10 = (editor: Editor): void | typeof Pass => editor.setOption('fullScreen', !editor.getOption('fullScreen'))
const esc = (editor: Editor): void | typeof Pass => {
@@ -30,8 +30,7 @@ const tab = (editor: Editor) => {
const tab = '\t'
// contruct x length spaces
- const spaces = Array((editor.getOption('indentUnit') ?? 0) + 1)
- .join(' ')
+ const spaces = Array((editor.getOption('indentUnit') ?? 0) + 1).join(' ')
// auto indent whole line when in list or blockquote
const cursor = editor.getCursor()
@@ -44,9 +43,7 @@ const tab = (editor: Editor) => {
const regex = /^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))/
let match
- const multiple = editor.getSelection()
- .split('\n').length > 1 ||
- editor.getSelections().length > 1
+ const multiple = editor.getSelection().split('\n').length > 1 || editor.getSelections().length > 1
if (multiple) {
editor.execCommand('defaultTab')
@@ -72,35 +69,35 @@ const tab = (editor: Editor) => {
export const defaultKeyMap: KeyMap = !isMac
? {
- F9: suppressKey,
- F10: f10,
- Esc: esc,
- 'Ctrl-S': suppressKey,
- Enter: 'newlineAndIndentContinueMarkdownList',
- Tab: tab,
- Home: 'goLineLeftSmart',
- End: 'goLineRight',
- 'Ctrl-I': makeSelectionItalic,
- 'Ctrl-B': makeSelectionBold,
- 'Ctrl-U': underlineSelection,
- 'Ctrl-D': strikeThroughSelection,
- 'Ctrl-M': markSelection,
- 'Ctrl-K': addLink
- }
+ F9: suppressKey,
+ F10: f10,
+ Esc: esc,
+ 'Ctrl-S': suppressKey,
+ Enter: 'newlineAndIndentContinueMarkdownList',
+ Tab: tab,
+ Home: 'goLineLeftSmart',
+ End: 'goLineRight',
+ 'Ctrl-I': makeSelectionItalic,
+ 'Ctrl-B': makeSelectionBold,
+ 'Ctrl-U': underlineSelection,
+ 'Ctrl-D': strikeThroughSelection,
+ 'Ctrl-M': markSelection,
+ 'Ctrl-K': addLink
+ }
: {
- F9: suppressKey,
- F10: f10,
- Esc: esc,
- 'Cmd-S': suppressKey,
- Enter: 'newlineAndIndentContinueMarkdownList',
- Tab: tab,
- 'Cmd-Left': 'goLineLeftSmart',
- 'Cmd-Right': 'goLineRight',
- Home: 'goLineLeftSmart',
- End: 'goLineRight',
- 'Cmd-I': makeSelectionItalic,
- 'Cmd-B': makeSelectionBold,
- 'Cmd-U': underlineSelection,
- 'Cmd-D': strikeThroughSelection,
- 'Cmd-M': markSelection
- }
+ F9: suppressKey,
+ F10: f10,
+ Esc: esc,
+ 'Cmd-S': suppressKey,
+ Enter: 'newlineAndIndentContinueMarkdownList',
+ Tab: tab,
+ 'Cmd-Left': 'goLineLeftSmart',
+ 'Cmd-Right': 'goLineRight',
+ Home: 'goLineLeftSmart',
+ End: 'goLineRight',
+ 'Cmd-I': makeSelectionItalic,
+ 'Cmd-B': makeSelectionBold,
+ 'Cmd-U': underlineSelection,
+ 'Cmd-D': strikeThroughSelection,
+ 'Cmd-M': markSelection
+ }
diff --git a/src/components/editor-page/editor-pane/status-bar/status-bar.tsx b/src/components/editor-page/editor-pane/status-bar/status-bar.tsx
index 0b1f6ac41..dbfd83a6b 100644
--- a/src/components/editor-page/editor-pane/status-bar/status-bar.tsx
+++ b/src/components/editor-page/editor-pane/status-bar/status-bar.tsx
@@ -34,11 +34,17 @@ export const createStatusInfo = (editor: Editor, maxDocumentLength: number): Sta
remainingCharacters: maxDocumentLength - editor.getValue().length,
linesInDocument: editor.lineCount(),
selectedColumns: editor.getSelection().length,
- selectedLines: editor.getSelection()
- .split('\n').length
+ selectedLines: editor.getSelection().split('\n').length
})
-export const StatusBar: React.FC
= ({ position, selectedColumns, selectedLines, charactersInDocument, linesInDocument, remainingCharacters }) => {
+export const StatusBar: React.FC = ({
+ position,
+ selectedColumns,
+ selectedLines,
+ charactersInDocument,
+ linesInDocument,
+ remainingCharacters
+}) => {
const { t } = useTranslation()
const getLengthTooltip = useMemo(() => {
@@ -52,27 +58,26 @@ export const StatusBar: React.FC = ({ position, selectedColumns,
}, [remainingCharacters, t])
return (
-
+
- { t('editor.statusBar.cursor', { line: position.line + 1, columns: position.ch + 1 }) }
-
-
- – { t('editor.statusBar.selection.column', { count: selectedColumns }) }
+ {t('editor.statusBar.cursor', { line: position.line + 1, columns: position.ch + 1 })}
+
+
+ – {t('editor.statusBar.selection.column', { count: selectedColumns })}
- 1 }>
- – { t('editor.statusBar.selection.line', { count: selectedLines }) }
+ 1}>
+ – {t('editor.statusBar.selection.line', { count: selectedLines })}
-
-
{ t('editor.statusBar.lines', { lines: linesInDocument }) }
+
+ {t('editor.statusBar.lines', { lines: linesInDocument })}
–
- { t('editor.statusBar.length', { length: charactersInDocument }) }
+ data-cy={'remainingCharacters'}
+ title={getLengthTooltip}
+ className={remainingCharacters <= 0 ? 'text-danger' : remainingCharacters <= 100 ? 'text-warning' : ''}>
+ {t('editor.statusBar.length', { length: charactersInDocument })}
diff --git a/src/components/editor-page/editor-pane/table-extractor.test.ts b/src/components/editor-page/editor-pane/table-extractor.test.ts
index f19383986..2c758c47f 100644
--- a/src/components/editor-page/editor-pane/table-extractor.test.ts
+++ b/src/components/editor-page/editor-pane/table-extractor.test.ts
@@ -7,90 +7,83 @@
import { convertClipboardTableToMarkdown, isTable } from './table-extractor'
describe('isTable detection: ', () => {
-
it('empty string is no table', () => {
- expect(isTable(''))
- .toBe(false)
+ expect(isTable('')).toBe(false)
})
it('single line is no table', () => {
const input = 'some none table'
- expect(isTable(input))
- .toBe(false)
+ expect(isTable(input)).toBe(false)
})
it('multiple lines without tabs are no table', () => {
const input = 'some none table\nanother line'
- expect(isTable(input))
- .toBe(false)
+ expect(isTable(input)).toBe(false)
})
it('code blocks are no table', () => {
const input = '```python\ndef a:\n\tprint("a")\n\tprint("b")```'
- expect(isTable(input))
- .toBe(false)
+ expect(isTable(input)).toBe(false)
})
it('tab-indented text is no table', () => {
const input = '\tsome tab indented text\n\tabc\n\tdef'
- expect(isTable(input))
- .toBe(false)
+ expect(isTable(input)).toBe(false)
})
it('not equal number of tabs is no table', () => {
const input = '1 ...\n2\tabc\n3\td\te\tf\n4\t16'
- expect(isTable(input))
- .toBe(false)
+ expect(isTable(input)).toBe(false)
})
it('table without newline at end is valid', () => {
const input = '1\t1\n2\t4\n3\t9\n4\t16\n5\t25'
- expect(isTable(input))
- .toBe(true)
+ expect(isTable(input)).toBe(true)
})
it('table with newline at end is valid', () => {
const input = '1\t1\n2\t4\n3\t9\n4\t16\n5\t25\n'
- expect(isTable(input))
- .toBe(true)
+ expect(isTable(input)).toBe(true)
})
it('table with some first cells missing is valid', () => {
const input = '1\t1\n\t0\n\t0\n4\t16\n5\t25\n'
- expect(isTable(input))
- .toBe(true)
+ expect(isTable(input)).toBe(true)
})
it('table with some last cells missing is valid', () => {
const input = '1\t1\n2\t\n3\t\n4\t16\n'
- expect(isTable(input))
- .toBe(true)
+ expect(isTable(input)).toBe(true)
})
})
describe('Conversion from clipboard table to markdown format', () => {
it('normal table without newline at end converts right', () => {
const input = '1\t1\ta\n2\t4\tb\n3\t9\tc\n4\t16\td'
- expect(convertClipboardTableToMarkdown(input))
- .toEqual('| #1 | #2 | #3 |\n| -- | -- | -- |\n| 1 | 1 | a |\n| 2 | 4 | b |\n| 3 | 9 | c |\n| 4 | 16 | d |')
+ expect(convertClipboardTableToMarkdown(input)).toEqual(
+ '| #1 | #2 | #3 |\n| -- | -- | -- |\n| 1 | 1 | a |\n| 2 | 4 | b |\n| 3 | 9 | c |\n| 4 | 16 | d |'
+ )
})
it('normal table with newline at end converts right', () => {
const input = '1\t1\n2\t4\n3\t9\n4\t16\n'
- expect(convertClipboardTableToMarkdown(input))
- .toEqual('| #1 | #2 |\n| -- | -- |\n| 1 | 1 |\n| 2 | 4 |\n| 3 | 9 |\n| 4 | 16 |')
+ expect(convertClipboardTableToMarkdown(input)).toEqual(
+ '| #1 | #2 |\n| -- | -- |\n| 1 | 1 |\n| 2 | 4 |\n| 3 | 9 |\n| 4 | 16 |'
+ )
})
it('table with some first cells missing converts right', () => {
const input = '1\t1\n\t0\n\t0\n4\t16\n'
- expect(convertClipboardTableToMarkdown(input))
- .toEqual('| #1 | #2 |\n| -- | -- |\n| 1 | 1 |\n| | 0 |\n| | 0 |\n| 4 | 16 |')
+ expect(convertClipboardTableToMarkdown(input)).toEqual(
+ '| #1 | #2 |\n| -- | -- |\n| 1 | 1 |\n| | 0 |\n| | 0 |\n| 4 | 16 |'
+ )
})
it('table with some last cells missing converts right', () => {
const input = '1\t1\n2\t\n3\t\n4\t16\n'
- expect(convertClipboardTableToMarkdown(input))
- .toEqual('| #1 | #2 |\n| -- | -- |\n| 1 | 1 |\n| 2 | |\n| 3 | |\n| 4 | 16 |')
+ expect(convertClipboardTableToMarkdown(input)).toEqual(
+ '| #1 | #2 |\n| -- | -- |\n| 1 | 1 |\n| 2 | |\n| 3 | |\n| 4 | 16 |'
+ )
})
it('empty input results in empty output', () => {
diff --git a/src/components/editor-page/editor-pane/table-extractor.ts b/src/components/editor-page/editor-pane/table-extractor.ts
index 12d9cbcd7..f118f9b00 100644
--- a/src/components/editor-page/editor-pane/table-extractor.ts
+++ b/src/components/editor-page/editor-pane/table-extractor.ts
@@ -16,43 +16,35 @@ export const isTable = (text: string): boolean => {
return false
}
- const lines = text.split(/\r?\n/)
- .filter(line => line.trim() !== '')
+ const lines = text.split(/\r?\n/).filter((line) => line.trim() !== '')
// Tab-indented text should not be matched as a table
- if (lines.every(line => line.startsWith('\t'))) {
+ if (lines.every((line) => line.startsWith('\t'))) {
return false
}
// Every line should have the same amount of tabs (table columns)
- const tabsPerLines = lines.map(line => line.match(/\t/g)?.length ?? 0)
- return tabsPerLines.every(line => line === tabsPerLines[0])
+ const tabsPerLines = lines.map((line) => line.match(/\t/g)?.length ?? 0)
+ return tabsPerLines.every((line) => line === tabsPerLines[0])
}
export const convertClipboardTableToMarkdown = (pasteData: string): string => {
if (pasteData.trim() === '') {
return ''
}
- const tableRows = pasteData.split(/\r?\n/)
- .filter(row => row.trim() !== '')
+ const tableRows = pasteData.split(/\r?\n/).filter((row) => row.trim() !== '')
const tableCells = tableRows.reduce((cellsInRow, row, index) => {
cellsInRow[index] = row.split('\t')
return cellsInRow
}, [] as string[][])
const arrayMaxRows = createNumberRangeArray(tableCells.length)
- const arrayMaxColumns = createNumberRangeArray(Math.max(...tableCells.map(row => row.length)))
+ const arrayMaxColumns = createNumberRangeArray(Math.max(...tableCells.map((row) => row.length)))
- const headRow1 = arrayMaxColumns
- .map(col => `| #${ col + 1 } `)
- .join('') + '|'
- const headRow2 = arrayMaxColumns
- .map(col => `| -${ '-'.repeat((col + 1).toString().length) } `)
- .join('') + '|'
+ const headRow1 = arrayMaxColumns.map((col) => `| #${col + 1} `).join('') + '|'
+ const headRow2 = arrayMaxColumns.map((col) => `| -${'-'.repeat((col + 1).toString().length)} `).join('') + '|'
const body = arrayMaxRows
- .map(row => {
- return arrayMaxColumns
- .map(col => '| ' + tableCells[row][col] + ' ')
- .join('') + '|'
+ .map((row) => {
+ return arrayMaxColumns.map((col) => '| ' + tableCells[row][col] + ' ').join('') + '|'
})
.join('\n')
- return `${ headRow1 }\n${ headRow2 }\n${ body }`
+ return `${headRow1}\n${headRow2}\n${body}`
}
diff --git a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-boolean-property.tsx b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-boolean-property.tsx
index e3e5710a4..ee3809857 100644
--- a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-boolean-property.tsx
+++ b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-boolean-property.tsx
@@ -19,28 +19,33 @@ export interface EditorPreferenceBooleanProps {
}
export const EditorPreferenceBooleanProperty: React.FC
= ({ property }) => {
- const preference = useSelector((state: ApplicationState) => state.editorConfig.preferences[property]?.toString() || '', equal)
+ const preference = useSelector(
+ (state: ApplicationState) => state.editorConfig.preferences[property]?.toString() || '',
+ equal
+ )
const { t } = useTranslation()
- const selectItem = useCallback((event: ChangeEvent) => {
- const selectedItem: boolean = event.target.value === 'true'
+ const selectItem = useCallback(
+ (event: ChangeEvent) => {
+ const selectedItem: boolean = event.target.value === 'true'
- mergeEditorPreferences({
- [property]: selectedItem
- } as EditorConfiguration)
- }, [property])
+ mergeEditorPreferences({
+ [property]: selectedItem
+ } as EditorConfiguration)
+ },
+ [property]
+ )
- const i18nPrefix = `editor.modal.preferences.${ property }`
+ const i18nPrefix = `editor.modal.preferences.${property}`
return (
-
-
-
+
+
+
)
}
diff --git a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-input.tsx b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-input.tsx
index 1260557d2..54fcbbab5 100644
--- a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-input.tsx
+++ b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-input.tsx
@@ -20,21 +20,28 @@ export interface EditorPreferenceInputProps {
value?: string | number | string[]
}
-export const EditorPreferenceInput: React.FC = ({ property, type, onChange, value, children }) => {
+export const EditorPreferenceInput: React.FC = ({
+ property,
+ type,
+ onChange,
+ value,
+ children
+}) => {
useTranslation()
return (
-
+
+ i18nKey={`editor.modal.preferences.${property}${type === EditorPreferenceInputType.NUMBER ? '' : '.label'}`}
+ />
- { children }
+ value={value}
+ onChange={onChange}
+ type={type === EditorPreferenceInputType.NUMBER ? 'number' : ''}>
+ {children}
)
diff --git a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-ligatures-select.tsx b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-ligatures-select.tsx
index 98d6c90fa..d1afd7101 100644
--- a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-ligatures-select.tsx
+++ b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-ligatures-select.tsx
@@ -11,8 +11,7 @@ import { setEditorLigatures } from '../../../../../redux/editor/methods'
import { EditorPreferenceInput, EditorPreferenceInputType } from './editor-preference-input'
export const EditorPreferenceLigaturesSelect: React.FC = () => {
- const ligaturesEnabled = useSelector((state: ApplicationState) => Boolean(state.editorConfig.ligatures)
- .toString())
+ const ligaturesEnabled = useSelector((state: ApplicationState) => Boolean(state.editorConfig.ligatures).toString())
const saveLigatures = useCallback((event: ChangeEvent) => {
const ligaturesActivated: boolean = event.target.value === 'true'
setEditorLigatures(ligaturesActivated)
@@ -20,10 +19,13 @@ export const EditorPreferenceLigaturesSelect: React.FC = () => {
const { t } = useTranslation()
return (
-
-
-
+
+
+
)
}
diff --git a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-number-property.tsx b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-number-property.tsx
index fedb3cbd8..71e831e01 100644
--- a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-number-property.tsx
+++ b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-number-property.tsx
@@ -18,18 +18,28 @@ export interface EditorPreferenceNumberProps {
}
export const EditorPreferenceNumberProperty: React.FC = ({ property }) => {
- const preference = useSelector((state: ApplicationState) => state.editorConfig.preferences[property]?.toString() || '', equal)
+ const preference = useSelector(
+ (state: ApplicationState) => state.editorConfig.preferences[property]?.toString() || '',
+ equal
+ )
- const selectItem = useCallback((event: ChangeEvent) => {
- const selectedItem: number = Number.parseInt(event.target.value)
+ const selectItem = useCallback(
+ (event: ChangeEvent) => {
+ const selectedItem: number = Number.parseInt(event.target.value)
- mergeEditorPreferences({
- [property]: selectedItem
- } as EditorConfiguration)
- }, [property])
+ mergeEditorPreferences({
+ [property]: selectedItem
+ } as EditorConfiguration)
+ },
+ [property]
+ )
return (
-
+
)
}
diff --git a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-select-property.tsx b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-select-property.tsx
index 432e28ee9..089bbd17e 100644
--- a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-select-property.tsx
+++ b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-select-property.tsx
@@ -19,28 +19,41 @@ export interface EditorPreferenceSelectPropertyProps {
selections: string[]
}
-export const EditorPreferenceSelectProperty: React.FC = ({ property, selections }) => {
- const preference = useSelector((state: ApplicationState) => state.editorConfig.preferences[property]?.toString() || '', equal)
+export const EditorPreferenceSelectProperty: React.FC = ({
+ property,
+ selections
+}) => {
+ const preference = useSelector(
+ (state: ApplicationState) => state.editorConfig.preferences[property]?.toString() || '',
+ equal
+ )
const { t } = useTranslation()
- const selectItem = useCallback((event: ChangeEvent) => {
- const selectedItem: string = event.target.value
+ const selectItem = useCallback(
+ (event: ChangeEvent) => {
+ const selectedItem: string = event.target.value
- mergeEditorPreferences({
- [property]: selectedItem
- } as EditorConfiguration)
- }, [property])
+ mergeEditorPreferences({
+ [property]: selectedItem
+ } as EditorConfiguration)
+ },
+ [property]
+ )
- const i18nPrefix = `editor.modal.preferences.${ property }`
+ const i18nPrefix = `editor.modal.preferences.${property}`
return (
-
- { selections.map(selection =>
- ) }
+
+ {selections.map((selection) => (
+
+ ))}
)
}
diff --git a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-smart-paste-select.tsx b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-smart-paste-select.tsx
index 3dbe04de3..450156189 100644
--- a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-smart-paste-select.tsx
+++ b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preference-smart-paste-select.tsx
@@ -11,8 +11,7 @@ import { setEditorSmartPaste } from '../../../../../redux/editor/methods'
import { EditorPreferenceInput, EditorPreferenceInputType } from './editor-preference-input'
export const EditorPreferenceSmartPasteSelect: React.FC = () => {
- const smartPasteEnabled = useSelector((state: ApplicationState) => Boolean(state.editorConfig.smartPaste)
- .toString())
+ const smartPasteEnabled = useSelector((state: ApplicationState) => Boolean(state.editorConfig.smartPaste).toString())
const saveSmartPaste = useCallback((event: ChangeEvent) => {
const smartPasteActivated: boolean = event.target.value === 'true'
setEditorSmartPaste(smartPasteActivated)
@@ -21,13 +20,12 @@ export const EditorPreferenceSmartPasteSelect: React.FC = () => {
return (
-
-
+ onChange={saveSmartPaste}
+ value={smartPasteEnabled}
+ property={'smartPaste'}
+ type={EditorPreferenceInputType.BOOLEAN}>
+
+
)
}
diff --git a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preferences.tsx b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preferences.tsx
index e92869615..ca98eedbd 100644
--- a/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preferences.tsx
+++ b/src/components/editor-page/editor-pane/tool-bar/editor-preferences/editor-preferences.tsx
@@ -24,47 +24,55 @@ import { EditorPreferenceSmartPasteSelect } from './editor-preference-smart-past
export const EditorPreferences: React.FC = () => {
const { t } = useTranslation()
const [showModal, setShowModal] = useState(false)
- const indentWithTabs = useSelector((state: ApplicationState) => state.editorConfig.preferences.indentWithTabs ?? false, equal)
+ const indentWithTabs = useSelector(
+ (state: ApplicationState) => state.editorConfig.preferences.indentWithTabs ?? false,
+ equal
+ )
return (
-