A platform for community discussion. Free, open, simple.
FEATURE: Add a small text option to the composer text sizes toolbar button (#42020)
chapoia76d4bb135ed
diff --git a/app/assets/stylesheets/common/toolbar-popup-menu-options.scss b/app/assets/stylesheets/common/toolbar-popup-menu-options.scssindex 3d03b0bf4bf..8c2cb1f0738 100644--- a/app/assets/stylesheets/common/toolbar-popup-menu-options.scss+++ b/app/assets/stylesheets/common/toolbar-popup-menu-options.scss@@ -191,5 +191,12 @@font-size: var(--font-down-1-rem);}}++ .btn[data-name="heading-small"] {+ .d-button-label__text,+ .d-icon {+ font-size: var(--font-down-2-rem);+ }+ }}}diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 0a7c035354a..244c68d98eb 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -3532,11 +3532,14 @@ en:italic_label: "I"italic_title: "Emphasis"italic_text: "emphasized text"- heading_title: "Headings"+ text_size_title: "Text sizes"heading_level_n: "Heading %{levelNumber}"heading_level_n_title: "Heading %{levelNumber}"heading_level_paragraph: "Paragraph"heading_level_paragraph_title: "Paragraph"+ heading_level_small: "Small"+ heading_level_small_title: "Small text"+ heading_level_small_text: "Small text"link_title: "Link"link_description: "enter link description here"link_dialog_title: "Insert link"diff --git a/frontend/discourse/app/lib/composer/text-manipulation.ts b/frontend/discourse/app/lib/composer/text-manipulation.tsindex ef77ec34f44..abb3bf04988 100644--- a/frontend/discourse/app/lib/composer/text-manipulation.ts+++ b/frontend/discourse/app/lib/composer/text-manipulation.ts@@ -28,6 +28,8 @@ export interface ToolbarState {inHeadingLevel?: number;/** Whether the selection is inside a paragraph. */inParagraph?: boolean;+ /** Whether the selection has small text formatting. */+ inSmall?: boolean;}export interface SelectedText {@@ -77,6 +79,8 @@ export interface SurroundOptions {applyEmptyLines?: boolean;/** Leave the leading marker outside the restored selection. */excludeHeadInSelection?: boolean;+ /** Expand the selection to whole lines before applying. */+ wholeLine?: boolean;}export interface AddTextOptions {diff --git a/frontend/discourse/app/lib/composer/toolbar.ts b/frontend/discourse/app/lib/composer/toolbar.tsindex 7f4a0526a8c..bba9a7e7507 100644--- a/frontend/discourse/app/lib/composer/toolbar.ts+++ b/frontend/discourse/app/lib/composer/toolbar.ts@@ -373,11 +373,15 @@ export default class Toolbar extends ToolbarBase {id: "heading",group: "fontStyles",active: ({ state }) => {- if (!state || !state.inHeading) {+ if (!state) {return false;}- if (state.inHeadingLevel > 4) {+ if (state.inSmall) {+ return true;+ }++ if (!state.inHeading || state.inHeadingLevel > 4) {return false;}@@ -394,7 +398,7 @@ export default class Toolbar extends ToolbarBase {return `discourse-h${state.inHeadingLevel}`;},- title: "composer.heading_title",+ title: "composer.text_size_title",popupMenu: {options: () => {const headingOptions = [];@@ -434,9 +438,28 @@ export default class Toolbar extends ToolbarBase {condition: true,showActiveIcon: true,shortcut: "Alt+0",- active: ({ state }) => state?.inParagraph,+ active: ({ state }) => state?.inParagraph && !state?.inSmall,action: (toolbarEvent) => toolbarEvent.applyHeading(0, "heading"),});+ headingOptions.push({+ name: "heading-small",+ icon: "discourse-text",+ label: "composer.heading_level_small",+ title: "composer.heading_level_small_title",+ shortcut: "Alt+5",+ condition: true,+ showActiveIcon: true,+ active: ({ state }) => state?.inSmall,+ action: (toolbarEvent) =>+ toolbarEvent.commands?.toggleSmall+ ? toolbarEvent.commands.toggleSmall()+ : toolbarEvent.applySurround(+ "<small>",+ "</small>",+ "heading_level_small_text",+ { multiline: true, wholeLine: true }+ ),+ });return headingOptions;},},diff --git a/frontend/discourse/app/lib/textarea-text-manipulation.ts b/frontend/discourse/app/lib/textarea-text-manipulation.tsindex 2e2e5a745de..89ff95cb449 100644--- a/frontend/discourse/app/lib/textarea-text-manipulation.ts+++ b/frontend/discourse/app/lib/textarea-text-manipulation.ts@@ -296,6 +296,10 @@ export default class TextareaTextManipulation implements TextManipulation {exampleKey: string,opts?: SurroundOptions): void {+ if (opts?.wholeLine) {+ sel = this.#expandToLines(sel);+ }+const pre = sel.pre;const post = sel.post;@@ -309,6 +313,8 @@ export default class TextareaTextManipulation implements TextManipulation {const example = i18n(`composer.${exampleKey}`);this._insertAt(sel.start, sel.end, `${hval}${example}${tail}`);this.selectText(pre.length + hlen, example.length);+ } else if (opts?.wholeLine) {+ this.#applyWholeLineSurround(sel, head, tail, opts);} else if (opts && !opts.multiline) {let [hval, hlen] = getHead(head);@@ -359,6 +365,74 @@ export default class TextareaTextManipulation implements TextManipulation {}}+ #applyWholeLineSurround(+ sel: SelectedText,+ head: string | ((previous?: string) => string),+ tail: string,+ opts: SurroundOptions+ ): void {+ const [hval, hlen] = getHead(head);+ const lines = sel.value.split("\n");+ const formattedLines = lines.filter(+ (line) => opts.applyEmptyLines || line.length > 0+ );+ const removing =+ formattedLines.length > 0 &&+ formattedLines.every(+ (line) => line.startsWith(hval) && line.endsWith(tail)+ );++ const contents = lines+ .map((line) => {+ if (!opts.applyEmptyLines && line.length === 0) {+ return line;+ }+ if (removing) {+ return line.slice(hlen, tail.length ? -tail.length : undefined);+ }+ let content = line;+ if (hval) {+ content = content.replaceAll(hval, "");+ }+ if (tail) {+ content = content.replaceAll(tail, "");+ }+ return `${hval}${content}${tail}`;+ })+ .join("\n");++ this._insertAt(sel.start, sel.end, contents);++ if (lines.length === 1) {+ this.selectText(+ sel.start + (removing ? 0 : hlen),+ removing ? contents.length : contents.length - hlen - tail.length+ );+ } else {+ this.selectText(sel.start, contents.length);+ }+ }++ #expandToLines(sel: SelectedText): SelectedText {+ const value = this.value;+ const start = value.lastIndexOf("\n", sel.start - 1) + 1;+ const endAnchor =+ sel.end > sel.start && value[sel.end - 1] === "\n"+ ? sel.end - 1+ : sel.end;+ const nextNewline = value.indexOf("\n", endAnchor);+ const end = nextNewline === -1 ? value.length : nextNewline;++ return {+ start,+ end,+ value: value.slice(start, end),+ pre: value.slice(0, start),+ post: value.slice(end),+ lineVal: value.slice(start, end),+ };+ }+// perform the same operation over many lines of text_getMultilineContents(lines: string[],diff --git a/frontend/discourse/app/static/prosemirror/extensions/html-inline.js b/frontend/discourse/app/static/prosemirror/extensions/html-inline.jsindex 07fe83b1476..2e35cddf3b1 100644--- a/frontend/discourse/app/static/prosemirror/extensions/html-inline.js+++ b/frontend/discourse/app/static/prosemirror/extensions/html-inline.js@@ -1,3 +1,7 @@+import { Fragment } from "prosemirror-model";+import { TextSelection } from "prosemirror-state";+import { i18n } from "discourse-i18n";+const HTML_INLINE_MARKS = {s: "strikethrough",strike: "strikethrough",@@ -62,6 +66,168 @@ function serializeHtmlAttrs(htmlAttrs) {const ALL_ALLOWED_TAGS = [...Object.keys(HTML_INLINE_MARKS), ...ALLOWED_INLINE];+const SMALL = "small";++function isSmall(node, schema) {+ return node.type === schema.nodes.html_inline && node.attrs.tag === SMALL;+}++function withoutSmall(fragment, schema) {+ const nodes = [];+ fragment.forEach((child) => {+ const content = child.content.size+ ? withoutSmall(child.content, schema)+ : [];++ if (isSmall(child, schema)) {+ nodes.push(...content);+ } else if (child.content.size) {+ nodes.push(child.copy(Fragment.fromArray(content)));+ } else {+ nodes.push(child);+ }+ });+ return nodes;+}++function splitTrailingWhitespace(content) {+ const main = [...content];+ const lastNode = main.at(-1);+ const trailingWhitespace = lastNode?.isText+ ? lastNode.text.match(/\s+$/)?.[0]+ : null;++ if (!trailingWhitespace) {+ return [main, []];+ }++ main.pop();+ const boundary = lastNode.nodeSize - trailingWhitespace.length;+ if (boundary > 0) {+ main.push(lastNode.cut(0, boundary));+ }++ return [main, [lastNode.cut(boundary)]];+}++/**+ * Small is offered as a text size alongside the heading levels, so it applies to+ * whole lines rather than to the selected range.+ */+function selectedLines(state) {+ const { from, to, empty, $from } = state.selection;+ const lines = [];++ if (empty) {+ for (let depth = $from.depth; depth > 0; depth--) {+ const node = $from.node(depth);+ if (node.isTextblock && !node.type.spec.code) {+ lines.push({ node, pos: $from.before(depth) });+ return lines;+ }+ }+ }++ state.doc.nodesBetween(from, to, (node, pos) => {+ if (node.isTextblock) {+ if (!node.type.spec.code) {+ lines.push({ node, pos });+ }+ return false;+ }+ });++ return lines;+}++function selectedSmallRanges(state, schema) {+ const { from, to, empty, $from } = state.selection;++ if (empty) {+ for (let depth = 1; depth <= $from.depth; depth++) {+ const node = $from.node(depth);+ if (isSmall(node, schema)) {+ return [+ {+ node,+ from: $from.before(depth),+ to: $from.after(depth),+ },+ ];+ }+ }+ return [];+ }++ const ranges = [];+ let hasContent = false;+ let allSmall = true;++ state.doc.nodesBetween(from, to, (node, pos) => {+ if (node.isBlock) {+ return true;+ }+ if (isSmall(node, schema)) {+ hasContent = true;+ ranges.push({ node, from: pos, to: pos + node.nodeSize });+ return false;+ }+ if (node.isText && !node.text.trim()) {+ return false;+ }+ hasContent = true;+ allSmall = false;+ return false;+ });++ return hasContent && allSmall ? ranges : [];+}++function containsSmall(node, schema) {+ let found = false;+ node.descendants((child) => {+ if (isSmall(child, schema)) {+ found = true;+ }+ return !found;+ });+ return found;+}++function replaceLines(state, lines, replacement, schema) {+ const tr = state.tr;++ for (const { node, pos } of lines) {+ const mappedPos = tr.mapping.map(pos);++ if (schema && node.type === schema.nodes.heading) {+ tr.setNodeMarkup(mappedPos, schema.nodes.paragraph, {});+ }++ tr.replaceWith(+ tr.mapping.map(pos + 1),+ tr.mapping.map(pos + node.nodeSize - 1),+ replacement(node)+ );+ }++ return tr;+}++function unwrapSmallRanges(state, ranges, schema) {+ const tr = state.tr;++ for (const { node, from, to } of ranges) {+ tr.replaceWith(+ tr.mapping.map(from),+ tr.mapping.map(to),+ withoutSmall(node.content, schema)+ );+ }++ return tr;+}+/** @type {RichEditorExtension} */const extension = {nodeSpec: {@@ -223,6 +389,103 @@ const extension = {return tr;},},+ commands: ({ schema }) => ({+ toggleSmall: () => (state, dispatch) => {+ const smallRanges = selectedSmallRanges(state, schema);++ if (smallRanges.length) {+ dispatch?.(unwrapSmallRanges(state, smallRanges, schema));+ return true;+ }++ const lines = selectedLines(state).filter(+ ({ node }) => node.content.size > 0+ );++ if (!lines.length && state.selection.empty) {+ const [{ node, pos } = {}] = selectedLines(state);+ if (!node) {+ return false;+ }++ const text = i18n("composer.heading_level_small_text");+ const tr = state.tr;+ if (node.type === schema.nodes.heading) {+ tr.setNodeMarkup(pos, schema.nodes.paragraph, {});+ }+ tr.replaceWith(+ pos + 1,+ pos + 1,+ schema.nodes.html_inline.create({ tag: SMALL }, schema.text(text))+ );+ tr.setSelection(+ TextSelection.create(tr.doc, pos + 2, pos + 2 + text.length)+ );+ dispatch?.(tr);+ return true;+ }++ if (!lines.length) {+ return false;+ }++ const tr = replaceLines(+ state,+ lines,+ (node) => {+ const [content, trailing] = splitTrailingWhitespace(+ withoutSmall(node.content, schema)+ );+ return Fragment.fromArray([+ schema.nodes.html_inline.create({ tag: SMALL }, content),+ ...trailing,+ ]);+ },+ schema+ );++ // Keep the caret inside the wrapper, so the option reports itself as+ // active and toggles back off without needing a new selection. Absorbing+ // an inner wrapper shortens the line, hence the clamp.+ if (state.selection.empty) {+ const contentStart = tr.mapping.map(lines[0].pos) + 2;+ const wrapper = tr.doc.nodeAt(contentStart - 1);++ if (wrapper) {+ tr.setSelection(+ TextSelection.create(+ tr.doc,+ Math.min(+ state.selection.from + 1,+ contentStart + wrapper.content.size+ )+ )+ );+ }+ }++ dispatch?.(tr);+ return true;+ },++ removeSmall: () => (state, dispatch) => {+ const lines = selectedLines(state).filter(({ node }) =>+ containsSmall(node, schema)+ );++ if (!lines.length) {+ return false;+ }++ dispatch?.(+ replaceLines(state, lines, (node) => withoutSmall(node.content, schema))+ );+ return true;+ },+ }),+ state: ({ schema }, state) => ({+ inSmall: selectedSmallRanges(state, schema).length > 0,+ }),};export default extension;diff --git a/frontend/discourse/app/static/prosemirror/lib/text-manipulation.ts b/frontend/discourse/app/static/prosemirror/lib/text-manipulation.tsindex 8b8d72531f9..dbf1d0c10cc 100644--- a/frontend/discourse/app/static/prosemirror/lib/text-manipulation.ts+++ b/frontend/discourse/app/static/prosemirror/lib/text-manipulation.ts@@ -388,6 +388,8 @@ export default class ProsemirrorTextManipulation implements TextManipulation {}applyHeading(_selection: SelectedText, level: number): void {+ this.commands.removeSmall?.();+let command;if (level === 0) {command = setBlockType(this.schema.nodes.paragraph);diff --git a/frontend/discourse/tests/integration/ui-kit/d-editor-test.gjs b/frontend/discourse/tests/integration/ui-kit/d-editor-test.gjsindex 2e49ba85ca2..41452155094 100644--- a/frontend/discourse/tests/integration/ui-kit/d-editor-test.gjs+++ b/frontend/discourse/tests/integration/ui-kit/d-editor-test.gjs@@ -11,6 +11,7 @@ import {triggerEvent,triggerKeyEvent,} from "@ember/test-helpers";+import { AllSelection, TextSelection } from "prosemirror-state";import { module, test } from "qunit";import DMenus from "discourse/float-kit/components/d-menus";import { ToolbarBase } from "discourse/lib/composer/toolbar";@@ -781,6 +782,115 @@ third line`});+ testCase("small button with no selection", async function (assert, textarea) {+ this.set("value", "");+ textarea.selectionStart = 0;+ textarea.selectionEnd = 0;++ await click("button.heading");+ await click('.btn[data-name="heading-small"]');++ assert.strictEqual(+ this.value,+ "<small>Small text</small>",+ "it adds a placeholder and selects it"+ );+ assert.strictEqual(textarea.selectionStart, 7);+ assert.strictEqual(textarea.selectionEnd, 17);+ });++ testCase("small button with a selection", async function (assert, textarea) {+ this.set("value", "Before\nHello world\nAfter");+ textarea.selectionStart = 13;+ textarea.selectionEnd = 18;++ await click("button.heading");+ await click('.btn[data-name="heading-small"]');++ assert.strictEqual(+ this.value,+ "Before\n<small>Hello world</small>\nAfter",+ "it wraps the whole line and reselects its text"+ );+ assert.strictEqual(textarea.selectionStart, 14);+ assert.strictEqual(textarea.selectionEnd, 25);+ });++ testCase(+ "small button with a selection already wrapped",+ async function (assert, textarea) {+ this.set("value", "<small>Hello world</small>");+ textarea.selectionStart = 7;+ textarea.selectionEnd = 18;++ await click("button.heading");+ await click('.btn[data-name="heading-small"]');++ assert.strictEqual(this.value, "Hello world", "it unwraps the selection");+ assert.strictEqual(textarea.selectionStart, 0);+ assert.strictEqual(textarea.selectionEnd, 11);+ }+ );++ testCase(+ "small button with the cursor in a non-empty line",+ async function (assert, textarea) {+ this.set("value", "Before\nHello world\nAfter");+ textarea.selectionStart = 12;+ textarea.selectionEnd = 12;++ await click("button.heading");+ await click('.btn[data-name="heading-small"]');++ assert.strictEqual(+ this.value,+ "Before\n<small>Hello world</small>\nAfter",+ "it wraps the whole line"+ );+ }+ );++ testCase(+ "small button with a multi-line selection",+ async function (assert, textarea) {+ this.set("value", "First\nSecond\nThird");+ textarea.selectionStart = 2;+ textarea.selectionEnd = 13;++ await click("button.heading");+ await click('.btn[data-name="heading-small"]');++ assert.strictEqual(+ this.value,+ "<small>First</small>\n<small>Second</small>\nThird",+ "it wraps every selected line without dropping content"+ );+ }+ );++ testCase(+ "small button normalizes inline small text in a line",+ async function (assert, textarea) {+ this.set("value", "Before <small>small</small> after");+ textarea.selectionStart = 2;+ textarea.selectionEnd = 2;++ await click("button.heading");+ await click('.btn[data-name="heading-small"]');++ assert.strictEqual(+ this.value,+ "<small>Before small after</small>",+ "it produces one whole-line wrapper"+ );+ assert.deepEqual(+ [textarea.selectionStart, textarea.selectionEnd],+ [7, 25],+ "it selects the normalized line content"+ );+ }+ );+test("clicking the toggle-direction changes dir from ltr to rtl and back", async function (assert) {this.siteSettings.support_mixed_text_direction = true;this.siteSettings.default_locale = "en";@@ -1483,6 +1593,31 @@ third line`module("Integration | ui-kit | DEditor | Rich Editor", function (hooks) {setupRenderingTest(hooks);+ async function setupRichEditor(context, value) {+ context.set("value", value);+ context.onSetup = (textManipulation) => {+ context.textManipulation = textManipulation;+ };++ await render(+ <template>+ <DEditor @value={{context.value}} @onSetup={{context.onSetup}} />+ </template>+ );+ await click(".composer-toggle-switch");++ return context.textManipulation.view;+ }++ function selectAll(view) {+ view.dispatch(view.state.tr.setSelection(new AllSelection(view.state.doc)));+ }++ async function toggleSmall() {+ await click("button.heading");+ await click('.btn[data-name="heading-small"]');+ }+test("hides preview when rich editor is enabled", async function (assert) {await render(<template><DEditor /></template>);await click(".composer-toggle-switch");@@ -1520,4 +1655,164 @@ module("Integration | ui-kit | DEditor | Rich Editor", function (hooks) {assert.dom(".ProseMirror p").hasText("goodbye");});++ test("small applies to every selected line and toggles off", async function (assert) {+ const view = await setupRichEditor(this, "First\n\nSecond");++ selectAll(view);+ await toggleSmall();++ assert+ .dom(".ProseMirror p > small")+ .exists({ count: 2 }, "both paragraphs are small");+ assert+ .dom(".ProseMirror")+ .hasText("First Second", "all selected content is preserved");++ selectAll(view);+ await toggleSmall();++ assert+ .dom(".ProseMirror small")+ .doesNotExist("small formatting is removed");+ assert.dom(".ProseMirror p").exists({ count: 2 }, "both paragraphs remain");+ });++ test("small does not accumulate trailing spaces when repeatedly toggled", async function (assert) {+ const view = await setupRichEditor(this, "First");++ selectAll(view);+ await toggleSmall();+ selectAll(view);+ await toggleSmall();+ const valueAfterOneToggleCycle = this.value;++ selectAll(view);+ await toggleSmall();+ selectAll(view);+ await toggleSmall();++ assert.strictEqual(+ this.value,+ valueAfterOneToggleCycle,+ "a second toggle cycle does not add another space"+ );+ });++ test("small applies to the whole line for a partial selection", async function (assert) {+ const view = await setupRichEditor(this, "Hello world");++ view.dispatch(+ view.state.tr.setSelection(TextSelection.create(view.state.doc, 7, 12))+ );+ await toggleSmall();++ assert+ .dom(".ProseMirror p > small")+ .hasText("Hello world", "the entire line becomes small");+ });++ test("small normalizes inline small text when applied to its line", async function (assert) {+ const view = await setupRichEditor(+ this,+ "Before <small>small</small> after"+ );++ view.dispatch(+ view.state.tr.setSelection(TextSelection.create(view.state.doc, 3))+ );+ await toggleSmall();++ assert+ .dom(".ProseMirror p > small")+ .exists({ count: 1 }, "the line has one small wrapper");+ assert+ .dom(".ProseMirror p > small")+ .hasText("Before small after", "the whole line becomes small");+ });++ test("small replaces a heading at line granularity", async function (assert) {+ const view = await setupRichEditor(this, "## Hello world");++ view.dispatch(+ view.state.tr.setSelection(TextSelection.create(view.state.doc, 3))+ );+ await toggleSmall();++ assert.dom(".ProseMirror h2").doesNotExist("the heading is removed");+ assert+ .dom(".ProseMirror p > small")+ .hasText("Hello world", "the whole line becomes small");+ });++ test("small toggles off from a collapsed caret", async function (assert) {+ const view = await setupRichEditor(this, "Hello world");++ view.dispatch(+ view.state.tr.setSelection(TextSelection.create(view.state.doc, 3))+ );+ await toggleSmall();++ assert.dom(".ProseMirror p > small").hasText("Hello world");+ assert.true(+ this.textManipulation.state.inSmall,+ "the caret stays inside the wrapper, so small reports itself active"+ );++ await toggleSmall();++ assert+ .dom(".ProseMirror small")+ .doesNotExist("a second click removes it without reselecting");+ });++ test("imported small text inside a heading exposes both active formats", async function (assert) {+ const view = await setupRichEditor(+ this,+ "## Before <small>small</small> after"+ );+ const textNode = find(".ProseMirror small").firstChild;+ const pos = view.posAtDOM(textNode, 2);++ view.dispatch(+ view.state.tr.setSelection(TextSelection.create(view.state.doc, pos))+ );+ await settled();+ await click("button.heading");++ // The check icon renders for every option with showActiveIcon and is only+ // hidden with CSS, so --active is the assertable signal.+ assert+ .dom('.btn[data-name="heading-2"]')+ .hasClass("--active", "the heading is active");+ assert+ .dom('.btn[data-name="heading-small"]')+ .hasClass("--active", "small is active at the cursor");+ assert+ .dom('.btn[data-name="heading-paragraph"]')+ .doesNotHaveClass("--active", "paragraph is not reported as the size");++ await click('.btn[data-name="heading-small"]');++ assert.dom(".ProseMirror h2").exists("the heading remains");+ assert.dom(".ProseMirror small").doesNotExist("small is removed");+ });++ test("small inserts and selects a placeholder in an empty line", async function (assert) {+ const view = await setupRichEditor(this, "");++ await toggleSmall();++ assert+ .dom(".ProseMirror p > small")+ .hasText("Small text", "a small placeholder is inserted");+ assert.strictEqual(+ view.state.doc.textBetween(+ view.state.selection.from,+ view.state.selection.to+ ),+ "Small text",+ "the placeholder is selected"+ );+ });});diff --git a/spec/system/composer/prosemirror_toolbar_spec.rb b/spec/system/composer/prosemirror_toolbar_spec.rbindex 30859616aab..1f4ff5480cb 100644--- a/spec/system/composer/prosemirror_toolbar_spec.rb+++ b/spec/system/composer/prosemirror_toolbar_spec.rb@@ -308,5 +308,51 @@ describe "Composer - ProseMirror - Toolbar" docomposer.type_content("This is a test")expect(rich).to have_css("h2", text: "This is a test")end++ it "lets the user apply and remove small text" do+ open_composer++ composer.type_content("This is a test")+ composer.select_all+ composer.send_keys([SystemHelpers::PLATFORM_KEY_MODIFIER, :alt, "5"])++ expect(rich).to have_css("p small", text: "This is a test")++ rich.find("small").click+ heading_menu = composer.heading_menu+ heading_menu.expand+ expect(heading_menu.option("[data-name='heading-small']")).to have_css(".d-icon-check")+ expect(heading_menu.option("[data-name='heading-paragraph']")).to have_no_css(".d-icon-check")+ heading_menu.option("[data-name='heading-small']").click++ expect(rich).to have_no_css("small")+ expect(rich).to have_css("p", text: "This is a test")+ end++ it "lets the user switch between a heading and small text" do+ open_composer++ composer.type_content("This is a test")+ composer.select_all++ heading_menu = composer.heading_menu+ heading_menu.expand+ heading_menu.option("[data-name='heading-2']").click+ expect(rich).to have_css("h2", text: "This is a test")++ composer.select_all+ heading_menu.expand+ heading_menu.option("[data-name='heading-small']").click++ expect(rich).to have_css("p small", text: "This is a test")+ expect(rich).to have_no_css("h2")++ composer.select_all+ heading_menu.expand+ heading_menu.option("[data-name='heading-2']").click++ expect(rich).to have_css("h2", text: "This is a test")+ expect(rich).to have_no_css("small")+ endendend