From 11ec632ddf4fe261cebc46f9109750d1672e0125 Mon Sep 17 00:00:00 2001 From: Caleb Figgers Date: Sat, 4 May 2024 19:40:04 -0500 Subject: [PATCH] Insert a pagebreak with `ctrl/cmd + enter` outside of list contexts --- src/listEditing.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/listEditing.ts b/src/listEditing.ts index 81d1f36..34f4606 100644 --- a/src/listEditing.ts +++ b/src/listEditing.ts @@ -136,6 +136,8 @@ function onEnterKey(modifiers?: IModifier) { editor.selection = new Selection(newCursorPos, newCursorPos); } }).then(() => { editor.revealRange(editor.selection) }); + + // Ordered list item before cursor } else if ((matches = /^(\s*)([0-9]+)([.)])( +)((\[[ x]\] +)?)/.exec(textBeforeCursor)) !== null) { // Ordered list let config = workspace.getConfiguration('typst-companion.extension.orderedList').get('marker'); @@ -166,7 +168,17 @@ function onEnterKey(modifiers?: IModifier) { } }).then(() => fixMarker(editor)).then(() => { editor.revealRange(editor.selection); }); } else { - return asNormal(editor, 'enter', modifiers); + if (modifiers == 'ctrl') { + return editor.edit( + editBuilder => { + editBuilder.insert(line.range.end, '#pagebreak()\n'); + } + ).then(() => { + editor.revealRange(editor.selection); + }); + } else { + return asNormal(editor, 'enter', modifiers); + } } }