RSyntaxTextArea icon indicating copy to clipboard operation
RSyntaxTextArea copied to clipboard

Highlight on the first line stays there when the line moves

Open matthijskooijman opened this issue 8 years ago • 0 comments

When you add a highlight on the first line, and then insert a new line by putting the cursor at the start of the first line and pressing enter, the highlighted line becomes the second line, but the highlight stays on the (now empty) first line. This is inconsistent with highlights on other lines, where the highlight moves along with the line.

This seems to be caused by swing having the 0 offset treated specially to never move. From the javax.swing.text.Position documentation:

Position with an offset of 0 is a special case. It never changes its offset while document content is altered.

One way to prevent this would be to use offset 1 for the first line instead of 0, which is probably best implemented here. I haven't tested if this has any side effects, but the only corner case I can imagine just now is if the highlighted line is empty (then the offset 1 would point after the newline, and might cause the next line to be highlighted, so this would need another exception).

This problem was originally reported for Arduino at https://github.com/arduino/Arduino/issues/5418 but I believe it applies to all of RSyntaxArea.

matthijskooijman avatar Jan 19 '17 08:01 matthijskooijman