Skip to content

Commit

Permalink
feature-strikethrough: Add strikethrough menu button.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nirmal Baldaniya committed Nov 13, 2019
1 parent 39265de commit bebaca1
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions dw-text-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ class DwTextEditor extends LitElement {
type: Boolean
},

/**
* Current state of Strikethrough menu in toolbar.
*/
_isStrikeThrough: {
type: Boolean
},

/**
* Current state of Number menu in toolbar.
*/
Expand Down Expand Up @@ -221,6 +228,14 @@ class DwTextEditor extends LitElement {
<dw-icon name="format_underlined"></dw-icon>
</button>
<button
class="menu-btn"
title="Strikethrough"
?active="${this._isStrikeThrough}"
@click="${this._updateStrikeThrough}">
<dw-icon name="format_strikethrough"></dw-icon>
</button>
<button
class="menu-btn"
title="Ordered List"
Expand Down Expand Up @@ -401,6 +416,22 @@ class DwTextEditor extends LitElement {
}
}

/**
* Updates `strikethrough` status of selected text.
*/
_updateStrikeThrough() {
if(!this._editor) {
console.warn('Editor is not ready.');
return;
}

if (this._isStrikeThrough) {
this._editor.removeStrikethrough();
} else {
this._editor.strikethrough();
}
}

/**
* Sets or removes numbered list.
*/
Expand Down Expand Up @@ -461,6 +492,12 @@ class DwTextEditor extends LitElement {
this._isUnderlined = false;
}

if (this._editor.hasFormat('S')) {
this._isStrikeThrough = true;
} else {
this._isStrikeThrough = false;
}

if (this._editor.hasFormat('OL')) {
this._isOrderedList = true;
} else {
Expand Down

0 comments on commit bebaca1

Please sign in to comment.