yabwe / medium-editor

Medium.com WYSIWYG editor clone. Uses contenteditable API to implement a rich text solution.
https://yabwe.github.io/medium-editor/
Other
16.07k stars 1.85k forks source link

Wrong active states on u, i, and can't cancel h2, h3 when used with Vue #1269

Open laosb opened 7 years ago

laosb commented 7 years ago

Description

I tried to use this with Vue 2.0, it looks fine but have problems stated in the title.

Reproduction

I have an self-written component for Vue2.0:

<template>
    <article v-html="value">{{valueData}}</article>
</template>
<style scoped>
    .medium-editor-placeholder:after {
        margin: 0;
        color: #555;
    }
</style>
<script>
    import MediumEditor from 'medium-editor';

    const options = {
        placeholder: {
            text: 'Write down your ideas...',
            hideOnClick: true,
        },
    };

    export default {
        props: {
            value: { type: String },
        },
        data(){
            return { valueData: this.value };
        },
        mounted() {
            const editorToDataSync = (data, editable) => {
                // this.valueData = editable.innerHTML;
                this.$emit('input', editable.innerHTML);
            };

            this.editor = new MediumEditor(this.$el, options);
            this.editor.subscribe('editableInput', editorToDataSync);
        },
        beforeDestroy() {
            this.editor.destroy();
        },
    };
</script>

and use it:

<medium-editor class="u-full-width" v-model="content"></medium-editor>

Hope you can reproduce with the traditional Webpack solution, but I'm actually using Akryum/meteor-vue-component with Meteor.

Versions

laosb commented 7 years ago

@j0k3r Hope you are still maintaining this awesome project

j0k3r commented 7 years ago

@laosb I don't have the time I had few months ago. That's why I do the minimum to answer what I can.

JelleScheer commented 7 years ago

Did you set any styling for underline and italic in your CSS? If it overwrites the Medium styling, the buttons wont work. Atleast that was the issue in my case.

laosb commented 7 years ago

We've customized the underline and italic, true. But I guess that's not the problem? I don't quite get your meaning of "overwrites the Medium styling"?

nmielnik commented 7 years ago

MediumEditor relies on the browser's document.queryCommandState() method to indicate whether the selected text is underlined, italic, bold, etc. If there is any css on the page which changes the appearance of <i>/<em> or <u> tags it can break the browser's built-in detection of whether the text is italic or underlined. This can also vary from browser to browser.

For example, if you set the font-weight to be something like 800 for the text within the editor element, the editor will likely not be able to detect 'bold' properly, and probably won't be able to bold/unbold the text either.

Like @JelleScheer stated, every time I've seen issues with the editor detecting the style of text, or not being able to style the text, it's been because some css on the page affects the presentation of some of these tags (<strong>, <b>, <i>, etc.). I know a bunch of normalization stylesheets will often include selectors which style these basic tags.

jaymanned commented 6 years ago

What I see is that by default, selecting a text as H2/H3 also make the bold button active. And if you select a link, the underline button becomes active. This is not the expected behaviour (check the original Medium editor) and therefore confusing. Can't anything be done?

paulocastellano commented 6 years ago

Any update @laosb ?

debugd commented 6 years ago

I am having this issue as well, unable to de-select the H tags