diff --git a/public/assets/scripts/dash/app/controllers/PageEditor.js b/public/assets/scripts/dash/app/controllers/PageEditor.js index 9364d37..914ea42 100644 --- a/public/assets/scripts/dash/app/controllers/PageEditor.js +++ b/public/assets/scripts/dash/app/controllers/PageEditor.js @@ -167,9 +167,13 @@ export default class PostEditor { } if (currentOption != null) { let active = currentOption.getAttribute('data-active'); - active == 'false' - ? currentOption.setAttribute('data-active', 'true') - : currentOption.setAttribute('data-active', 'false'); + if (active == 'false') { + currentOption.setAttribute('data-active', 'true'); + currentOption.setAttribute('aria-pressed', 'true'); + } else { + currentOption.setAttribute('data-active', 'false'); + currentOption.setAttribute('aria-pressed', 'false'); + } } } handleEditorOptions(e) { diff --git a/public/assets/scripts/dash/app/ui/TextEditor.js b/public/assets/scripts/dash/app/ui/TextEditor.js index 0971315..23c24b8 100644 --- a/public/assets/scripts/dash/app/ui/TextEditor.js +++ b/public/assets/scripts/dash/app/ui/TextEditor.js @@ -124,30 +124,54 @@ class TextEditor extends EventEmitter { let end = this.textEditor.selectionEnd; let selectedText = this.textEditor.value.substring(start, end); + let formatText = this.textEditor.value.substring(start - 1, end + 1); let insert = ''; switch (e.target.id) { case 'edit-bold': - insert = '**' + selectedText + '**'; - this.textEditor.value = - this.textEditor.value.substring(0, start) + - insert + - this.textEditor.value.substring(end, len); + if (formatText.includes('*')) { + insert = selectedText; + this.textEditor.value = + this.textEditor.value.substring(0, start - 2) + + insert + + this.textEditor.value.substring(end + 2, len); + } else { + insert = '**' + selectedText + '**'; + this.textEditor.value = + this.textEditor.value.substring(0, start) + + insert + + this.textEditor.value.substring(end, len); + } break; case 'edit-italic': - insert = '*' + selectedText + '*'; - //console.log(this.textEditor); - this.textEditor.value = - this.textEditor.value.substring(0, start) + - insert + - this.textEditor.value.substring(end, len); + if (formatText.includes('*')) { + insert = selectedText; + this.textEditor.value = + this.textEditor.value.substring(0, start - 1) + + insert + + this.textEditor.value.substring(end + 1, len); + } else { + insert = '*' + selectedText + '*'; + this.textEditor.value = + this.textEditor.value.substring(0, start) + + insert + + this.textEditor.value.substring(end, len); + } break; case 'edit-strikethrough': - insert = '~~' + selectedText + '~~'; - this.textEditor.value = - this.textEditor.value.substring(0, start) + - insert + - this.textEditor.value.substring(end, len); + if (formatText.includes('~')) { + insert = selectedText; + this.textEditor.value = + this.textEditor.value.substring(0, start - 2) + + insert + + this.textEditor.value.substring(end + 2, len); + } else { + insert = '~~' + selectedText + '~~'; + this.textEditor.value = + this.textEditor.value.substring(0, start) + + insert + + this.textEditor.value.substring(end, len); + } break; case 'edit-header1': insert = '# ' + selectedText + '\n'; diff --git a/resources/views/includes/options.blade.php b/resources/views/includes/options.blade.php index 067ccc3..0aaeb43 100644 --- a/resources/views/includes/options.blade.php +++ b/resources/views/includes/options.blade.php @@ -30,15 +30,15 @@ if(isset($page['uuid'])) ?>