1301 Update formatting state on selection update (#1806)

Signed-off-by: Denis Bunakalya <denis.bunakalya@xored.com>
This commit is contained in:
Denis Bunakalya 2022-05-20 06:21:31 +03:00 committed by GitHub
parent e3ef0a0793
commit fcea07cba5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -166,6 +166,11 @@
a.action(evt?.target as HTMLElement, editorHandler) a.action(evt?.target as HTMLElement, editorHandler)
} }
function updateFormattingState () {
isBold = textEditor.checkIsActive('bold')
isItalic = textEditor.checkIsActive('italic')
}
function toggleBold () { function toggleBold () {
textEditor.toggleBold() textEditor.toggleBold()
textEditor.focus() textEditor.focus()
@ -201,6 +206,7 @@
textEditor.clear() textEditor.clear()
}} }}
extensions={editorExtensions} extensions={editorExtensions}
on:selection-update={updateFormattingState}
/> />
</div> </div>
{#if showSend} {#if showSend}

View File

@ -53,6 +53,9 @@
export function insertText (text: string): void { export function insertText (text: string): void {
editor.commands.insertContent(text as HTMLContent) editor.commands.insertContent(text as HTMLContent)
} }
export function checkIsActive (markName: string) {
return editor.isActive(markName)
}
export function toggleBold () { export function toggleBold () {
editor.commands.toggleBold() editor.commands.toggleBold()
} }
@ -119,7 +122,8 @@
onUpdate: () => { onUpdate: () => {
content = editor.getHTML() content = editor.getHTML()
dispatch('value', content) dispatch('value', content)
} },
onSelectionUpdate: () => dispatch('selection-update')
}) })
}) })
}) })