Codemirror cursor behaving weirdly

Hi @marijn,

We’re using a custom highlighter and we’re facing a very weird issue.
So I’m uploading a screen recording. It works fine on Chrome and Firefox, but the issue occurs on NW.js container (with Chromium 114).
Can you please guide here?

The file link expires in 24hrs - Screen Recording 2024-06-03 at 18.25.42

1 Like

here is the custom highlighter.

import {
  EditorView,
  Decoration,
} from '@codemirror/view';
import { StateEffect, StateField } from '@codemirror/state';

export const currentQueryHighlighterEffect = StateEffect.define({
  map: ({ from, to }, change) => ({ from: change.mapPos(from), to: change.mapPos(to) })
});

const currentQueryHighlighterDeco = Decoration.mark({ class: 'cm-current-query' });

export const currentQueryHighlighterField = StateField.define({
  create() {
    return Decoration.none;
  },
  update(value, tr) {
    value = value.map(tr.changes);
    for (let e of tr.effects) if (e.is(currentQueryHighlighterEffect)) {
      if (e.value.from < e.value.to) {
        return Decoration.set([currentQueryHighlighterDeco.range(e.value.from, e.value.to)]);
      }
      return Decoration.none;
    }
    return value;
  },
  provide: f => EditorView.decorations.from(f)
});

export default function currentQueryHighlighterExtn() {
  return [currentQueryHighlighterField];
}

One more observation is, if the line starts with “Tab” then it creates problem. But if start “Spaces Tab” then seems to be working fine.

I’m not prepared to debug node-webkit or any other pseudo-browser platforms. If you cannot reproduce this in a real browser, you’ll have to figure out the issue on your own.

Can you please guide me where to debug in the codemirror code?

Hi @marijn,

When typing itself the character is added to end of line. Could this be a NW.js bug?

Could it be that you’re using some kind of frames and this is issue #1386.

Is it released? I can give a try on latest version.
BTW, we had a similar issue as well. But not related this.

No, it occurs without Iframe as well.

It wasn’t, but I’ve just tagged @codemirror/view 6.26.6, which includes that fix.

1 Like

Thank you for your quick response. But its definitely a NW.js bug related to contenteditable. I’ve tried Electron, Safari, Chrome, Firefox. All works fine.