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

Commit

Permalink
more code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
yaya-usman committed Apr 14, 2022
1 parent 86b1353 commit dc3ca11
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 16 deletions.
1 change: 1 addition & 0 deletions src/editor/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export function formatRangeAsCode(range: Range): void {
} else {
const fenceLen = longestBacktickSequence(range.text);
const hasInlineFormatting = range.text.startsWith("`") && range.text.endsWith("`");
//if it's already formatted untoggle based on fenceLen which returns the max. num of backtick within a text else increase the fence backticks with a factor of 1.
toggleInlineFormat(range, "`".repeat(hasInlineFormatting ? fenceLen : fenceLen + 1));
return;
}
Expand Down
16 changes: 0 additions & 16 deletions test/editor/operations-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,6 @@ describe('editor/operations: formatting operations', () => {
formatRangeAsCode(range);
expect(model.serializeParts()).toEqual([{ "text": "````hell```o`w`o``rld````", "type": "plain" }]);
});

it('escapes backticks in between text and untoggles already formated code text', () => {
const renderer = createRenderer();
const pc = createPartCreator();
const model = new EditorModel([
pc.plain("`hello`world`"),
], pc, renderer);

const range = model.startRange(model.positionForOffset(0, false),
model.getPositionAtEnd()); // `hello`world`
expect(range.parts[0].text.includes("`")).toBeTruthy();
expect(longestBacktickSequence(range.parts[0].text)).toBe(1);
expect(model.serializeParts()).toEqual([{ "text": "`hello`world`", "type": "plain" }]);
formatRangeAsCode(range);
expect(model.serializeParts()).toEqual([{ "text": "hello`world", "type": "plain" }]);
});
});

it('works for parts of words', () => {
Expand Down

0 comments on commit dc3ca11

Please sign in to comment.