✨ cleanup spacing
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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'
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user