Skip to content

Commit f47b19d

Browse files
committed
fix(commands): remove new lines command improve: add spaces
1 parent c712149 commit f47b19d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
joinAsSentences_Map, joinViaCommas_Attach, joinViaSpaces_Attach,
1818
joinViaNewLines_Attach, joinViaNewLines_Map,
1919

20-
splitByLines, splitBySentences, splitByWords,
20+
splitByLines, splitBySentences, splitByWords, removeNewLinesCommand,
2121
} from './commands'
2222
import { improveCursorMovement_KeyDownListener, improveSearch_KeyDownListener } from './features'
2323
import { getChosenBlocks, p, scrollToBlock } from './utils'
@@ -218,7 +218,7 @@ async function main() {
218218
label: ICON + ' Remove new lines', key: 'mc-6-update-1-remove-new-lines',
219219
// @ts-expect-error
220220
keybinding: {},
221-
}, (e) => updateBlocksCommand((content, level, block, parent) => content.replaceAll('\n', '')))
221+
}, (e) => removeNewLinesCommand())
222222

223223

224224
// Navigation

src/commands.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,3 +908,12 @@ export async function updateBlocksCommand(
908908
await logseq.Editor.exitEditingMode()
909909
}
910910
}
911+
912+
export function removeNewLinesCommand() {
913+
return updateBlocksCommand((content, level, block, parent) => {
914+
return content
915+
.replaceAll(/\n+/g, '\n')
916+
.replaceAll(/(?<=[^\S\n])\n/g, '') // remove \n when there are spaces before
917+
.replaceAll(/(?<![^\S])\n/g, ' ') // replace \n to space when there are no spaces before
918+
})
919+
}

0 commit comments

Comments
 (0)