Skip to content

rubywwwilde/codemirror-assoc-bug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeMirror Initial Selection assoc Bug

Minimal reproduction for a bug where EditorSelection.cursor(pos, assoc) does not respect the assoc parameter when the selection is provided to EditorState.create().

The Bug

When creating an initial selection at a line-wrap boundary with assoc=-1, the cursor should appear at the end of the first visual line. Instead, it appears at the start of the second visual line (as if assoc=1).

// Position 48 is at the wrap boundary (at 400px container width)
// assoc=-1 should place cursor at END of first visual line
const selection = EditorSelection.create([EditorSelection.cursor(48, -1)]);

const state = EditorState.create({
  doc: text,
  extensions: [EditorView.lineWrapping],
  selection, // <-- assoc is ignored here
});

Expected Behavior

Cursor appears at the end of the first visual line (right edge).

Actual Behavior

Cursor appears at the start of the second visual line (left edge).

Reproduction

pnpm install
pnpm dev

Open http://localhost:5173 and observe the cursor position.

Environment

  • @codemirror/state: 6.5.2
  • @codemirror/view: 6.39.8

About

Minimal reproduction: EditorSelection.cursor() ignores assoc parameter on initial state creation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors