Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
updated backtick logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yaya-usman committed Mar 30, 2022
1 parent cfd5157 commit 83202af
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/editor/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,13 @@ export function formatRangeAsCode(range: Range): void {
const hasBlockFormatting = (range.length > 0)
&& range.text.startsWith("```")
&& range.text.endsWith("```");
const hasBacktick = (range.text.includes("`"))
&& !range.text.startsWith("`")
&& !range.text.endsWith("`");

const hasBacktick = (range.text.includes("`"));
const needsBlockFormatting = parts.some(p => p.type === Type.Newline);

if (hasBlockFormatting) {
// Remove previously pushed backticks and new lines
parts.shift();
parts.pop();
if (parts[0]?.text === "\n" && parts[parts.length - 1]?.text === "\n") {
Expand Down Expand Up @@ -247,6 +248,7 @@ export function toggleInlineFormat(range: Range, prefix: string, suffix = prefix
// compute paragraph [start, end] indexes
const paragraphIndexes = [];
let startIndex = 0;

// start at i=2 because we look at i and up to two parts behind to detect paragraph breaks at their end
for (let i = 2; i < parts.length; i++) {
// paragraph breaks can be denoted in a multitude of ways,
Expand Down

0 comments on commit 83202af

Please sign in to comment.