Codemirror gutter marker change issue

社会主义新天地 提交于 2019-12-08 07:22:52

问题


I have a requirement where i need to show line character counts in every line. I am showing it in gutter like such

The limit on each line is 112, so the gutter number goes to negative when user types more than 112 characters. Everything works great. But when i do copy paste it doesn't work. The line is identified from the copy/paste texts and everything just the gutter marker which shows line character counts doesn't show.

I have a little video demo of the behavior, and code posted below.

Video

// Instantiate CodeMirror
var textEditor = CodeMirror(document.getElementById('noteArea'), {
  lineNumbers: true,
  autofocus: true,
  gutters: ["CodeMirror-linenumbers", "lineLength"],
  lineWrapping: true,
  fixedGutter: true,
  lineWiseCopyCut: true,
  dragDrop: true,
  lineSeparator: '\n'
});

// Logic to check character length in one line. This function also displays the number of characters on the left
textEditor.on("change", function(cm, change) {
  var doc = cm.getDoc();
  var cursor = doc.getCursor();
  var count = 112 - cursor.ch
  var line = doc.size -1
  var info = cm.lineInfo(line);
  cm.setGutterMarker(line, "lineLength",makeMarker(count, line));
});

来源:https://stackoverflow.com/questions/51289031/codemirror-gutter-marker-change-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!