Can anyone help me with getting an access to history data?
Currently I’m trying to serialize historyField in update method of ViewPlugin class… so far I have some TS issues like this one (which I successfully ignore), when I tried to pass {history: historyField} into toJSON() method:
Type 'StateField\<unknown>' is not assignable to type 'StateField\<any>'. Types have separate declarations of a private property 'createF'.
As seen on screenshot below, history depth is always about to be 0, and I’m not sure what serialization supposed to do with provided object, but I assumed to get some history info:
My overall goal is to easily understand with existing methods when I should change UI for undo/redo buttons: so if undoDepth / redoDepth = 0, I’d like to make buttons look disabled respectively.
P.S. I also tried to get this data in EditorView.updateListener, and it didn’t work out…
as I understand, history extension comes from basicSetup, so I don’t need to add it myself, so all I need to do is to provide current state to undo / redoDepth functions. Even when I tried to add extension myself, I got this error:
Error: Unrecognized extension value in extension set ([object Object]). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.
The error probably points at the problem — you’re loading multiple versions of the packages, causing the undoDepth function you’re calling to try and read another instance of the state field than the one that’s actually on your state, causing it to return 0. Check your dependency tree for duplicates (npm ls -a | grep @codemirror).
Then I uninstalled everything related to codemirror (including @uiw react package), removed node_modules, package-lock.json and just installed codemirror package and tried to run it in react environment.
The problem still persists. undoDepth yields 0.
I tried to put history extension explicitly and got this error again:
Uncaught Error: Unrecognized extension value in extension set ([object Object]). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.
The dependencies related to @codemirror after reinstallation:
The problem was that history methods were suggested to be imported from @codemirror/history, which is deprecated package that comes from @emmetio/codemirror6-plugin dependencies.
Thus, I had no clue that this package is deprecated and would conflict with @codemirror/commands imports (where all the history related stuff should be actually imported from).
I should’ve paid more attention… Anyway, thanks a lot for help and patience