compose: Format button for strikethrough.

This commit is contained in:
Julia Bichler 2022-02-02 15:39:59 +01:00 committed by Tim Abbott
parent 4ccbde23cc
commit 63e5e05643
3 changed files with 50 additions and 0 deletions

View File

@ -677,6 +677,11 @@ export function format_text($textarea, type, inserted_content) {
case "numbered":
format_list(type);
break;
case "strikethrough": {
const strikethrough_syntax = "~~";
format(strikethrough_syntax);
break;
}
case "link": {
// Ctrl + L: Insert a link to selected text
wrapSelection(field, "[", "](url)");

View File

@ -2,6 +2,7 @@
<a role="button" data-format-type="link" class="compose_control_button fa fa-link formatting_button" aria-label="{{t 'Link' }}" {{#unless preview_mode_on}} tabindex=0 {{/unless}} data-tippy-content="{{t 'Link' }}"></a>
<a role="button" data-format-type="bold" class="compose_control_button fa fa-bold formatting_button" aria-label="{{t 'Bold' }}" {{#unless preview_mode_on}} tabindex=0 {{/unless}} data-tippy-content="{{t 'Bold' }}"></a>
<a role="button" data-format-type="italic" class="compose_control_button fa fa-italic formatting_button" aria-label="{{t 'Italic' }}" {{#unless preview_mode_on}} tabindex=0 {{/unless}} data-tippy-content="{{t 'Italic' }}"></a>
<a role="button" data-format-type="strikethrough" class="compose_control_button fa fa-strikethrough formatting_button" aria-label="{{t 'Strikethrough' }}" {{#unless preview_mode_on}} tabindex=0 {{/unless}} data-tippy-content="{{t 'Strikethrough' }}"></a>
<div class="divider">|</div>
<a role="button" data-format-type="numbered" class="compose_control_button fa fa-list-ol formatting_button" aria-label="{{t 'Numbered list' }}" {{#unless preview_mode_on}} tabindex=0 {{/unless}} data-tippy-content="{{t 'Numbered list' }}"></a>
<a role="button" data-format-type="bulleted" class="compose_control_button fa fa-list-ul formatting_button" aria-label="{{t 'Bulleted list' }}" {{#unless preview_mode_on}} tabindex=0 {{/unless}} data-tippy-content="{{t 'Bulleted list' }}"></a>

View File

@ -766,6 +766,50 @@ run_test("format_text - bold and italic", ({override}) => {
assert.equal(wrap_selection_called, false);
});
run_test("format_text - strikethrough", ({override}) => {
override(text_field_edit, "set", (_field, text) => {
set_text = text;
});
override(text_field_edit, "wrapSelection", (_field, syntax_start, syntax_end) => {
wrap_selection_called = true;
wrap_syntax_start = syntax_start;
wrap_syntax_end = syntax_end;
});
const strikethrough_syntax = "~~";
// Strikethrough selected text
reset_state();
compose_ui.format_text($textarea, "strikethrough");
assert.equal(set_text, "");
assert.equal(wrap_selection_called, true);
assert.equal(wrap_syntax_start, strikethrough_syntax);
assert.equal(wrap_syntax_end, strikethrough_syntax);
// Undo strikethrough selected text, syntax not selected
reset_state();
init_textarea("~~abc~~", {
start: 2,
end: 5,
text: "abc",
length: 3,
});
compose_ui.format_text($textarea, "strikethrough");
assert.equal(set_text, "abc");
assert.equal(wrap_selection_called, false);
// Undo strikethrough selected text, syntax selected
reset_state();
init_textarea("~~abc~~", {
start: 0,
end: 7,
text: "~~abc~~",
length: 7,
});
compose_ui.format_text($textarea, "strikethrough");
assert.equal(set_text, "abc");
});
run_test("markdown_shortcuts", ({override_rewire}) => {
let format_text_type;
override_rewire(compose_ui, "format_text", (_$textarea, type) => {