我有一个要求,我需要在每行中显示行字符计数。我像这样
每行的限制是112,因此当用户键入超过112个字符时,装订线数将变为负数。一切正常。但是当我复制粘贴时它不起作用。该行是从复制/粘贴文本中识别出来的,只是显示行字符数的装订线标记不会显示所有内容。
我有一个有关行为的视频演示,并在下面发布了代码。
// 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));
});