Codemirror hint on inputRead resets cm.display.viewOffset

While calling Codemirror.hint inside “inputRead” event, the content assist DOM element

    goes out of the viewport.
    After debugging I found that cm.display.viewOffset becomes 0, during the inputRead event, which in turn makes the yOffset variable to become more than the cursor position.

    else yOff -= cm.display.viewOffset; (line no: 2713, file codemirror.js, function intoCoordSystem)

    I need to know when should i call autocomplete. This issue was not there in version 5.1.1. I m currently in 5.14.3.

I can’t reproduce this – viewOffset seems to have its proper value when I log it inside an "inputRead" event handler.

Hi Marjin,

Thanks for the reply. The problem still persists.
In the codemirror 5.15.0, the line number is 2799, have a log after the line number 2799 i.e

console.log(cm.display.viewOffset) in line number 2801

for every

inputRead

i get a series of these logs where one particular value is 0

You’re pointing at the intoCoordSystem function, I guess. How are you causing that to run when inputRead fires? Could you provide the full code needed to show the issue?

This is the code I use for hinting on every text input

editor.on(“inputRead”, function (cm, change) {
CodeMirror.showHint(cm, CodeMirror.hint.anyword, {
completeSingle: false,
closeOnUnfocus: false,
viewOffset: cm.display.viewOffset
});
});

The above code shifts the <ul> element of the content assist outside the viewport.The issue was temporarily corrected by adding a setTimeout inside “inputRead” event.

editor.on(“inputRead”, function (cm, change) {
setTimeout(function () {
CodeMirror.showHint(cm, CodeMirror.hint.anyword, {
completeSingle: false,
closeOnUnfocus: false,
viewOffset: cm.display.viewOffset
});
}, 10);
});

There is no viewOffset option to showHint. Why are you passing that there?

If I set up an editor like you describe, the hint widget does seem to appear in the right place.