Trying to hide lines with certain text

I’m trying to use markText with collapsed=true to hide lines that contain certain text. The correct lines get hidden, but the line numbers are wrong.

I am trying to hide the lines by setting “from = {line: lineNumber, ch: 0};” and “to = {line: lineNumber+1, ch: 0}”.

If I try to set “to = {line: lineNumber, ch: <length of line+1>”, the line disappears, but the collapse does not happen.

Any ideas?

In what way are the line numbers wrong?

I want to hide lines 1-28, 30, 31, 33, 34, 35, and 39. I want to keep lines 29, 32, 36, 37, 38, 40, 41, 44, and 45. After I run through each line setting the markText, the correct lines appear, but the line numbers are 1, 30, 33, 37, 38, 39, 41, 42, 45.

It appears the line numbers get messed up somewhere around the lines that are hidden/collapsed.

On Mon, Dec 15, 2014 at 4:02 PM, marijn <discourse@marijnhaverbeke.nl> wrote:


marijn

December 15

In what way are the line numbers wrong?

To respond, reply to this email or visit http://discuss.codemirror.net/t/trying-to-hide-lines-with-certain-text/100/2 in your browser.


Previous Replies

gtaylor20

December 15

I'm trying to use markText with collapsed=true to hide lines that contain certain text. The correct lines get hidden, but the line numbers are wrong.

I am trying to hide the lines by setting "from = {line: lineNumber, ch: 0};" and "to = {line: lineNumber+1, ch: 0}".

If I try to set "to = {line: lineNumber, ch: <length of line+1>", the line disappears, but the collapse does not happen.

Any ideas?


To respond, reply to this email or visit http://discuss.codemirror.net/t/trying-to-hide-lines-with-certain-text/100/2 in your browser.

To unsubscribe from these emails, visit your user preferences.

This is not a bug. It occurs because you are including the line ends in your folded ranges, so for example the start of line 29 is folded away, causing its contents to be added to line 1. You can do this instead:

cm.markText({line: 1, ch: 0}, {line: 28}, {inclusiveRight: true, inclusiveLeft: true, collapsed: true});

This will collapse only the text you actually want to hide. You have to make the mark inclusive on both sides to actually have it hide the line. Also, when I just tested this I noticed a bug that caused codemirror to not update its display in this case. This patch fixes that.

Thanks a lot! That is the trick.

On Tue, Dec 16, 2014 at 5:52 AM, marijn <discourse@marijnhaverbeke.nl> wrote:


marijn

December 16

This is not a bug. It occurs because you are including the line ends in your folded ranges, so for example the start of line 29 is folded away, causing its contents to be added to line 1. You can do this instead:

cm.markText({line: 1, ch: 0}, {line: 28}, {inclusiveRight: true, inclusiveLeft: true, collapsed: true});

This will collapse only the text you actually want to hide. You have to make the mark inclusive on both sides to actually have it hide the line. Also, when I just tested this I noticed a bug that caused codemirror to not update its display in this case. This patch fixes that.

To respond, reply to this email or visit http://discuss.codemirror.net/t/trying-to-hide-lines-with-certain-text/100/4 in your browser.


Previous Replies

gtaylor20

December 15

I want to hide lines 1-28, 30, 31, 33, 34, 35, and 39. I want to keep lines 29, 32, 36, 37, 38, 40, 41, 44, and 45. After I run through each line setting the markText, the correct lines appear, but the line numbers are 1, 30, 33, 37, 38, 39, 41, 42, 45.

It appears the line numbers get messed up somewhere around the lines that are hidden/collapsed.

On Mon, Dec 15, 2014 at 4:02 PM, marijn <discourse@marijnhaverbeke.nl> wrote:

marijn

December 15

In what way are the line numbers wrong?

To respond, reply to this email or visit http://discuss.codemirror.net/t/trying-to-hide-lines-with-certain-text/100/2 in your browser.


Previous Replies

gtaylor20

December 15

I'm trying to use markText with collapsed=true to hide lines that contain certain text. The correct lines get hidden, but the line numbers are wrong.

I am trying to hide the lines by setting "from = {line: lineNumber, ch: 0};" and "to = {line: lineNumber+1, ch: 0}".

If I try to set "to = {line: lineNumber, ch: <length of line+1>", the line disappears, but the collapse does not happen.

Any ideas?


To respond, reply to this email or visit http://discuss.codemirror.net/t/trying-to-hide-lines-with-certain-text/100/2 in your browser.

To unsubscribe from these emails, visit your user preferences.


To respond, reply to this email or visit http://discuss.codemirror.net/t/trying-to-hide-lines-with-certain-text/100/4 in your browser.

To unsubscribe from these emails, visit your user preferences.