From ee684d09b64c54fa010babd286fee8ccf273c781 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Sat, 28 Mar 2020 16:43:39 -0400 Subject: [PATCH] Bug 561319: Remove flickering in terminal when changing selection This is done by buffering the drawing of the line of the terminal. Change-Id: I593a3b99080d779046ea37497d93a25584c472c1 --- .../feature.xml | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../terminal/textcanvas/TextLineRenderer.java | 53 +++++++++++-------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/terminal/features/org.eclipse.tm.terminal.control.feature/feature.xml b/terminal/features/org.eclipse.tm.terminal.control.feature/feature.xml index c1966c85670..53af7622cb9 100644 --- a/terminal/features/org.eclipse.tm.terminal.control.feature/feature.xml +++ b/terminal/features/org.eclipse.tm.terminal.control.feature/feature.xml @@ -16,7 +16,7 @@ = getTerminalText().getHeight() || colFirst >= getTerminalText().getWidth() || colFirst - colLast == 0) { - fillBackground(gc, x, y, getCellWidth() * (colLast - colFirst), getCellHeight()); + fillBackground(doubleBufferGC, 0, 0, width, height); } else { colLast = Math.min(colLast, getTerminalText().getWidth()); LineSegment[] segments = getTerminalText().getLineSegments(line, colFirst, colLast - colFirst); for (int i = 0; i < segments.length; i++) { LineSegment segment = segments[i]; Style style = segment.getStyle(); - setupGC(gc, style); + setupGC(doubleBufferGC, style); String text = segment.getText(); - drawText(gc, x, y, colFirst, segment.getColumn(), text); - drawCursor(model, gc, line, x, y, colFirst); + drawText(doubleBufferGC, 0, 0, colFirst, segment.getColumn(), text); + drawCursor(model, doubleBufferGC, line, 0, 0, colFirst); } if (fModel.hasLineSelection(line)) { - gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT)); - gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_SELECTION)); + doubleBufferGC.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT)); + doubleBufferGC.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_SELECTION)); Point start = model.getSelectionStart(); Point end = model.getSelectionEnd(); char[] chars = model.getTerminalText().getChars(line); - if (chars == null) - return; - int offset = 0; - if (start.y == line) - offset = start.x; - offset = Math.max(offset, colFirst); - int len; - if (end.y == line) - len = end.x - offset + 1; - else - len = chars.length - offset + 1; - len = Math.min(len, chars.length - offset); - if (len > 0) { - String text = new String(chars, offset, len); - drawText(gc, x, y, colFirst, offset, text); + if (chars != null) { + int offset = 0; + if (start.y == line) + offset = start.x; + offset = Math.max(offset, colFirst); + int len; + if (end.y == line) + len = end.x - offset + 1; + else + len = chars.length - offset + 1; + len = Math.min(len, chars.length - offset); + if (len > 0) { + String text = new String(chars, offset, len); + drawText(doubleBufferGC, 0, 0, colFirst, offset, text); + } } } } + gc.drawImage(buffer, x, y); + doubleBufferGC.dispose(); + buffer.dispose(); } private void fillBackground(GC gc, int x, int y, int width, int height) {