Skip to content

During drop file error on setSelectionReplaceHistory #6127

@lonejack

Description

@lonejack

When I drop a file I get a console this error:
Uncaught Error: There is no line XX in the document.

at getLine (codemirror.js:876)
  at skipAtomicInner (codemirror.js:5147)
  at skipAtomic (codemirror.js:5188)
  at skipAtomicInSelection (codemirror.js:5137)
  at setSelectionNoUndo (codemirror.js:5104)
  at setSelectionReplaceHistory (codemirror.js:5086)
  at CodeMirror.<anonymous> (codemirror.js:6539)
  at FileReader.<anonymous> (codemirror.js:3908)

Supposed casue of the problem:
On beforeChange event I replace line by line what I want and conclude the procedure with obj.cancel().

Details:
On FileReader the execution of the command makeChange(cm.doc, change) produces a call on:

doc.on("beforeChange", function(doc, obj) {
    let limit = Math.max(object.text, 10);;
    for (let ii = 0; ii < limit ; ii++) {
         let line = doc.getLine(ii + doc.firstLine());
         doc.replaceRange(nlist[ii], {line: ii, ch: 0}, {line: ii, ch: line.length});
    }
    obj.cancel(); // is this allowed?
});

After the command
setSelectionReplaceHistory(cm.doc,`` simpleSelection(pos, changeEnd(change))) // FileReader

the command changeEnd(change) produces an invalid range(probably because the paste hasn't happened):

function changeEnd(change) {
    if (!change.text) { return change.to }
    return Pos(**change.from.line + change.text.length - 1**,
               lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0))
  }

I hope this help
Thank you for your job!
Claudio

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions