cleanup spacing

This commit is contained in:
TC
2026-06-22 17:17:16 +10:00
parent 2472860966
commit 78d3bc2d82
2 changed files with 21 additions and 0 deletions

View File

@@ -137,6 +137,12 @@ function buildAppMenu(win: BrowserWindow): void {
{ type: 'separator' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: 'Clean Up Spacing',
accelerator: 'CmdOrCtrl+Shift+K',
click: () => send(win, 'cleanupSpacing')
},
{ type: 'separator' },
{
label: 'Find / Replace',
accelerator: 'CmdOrCtrl+F',

View File

@@ -139,6 +139,21 @@ export default function App(): JSX.Element {
}
} else if (action === 'exportProjectPDF') {
setExportOpen(true)
} else if (action === 'cleanupSpacing') {
const view = currentEditorView
if (!view) return
const { from, to } = view.state.selection.main
const hasSelection = from !== to
const start = hasSelection ? from : 0
const end = hasSelection ? to : view.state.doc.length
const text = view.state.doc.sliceString(start, end)
const cleaned = text.replace(/\n\n+/g, '\n')
if (cleaned !== text) {
view.dispatch(view.state.update({
changes: { from: start, to: end, insert: cleaned },
userEvent: 'input'
}))
}
}
}