Skip to content
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

Open
ffissore opened this issue Oct 26, 2015 · 3 comments
Open

Highlighted line moved to top when pasting #150

ffissore opened this issue Oct 26, 2015 · 3 comments

Comments

@ffissore
Copy link

Paste document

a
b
c

into an empty editor. Highlight line c using RTextArea.addLineHighlight. Then select the whole document and paste again (actually replacing it). Line a gets highlighted.
It should 1) maintain line c highlighed or 2) remove highlighting if the pasted document is shorter

@ffissore
Copy link
Author

Same happens when undoing. Paste document

a
b
c

on itself, then highlight line c and finally undo. Line a will get highlighted

ffissore pushed a commit to arduino/Arduino that referenced this issue Oct 26, 2015
Current highlighting logic is a bit buggy: see bobbylight/RSyntaxTextArea#150.
@bobbylight
Copy link
Owner

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 Parser interface, and would be automatically updated when updates are made in an instance of RSTA.

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.

@ffissore
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants