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', () => {