问题
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