Should gapCursor expose $cursor?

Since the GapCursor selection class represents a single position (unlike a NodeSelection) would it be possible for the prose-mirror code to treat it like an empty TextSelection? So toggleMark and other such places in the code that bail if there is an empty selection without a $cursor would instead continue and update the storedMarks, etc? Right now if I use that and try to enable bold, etc. the toggleMark just returns false. I didn’t follow it through if I had changed that but essentially it seems like it should behave like an empty text selection although I guess that assumes the insertion that may happen will be text.

Hmm. So tried forcing it to use my derived gapcursor that did have that and it gets further but then bails within markApplies because the position is not in a node with inline content. So this may be a losing battle. Maybe i’ll just detect that its a gapcursor and then force insertion of a paragraph when i’m going to toggle a mark.

Or maybe I just avoid markApplies in that case and push it into the storedMarks myself because if it’s there (in the storedMarks) it does seem to work. I assume if the node that is ultimately inserted doesn’t support that mark it just won’t be applied. Sorry for the play by play but throwing this out there in case anyone else has this same issue or in case there’s some bad scenario I’m just overlooking.

Note to solve the lack of the $cursor I’m just deriving from GapCursor and exposing a $cursor property and using a plugin with an appendTransaction to provide a new transaction with my cursor if the current selection is a gapcursor. I also have to propogate the storedMarks from the newState because the setSelection is clearing them.

I don’t think it should, since the assumption is that $cursor means a regular text cursor position, in inline context, which doesn’t hold for gap cursors.

I understand not changing the existing gapCursor, toggleMark, markApplies, etc. but without a $cursor property storedMarks on a transaction is not supported/valid. So perhaps that code should ask the Selection if stored marks are supported? The default impl could even be to check if it has $cursor so nothing breaks? Currently my hack/approach of including a $cursor on my Selection class and having some special handling for setting/toggling a mark on such a selection is working but I’m hesitant that something could change in a future version even inadvertantly.

The storedMarks mechanism assumes inline context throughout. What kind of use are you trying to make of it in this case? Marking blocks? Or marking the content of blocks inserted at the position of a gap cursor?

The latter so no, I’m not looking to mark blocks. My understanding is that storedMarks are like a collection of pending styles/state that will be applied to text that is inserted at that position. The gap cursor represents a single position before/after a node that one may insert content and so I would expect that I should be able to store marks at that position and that if I type text thereafter that it would apply. So simple steps:

  1. Go to prosemirror main page.
  2. Select all the text and delete it
  3. Use Insert->Horizontal Rule
  4. Use gap cursor to select before or after the HR
  5. I should be able to use B/I/U/etc but they’re disabled
  6. Type text …

So to me really at step 5 B/I/U/etc should not be disabled. It should be able to set the stored marks so that when i perform step 6 and a default block is created that it applies to that. And if I hack the gapcursor selection to have a $cursor and then avoid markApplies (using a custom toggleMark impl) that all works. But without the $cursor on the selection it is not even feasible even if I did force the marks into the storedMarks because of the code I linked to in the previous response.

1 Like