New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Highlighted line moved to top when pasting #150
Comments
Same happens when undoing. Paste document
on itself, then highlight line |
Current highlighting logic is a bit buggy: see bobbylight/RSyntaxTextArea#150.
This happens because the line highlighting is actually tracking an offset in the document (the start offset of the line). In Swing, this is represented by an implementation of the javax.swing.text.Position interface. It seems that, in situations like you describe, these Positions get moved to offset 0 when all content is removed from the document. I'm not sure leaving the highlight on the same line is ideal. Take your use case for example - a code formatter. What if curly braces for a C-like language are moved "up" to the function/method/conditional line when they were previously on another line? In such a case I'd imagine that line highlights on subsequent lines should be moved up one line, not stay on the same line. This is a little tricky to handle. My shameless plug would be to use the AutoComplete add-on to implement error highlighting in the editor (RSTALanguageSupport has examples), but I understand you may not want to make changes to something that's already working. The benefit it would provide is that your errors would be identified by a class that implements a That said, the only fix I can think of here is to simply remove any line highlights for lines that are entirely removed/replaced by editing operations. I will look into that. |
I too don't feel 100% confident about keeping line, say, 3 highlighted, as it could make no sense at all once another, possibly totally different, document is pasted. But the current behaviour is wrong anyway. On the Arduino IDE I worked around it by removing the highlight. A bit rude but at least it can be explained to users |
Paste document
into an empty editor. Highlight line
c
usingRTextArea.addLineHighlight
. Then select the whole document and paste again (actually replacing it). Linea
gets highlighted.It should 1) maintain line
c
highlighed or 2) remove highlighting if the pasted document is shorterThe text was updated successfully, but these errors were encountered: