Skip to content

Commit

Permalink
Abstracted indenting to match existing text.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglev committed Aug 29, 2022
1 parent ae6fae5 commit 4e0e4f8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,19 @@ export default class PastetoIndentationPlugin extends Plugin {

const leadingWhitespaceMatch = editor
.getLine(editor.getCursor().line)
.match(new RegExp(`^(\\s*)([-\\*]\\s)?`));
.match(new RegExp(`^(\\s*)(.*)?`));
const leadingWhitespace =
leadingWhitespaceMatch !== null ? leadingWhitespaceMatch[1] : "";

// The length of `- ` / `* `, to accomodate a bullet list:
const additionalLeadingWhitespace =
leadingWhitespaceMatch !== null &&
leadingWhitespaceMatch[2] !== undefined
? " "
? " ".repeat(
leadingWhitespaceMatch[2].length > 3
? 3
: leadingWhitespaceMatch[2].length
)
: "";

if (
Expand Down

0 comments on commit 4e0e4f8

Please sign in to comment.