Tiptap: Access the the Vue component instance inside an Editor event

Created on 17 Oct 2019  路  1Comment  路  Source: ueberdosis/tiptap

I'm trying to find a way to mutate a data property in my vue component so I can display what a highlighted mark's attribute contains ( in the editor menu bar).

I have a custom font mark extension with a color attribute, and in the menu bar I have a color selector button with a color indicator. My desired behavior would be on the event when the user is selecting text or otherwise moving their cursor in the editor, if a mark is selected and has the color attribute, the indicator would change color accordingly

So far, I've been able to determine that the onTransaction gets fired when I need, but I'm trying to figure out how I can access the Editor's parent vue component from within the onTransaction event which is defined in the Editor instance is created. Is is possible to save a reference to the current component instance inside the Editor instance, or maybe is there a way to propagate this event up to the component?

Most helpful comment

You can

export default {
  data() {
    return { editor: null, name: 'world' }
  },
  mounted() {
    this.$nextTick(() => {
        const onTransaction = () => {
            console.log('hello' + this.name)
        }
        this.editor = new Editor({
            onTransaction
        })
    })
  }
}

or

export default {
  data() {
    return { editor: null, name: 'world' }
  },
  mounted() {
    this.$nextTick(() => {
        const that = this
        this.editor = new Editor({
            onTransaction() => {
                console.log('hello' + that.name)
            }
        })
    })
  }
}

>All comments

You can

export default {
  data() {
    return { editor: null, name: 'world' }
  },
  mounted() {
    this.$nextTick(() => {
        const onTransaction = () => {
            console.log('hello' + this.name)
        }
        this.editor = new Editor({
            onTransaction
        })
    })
  }
}

or

export default {
  data() {
    return { editor: null, name: 'world' }
  },
  mounted() {
    this.$nextTick(() => {
        const that = this
        this.editor = new Editor({
            onTransaction() => {
                console.log('hello' + that.name)
            }
        })
    })
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jameswragg picture jameswragg  路  3Comments

pk-pressf1 picture pk-pressf1  路  3Comments

klaasgeldof picture klaasgeldof  路  3Comments

chrisjbrown picture chrisjbrown  路  3Comments

afwn90cj93201nixr2e1re picture afwn90cj93201nixr2e1re  路  3Comments