Highlighting matching brace in Text Editor
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, September 16, 2008 10:05 PM

In a Text Editor for a custom language similar to C++, if the cursor is near a brace, I want to highlight the matching brace ( "{", "(","[" and counter parts), similar to Java Editor. i.e to draw a rectangle around the matching brace. I was able to do that with below code. StyledText text = sourceViewer.getTextWidget(); int modelPosition = projectionViewer.modelOffset2WidgetOffset( matchingBracePosition); Rectangle rectangle = text.getTextBounds(modelPosition, modelPosition+1); GC gc = new GC( text); Color color = new Color ( gc.getDevice(),127, 127, 127); gc.setForeground(color);    More>>


In a Text Editor for a custom language similar to C++, if the cursor is near a brace, I want to highlight the matching brace ( "{", "(","[" and counter parts), similar to Java Editor. i.e to draw a rectangle around the matching brace.


I was able to do that with below code.



StyledText text = sourceViewer.getTextWidget();

int modelPosition = projectionViewer.modelOffset2WidgetOffset( matchingBracePosition);

Rectangle rectangle = text.getTextBounds(modelPosition, modelPosition+1);

GC gc = new GC( text);


Color color = new Color ( gc.getDevice(),127, 127, 127);


gc.setForeground(color);

rectangle.width = 6;


gc.drawRectangle(rectangle);

gc.dispose();



But the problem with this code is if we scroll (vertical) the text in the editor and if text containing brace moves out-of-viewable range due to scroll, rectangle around the matching brace disappears on scrolling back.



How can i maintain the rectangle, even after scrolling, as long as the cursor is near brace?
Any suggestions?


Sincerely,
Lolita    <<Less
About | Sitemap | Contact