From dc3ca1183d9a925e58d3846e38ff186062e8c518 Mon Sep 17 00:00:00 2001 From: yaya-usman Date: Tue, 12 Apr 2022 15:29:30 +0300 Subject: [PATCH] more code refactoring --- src/editor/operations.ts | 1 + test/editor/operations-test.ts | 16 ---------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/editor/operations.ts b/src/editor/operations.ts index 69384a07efc..40a438cc562 100644 --- a/src/editor/operations.ts +++ b/src/editor/operations.ts @@ -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; } diff --git a/test/editor/operations-test.ts b/test/editor/operations-test.ts index e7793cc9272..a728e150bd3 100644 --- a/test/editor/operations-test.ts +++ b/test/editor/operations-test.ts @@ -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', () => {