0
활성 줄의 글 머리 기호가 강조 표시된 배경을 만들려고합니다. 사용하고 있습니다SWT StyledText getCaretOffset 줄 번호가 잘못되었습니다.
int activeLine = styledText.getLineAtOffset(styledText.getCaretOffset());
다른 사람들이 현재 활동 중입니다. 이것은 나가 입력을 명중하고 새로운 선을 얻을 때를 제외하면 작동하는 것을 보인다.
getCaretOffset 35 반환하고 내가 마지막 줄을 클릭하면 getCharCount 라인이 제대로 강조 (지금은 클릭에) (다시 그리기 호출 용), 그러나 36
를 반환하고 getCaretOffset는 36
을 반환 여기![Correct highlighting](https://i.stack.imgur.com/CebXR.png)
는 관련 코드
public void lineGetStyle(LineStyleEvent event) {
// Set the line number
int activeLine = styledText.getLineAtOffset(styledText.getCaretOffset());
System.out.println("Offset " + styledText.getCaretOffset() + " max " + styledText.getCharCount());
int currentLine = styledText.getLineAtOffset(event.lineOffset);
event.bulletIndex = currentLine;
// Set the style, 12 pixles wide for each digit
StyleRange style = new StyleRange();
style.metrics = new GlyphMetrics(0, 0, 36);
if (activeLine == currentLine) {
style.background = highlightedLine;
if (curActiveLine != activeLine){
System.out.println("ActiveLine " + activeLine + " old " + curActiveLine);
int redrawLine = curActiveLine;
curActiveLine = activeLine;
styledText.redraw(0, styledText.getLinePixel(redrawLine), 36, styledText.getLineHeight(),true);
}
}
style.foreground = mainBackground;
// Create and set the bullet
event.bullet = new Bullet(ST.BULLET_NUMBER, style);
event.styles = matchKeywords(event);
}