From 2e1533c1d8176a93ce46ce9ecacbaa71554df954 Mon Sep 17 00:00:00 2001 From: yaya-usman Date: Fri, 1 Apr 2022 01:57:45 +0300 Subject: [PATCH] escaping backticks on formatting test-update --- test/editor/operations-test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/editor/operations-test.js b/test/editor/operations-test.js index 1db566084051..fedd539959de 100644 --- a/test/editor/operations-test.js +++ b/test/editor/operations-test.js @@ -23,6 +23,7 @@ import { formatRange, } from "../../src/editor/operations"; import { Formatting } from "../../src/components/views/rooms/MessageComposerFormatBar"; +import { longestBacktickSequence } from '../../src/editor/deserialize'; const SERIALIZED_NEWLINE = { "text": "\n", "type": "newline" }; @@ -44,6 +45,23 @@ describe('editor/operations: formatting operations', () => { expect(model.serializeParts()).toEqual([{ "text": "hello _world_!", "type": "plain" }]); }); + it('works for escaping backticks in between texts', () => { + 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.positionForOffset(13, false)); // hello ` world + + expect(range.parts[0].text.trim().includes("`")).toBeTruthy(); + expect(longestBacktickSequence(range.parts[0].text.trim())).toBe(1); + expect(model.serializeParts()).toEqual([{ "text": "hello ` world!", "type": "plain" }]); + toggleInlineFormat(range, "`".repeat(longestBacktickSequence(range.parts[0].text.trim()) + 1)); + expect(model.serializeParts()).toEqual([{ "text": "``hello ` world``!", "type": "plain" }]); + }); + it('works for parts of words', () => { const renderer = createRenderer(); const pc = createPartCreator();