vue-codemirror icon indicating copy to clipboard operation
vue-codemirror copied to clipboard

No support for renderLine event

Open vintprox opened this issue 5 years ago • 2 comments

Vue.js version and component version

  • vue version 2.6.11
  • vue-codemirror version 4.0.6

Reproduction Link

Example usage of "renderLine" event is shown here: https://jsfiddle.net/vintprox/ndgz4y9b/1/

Steps to reproduce

  1. Add listener @render-line="onRenderLine" to codemirror component.
  2. Write method like this:
onRenderLine(cm, line, el) {
  console.log('renderLine', cm, line, el);
}
  1. Look for console output.

What is Expected?

Being able to wrap lines with certain indentation with help of renderLine event, as shown here: https://codemirror.net/demo/indentwrap.html

What is actually happening?

You'll get silence, because render-line was not declared inside the <codemirror> component.

vintprox avatar Apr 10 '20 11:04 vintprox

There are couple of issues appearing because of lacking events in this component: could as well fetch events list from somewhere (instead of handpicking), but I didn't look into this capability yet. Related: #89

vintprox avatar Apr 10 '20 11:04 vintprox

One workaround would be to bind event listener @ready="onCmReady" and add method

onCmReady(cm) {
  cm.on('renderLine', (cm, line, el) => {
    const paddingLeft = (3 + CodeMirror.countColumn(line.text, null, cm.getOption('tabSize'))) * cm.defaultCharWidth();
    el.style.textIndent = `${-paddingLeft}px`;
    el.style.paddingLeft = `${4 + paddingLeft}px`;
  });
},

Getting codemirror instance cm this way seems less troublesome IMHO. That allows to bind any event (not currently foreseen by vue-codemirror) on editor.

(If you wonder what this snippet is about, it adapts indentation of subsequent "sublines" as a result of line wrapping - to whitespace of line in general plus 3 spaces. So, yeah, it just works now.) image

vintprox avatar Apr 11 '20 09:04 vintprox