Detect wrap position

Hello!

Scenario: I have longer line/paragraph that is wrapped and spans multiple lines. I put cursor somewhere inside that paragraph.

Is it possible to get start and end positions of that line (not start and end of the paragraph)?

I am almost certain api doesn’t support it, but is there a hacky way to get this?

In word processors Home and End buttons won’t move to the start/end of the paragraph, but start/end of the onscreen line. I’d like to mimic that functionality with cm.

Thanks,
Iztok

You can simply bind Home and End to the "goLineLeft" and "goLineRight" commands

I also would like to know the character position for each wrapped line in a paragraph also (and binding won’t cover my use case).

My use case is that I’ve created a minimap replacement for the traditional scrollbar. I create the minimap display using runmode and an overlay which you can drag up/down. This works OK if your representation of the editor doesn’t have wrapped lines.

However, if the editor does have wrapped lines, trying to do that in a runmode created representation for display in the minimap is near impossible as chars render differently at the large and small sizes, so wrap at different points and you end up with a mismatch.

If I knew where the line wraps happened in the editor, I could make the minimap not really have line wrapping and fake it by breaking lines at the correct positions.

Is there a way to get the wrap ch positions for each line wrapped?

I overlooked that. Sorry and thanks,
Iztok

Nothing clean, but you could get pretty far with calling coordsChar on a position to the right of a given line.

1 Like

I thought that might be the best approach, OK thanks.

Also donated a little something - keep up the good work. :slight_smile:

1 Like