diff --git a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLinesProvider.java b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/DefaultStickyLinesProvider.java similarity index 80% rename from bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLinesProvider.java rename to bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/DefaultStickyLinesProvider.java index 01a8e8090d6..f0f1370257f 100644 --- a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLinesProvider.java +++ b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/DefaultStickyLinesProvider.java @@ -24,32 +24,26 @@ /** * This class provides sticky lines for the given source code in the source viewer. The - * implementation is completely based on indentation and therefore should work by default for - * several languages. + * implementation is completely based on indentation and therefore works by default for several + * languages. */ -public class StickyLinesProvider { +public class DefaultStickyLinesProvider implements IStickyLinesProvider { - private final static int IGNORE_INDENTATION= -1; + private final static int IGNORE_LINE_INDENTATION= -1; private final static String TAB= "\t"; //$NON-NLS-1$ - private int tabWidth= 4; - - /** - * Calculate the sticky lines for the given source code in the source viewer for the given - * vertical offset. - * - * @param verticalOffset The vertical offset line index of the first visible line - * @param sourceViewer The source viewer containing the source code - * @return A list of sticky lines - */ - public List get(int verticalOffset, ISourceViewer sourceViewer) { - LinkedList stickyLines= new LinkedList<>(); + private StickyLinesProperties fProperties; - if (verticalOffset == 0) { - return stickyLines; + @Override + public List getStickyLines(ISourceViewer sourceViewer, StickyLinesProperties properties) { + if (sourceViewer.getTopIndex() == 0) { + return Collections.emptyList(); } + this.fProperties= properties; + LinkedList stickyLines= new LinkedList<>(); + try { StyledText textWidget= sourceViewer.getTextWidget(); int startLine= textWidget.getTopIndex(); @@ -71,7 +65,7 @@ private void calculateStickyLinesForLineNumber(LinkedList stickyLine String line= textWidget.getLine(i); int indentation= getIndentation(line); - if (indentation == IGNORE_INDENTATION) { + if (indentation == IGNORE_LINE_INDENTATION) { continue; } @@ -91,7 +85,7 @@ private void calculateStickyLinesUnderStickyLineControl(LinkedList s String line= textWidget.getLine(i); int indentation= getIndentation(line); - if (indentation == IGNORE_INDENTATION) { + if (indentation == IGNORE_LINE_INDENTATION) { continue; } @@ -123,7 +117,7 @@ private int mapLineNumberToSourceViewerLine(int lineNumber, ISourceViewer source private int getStartIndentation(int startFromLine, StyledText styledText) { int indentation= getIndentation(styledText.getLine(startFromLine)); - if (indentation != IGNORE_INDENTATION) { + if (indentation != IGNORE_LINE_INDENTATION) { return indentation; } else { int nextContentLine= getIndentation(getNextContentLine(startFromLine, styledText)); @@ -154,21 +148,12 @@ private String getPreviousContentLine(int startFromLine, StyledText styledText) private int getIndentation(String line) { if (line == null || line.isBlank()) { - return IGNORE_INDENTATION; + return IGNORE_LINE_INDENTATION; } - String tabAsSpaces= String.join("", Collections.nCopies(tabWidth, " ")); //$NON-NLS-1$ //$NON-NLS-2$ + String tabAsSpaces= String.join("", Collections.nCopies(fProperties.tabWith(), " ")); //$NON-NLS-1$ //$NON-NLS-2$ line= line.replace(TAB, tabAsSpaces); return line.length() - line.stripLeading().length(); } - /** - * Sets the with in spaces of a tab in the editor. - * - * @param tabWidth The amount of spaces a tab is using. - */ - public void setTabWidth(int tabWidth) { - this.tabWidth= tabWidth; - } - } diff --git a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/IStickyLinesProvider.java b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/IStickyLinesProvider.java new file mode 100644 index 00000000000..677ae114cd3 --- /dev/null +++ b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/IStickyLinesProvider.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2024 SAP SE. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * SAP SE - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.texteditor.stickyscroll; + +import java.util.List; + +import org.eclipse.swt.custom.StyledText; + +import org.eclipse.jface.text.source.ISourceViewer; + +/** + * A sticky lines provider calculates the sticky lines for a given source viewer. The sticky lines + * will be displayed in the top area of the editor. + * + * TODO move to public package and add since 3.19 + */ +public interface IStickyLinesProvider { + + /** + * Calculate the sticky lines for the source code of the given sourceViewer. Specific + * properties, such as the tabWidht can be retrieved from the + * properties. + * + * @param sourceViewer The source viewer containing the source code and information about the + * first visible line + * @return The list of sticky lines to show + * + * @see ISourceViewer#getTopIndex() + * @see ISourceViewer#getTextWidget() + * @see StyledText#getTopIndex() + */ + public List getStickyLines(ISourceViewer sourceViewer, StickyLinesProperties properties); + + /** + * Properties required to calculate the sticky lines. + * + * @param tabWith The with of a tab + */ + record StickyLinesProperties(int tabWith) { + } + +} diff --git a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandler.java b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandler.java index 05b8813af39..432ee38f381 100644 --- a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandler.java +++ b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandler.java @@ -21,6 +21,7 @@ import static org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH; import java.time.Duration; +import java.util.Collections; import java.util.List; import org.eclipse.swt.graphics.Color; @@ -37,9 +38,10 @@ import org.eclipse.jface.text.source.IVerticalRuler; import org.eclipse.ui.internal.editors.text.EditorsPlugin; +import org.eclipse.ui.internal.texteditor.stickyscroll.IStickyLinesProvider.StickyLinesProperties; /** - * A sticky scrolling handler that retrieves stick lines from the {@link StickyLinesProvider} and + * A sticky scrolling handler that retrieves stick lines from a {@link IStickyLinesProvider} and * shows them in a {@link StickyScrollingControl} on top of the given source viewer. */ public class StickyScrollingHandler implements IViewportListener { @@ -50,94 +52,95 @@ public class StickyScrollingHandler implements IViewportListener { private StickyScrollingControl stickyScrollingControl; - private int tabWidth; - private IPropertyChangeListener propertyChangeListener; private IPreferenceStore preferenceStore; - private StickyLinesProvider stickyLinesProvider; + private IStickyLinesProvider stickyLinesProvider; + + private StickyLinesProperties stickyLinesProperties; private Throttler throttler; private int verticalOffset; /** - * Creates a StickyScrollingHandlerIndentation that will be linked to the given source viewer. - * The sticky scrolling will be computed by the default {@link StickyLinesProvider}. + * Creates a StickyScrollingHandler that will be linked to the given source viewer. The sticky + * lines will be provided by the {@link DefaultStickyLinesProvider}. * - * @param sourceViewer The source viewer to link the handler + * @param sourceViewer The source viewer to link the handler with * @param verticalRuler The vertical ruler of the source viewer * @param preferenceStore The preference store */ public StickyScrollingHandler(ISourceViewer sourceViewer, IVerticalRuler verticalRuler, IPreferenceStore preferenceStore) { - this(sourceViewer, verticalRuler, preferenceStore, new StickyLinesProvider()); + this(sourceViewer, verticalRuler, preferenceStore, new DefaultStickyLinesProvider()); } /** - * Creates a StickyScrollingHandlerIndentation that will be linked to the given source viewer. + * Creates a StickyScrollingHandler that will be linked to the given source viewer. The sticky + * lines will be provided by the given stickyLinesProvider. * - * @param sourceViewer The source viewer to link the handler + * @param sourceViewer The source viewer to link the handler with * @param verticalRuler The vertical ruler of the source viewer * @param preferenceStore The preference store - * @param stickyLinesProvider The sticky scrolling computer + * @param stickyLinesProvider The sticky scrolling provider */ public StickyScrollingHandler(ISourceViewer sourceViewer, IVerticalRuler verticalRuler, IPreferenceStore preferenceStore, - StickyLinesProvider stickyLinesProvider) { + IStickyLinesProvider stickyLinesProvider) { this.sourceViewer= sourceViewer; throttler= new Throttler(sourceViewer.getTextWidget().getDisplay(), Duration.ofMillis(THROTTLER_DELAY), this::calculateAndShowStickyLines); this.stickyLinesProvider= stickyLinesProvider; - StickyScrollingControlSettings settings= loadAndListenForProperties(preferenceStore); + listenForPropertiesChanges(preferenceStore); + stickyLinesProperties= loadStickyLinesProperties(preferenceStore); + StickyScrollingControlSettings settings= loadControlSettings(preferenceStore); + stickyScrollingControl= new StickyScrollingControl(sourceViewer, verticalRuler, settings, this); sourceViewer.addViewportListener(this); } - private StickyScrollingControlSettings loadAndListenForProperties(IPreferenceStore store) { + private void listenForPropertiesChanges(IPreferenceStore store) { preferenceStore= store; propertyChangeListener= e -> { if (e.getProperty().equals(EDITOR_TAB_WIDTH) || e.getProperty().equals(EDITOR_STICKY_SCROLLING_MAXIMUM_COUNT) || e.getProperty().equals(EDITOR_CURRENT_LINE_COLOR) || e.getProperty().equals(EDITOR_LINE_NUMBER_RULER) || e.getProperty().equals(STICKY_LINES_SEPARATOR_COLOR)) { if (stickyScrollingControl != null && !sourceViewer.getTextWidget().isDisposed()) { - StickyScrollingControlSettings settings= loadSettings(preferenceStore); + StickyScrollingControlSettings settings= loadControlSettings(preferenceStore); stickyScrollingControl.applySettings(settings); - stickyLinesProvider.setTabWidth(tabWidth); + stickyLinesProperties= loadStickyLinesProperties(preferenceStore); } } }; store.addPropertyChangeListener(propertyChangeListener); - return loadSettings(store); } - private StickyScrollingControlSettings loadSettings(IPreferenceStore store) { - tabWidth= store.getInt(EDITOR_TAB_WIDTH); - + private StickyScrollingControlSettings loadControlSettings(IPreferenceStore store) { int stickyScrollingMaxCount= store.getInt(EDITOR_STICKY_SCROLLING_MAXIMUM_COUNT); Color lineNumberColor= new Color(PreferenceConverter.getColor(store, EDITOR_LINE_NUMBER_RULER_COLOR)); sourceViewer.getTextWidget().addDisposeListener(e -> lineNumberColor.dispose()); - Color stickyLineHoverColor= new Color(PreferenceConverter.getColor(store, EDITOR_CURRENT_LINE_COLOR)); sourceViewer.getTextWidget().addDisposeListener(e -> stickyLineHoverColor.dispose()); - Color stickyLineBackgroundColor= sourceViewer.getTextWidget().getBackground(); - boolean showLineNumbers= store.getBoolean(EDITOR_LINE_NUMBER_RULER); - Color stickyLineSeparatorColor= null; if (EditorsPlugin.getDefault() != null) { RGB rgb= PreferenceConverter.getColor(store, STICKY_LINES_SEPARATOR_COLOR); ISharedTextColors sharedTextColors= EditorsPlugin.getDefault().getSharedTextColors(); stickyLineSeparatorColor= sharedTextColors.getColor(rgb); } - return new StickyScrollingControlSettings(stickyScrollingMaxCount, lineNumberColor, stickyLineHoverColor, stickyLineBackgroundColor, stickyLineSeparatorColor, showLineNumbers); } + private StickyLinesProperties loadStickyLinesProperties(IPreferenceStore store) { + int tabWidth= store.getInt(EDITOR_TAB_WIDTH); + return new StickyLinesProperties(tabWidth); + } + @Override public void viewportChanged(int newVerticalOffset) { if (this.verticalOffset == newVerticalOffset) { @@ -148,7 +151,10 @@ public void viewportChanged(int newVerticalOffset) { } private void calculateAndShowStickyLines() { - List stickyLines= stickyLinesProvider.get(verticalOffset, sourceViewer); + List stickyLines= stickyLinesProvider.getStickyLines(sourceViewer, stickyLinesProperties); + if (stickyLines == null) { + stickyLines= Collections.emptyList(); + } stickyScrollingControl.setStickyLines(stickyLines); } diff --git a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java index 66cda995575..29593243ade 100644 --- a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java +++ b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java @@ -21,7 +21,7 @@ import org.eclipse.jface.text.tests.codemining.CodeMiningTest; -import org.eclipse.ui.internal.texteditor.stickyscroll.StickyLinesProviderTest; +import org.eclipse.ui.internal.texteditor.stickyscroll.DefaultStickyLinesProviderTest; import org.eclipse.ui.internal.texteditor.stickyscroll.StickyScrollingControlTest; import org.eclipse.ui.internal.texteditor.stickyscroll.StickyScrollingHandlerTest; @@ -49,7 +49,7 @@ StickyScrollingControlTest.class, StickyScrollingHandlerTest.class, - StickyLinesProviderTest.class, + DefaultStickyLinesProviderTest.class, CodeMiningTest.class, }) diff --git a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLinesProviderTest.java b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/DefaultStickyLinesProviderTest.java similarity index 75% rename from tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLinesProviderTest.java rename to tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/DefaultStickyLinesProviderTest.java index 8e1bc8bae91..5e9fd440589 100644 --- a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLinesProviderTest.java +++ b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/DefaultStickyLinesProviderTest.java @@ -34,26 +34,28 @@ import org.eclipse.jface.text.source.IVerticalRuler; import org.eclipse.jface.text.source.SourceViewer; -public class StickyLinesProviderTest { +import org.eclipse.ui.internal.texteditor.stickyscroll.IStickyLinesProvider.StickyLinesProperties; + +public class DefaultStickyLinesProviderTest { private Shell shell; private SourceViewer sourceViewer; - private StickyLinesProvider stickyLinesProvider; + private DefaultStickyLinesProvider stickyLinesProvider; private StyledText textWidget; - - private static final int CALCULATE = 1; + private StickyLinesProperties stickyLinesProperties; @Before public void setup() { shell = new Shell(Display.getDefault()); sourceViewer = new SourceViewer(shell, null, SWT.None); - stickyLinesProvider = new StickyLinesProvider(); + stickyLinesProvider = new DefaultStickyLinesProvider(); textWidget = sourceViewer.getTextWidget(); + stickyLinesProperties = new StickyLinesProperties(4); } @Test public void testEmptySourceCode() { - List stickyLines = stickyLinesProvider.get(0, sourceViewer); + List stickyLines = stickyLinesProvider.getStickyLines(sourceViewer, stickyLinesProperties); assertThat(stickyLines, is(empty())); } @@ -65,7 +67,7 @@ public void testSingleStickyLine() { line 2<"""; setText(text); - List stickyLines = stickyLinesProvider.get(CALCULATE, sourceViewer); + List stickyLines = stickyLinesProvider.getStickyLines(sourceViewer, stickyLinesProperties); assertThat(stickyLines, contains(new StickyLine("line 1", 0))); } @@ -79,7 +81,7 @@ public void testLineUnderStickyLine() { line 4"""; setText(text); - List stickyLines = stickyLinesProvider.get(CALCULATE, sourceViewer); + List stickyLines = stickyLinesProvider.getStickyLines(sourceViewer, stickyLinesProperties); assertThat(stickyLines, contains(new StickyLine("line 1", 0), new StickyLine(" line 2<", 1))); } @@ -93,7 +95,7 @@ public void testNewStickyRoot() { line 4<"""; setText(text); - List stickyLines = stickyLinesProvider.get(CALCULATE, sourceViewer); + List stickyLines = stickyLinesProvider.getStickyLines(sourceViewer, stickyLinesProperties); assertThat(stickyLines, contains(new StickyLine("line 3", 2))); } @@ -108,21 +110,21 @@ public void testIgnoreEmptyLines() { line 3<"""; setText(text); - List stickyLines = stickyLinesProvider.get(CALCULATE, sourceViewer); + List stickyLines = stickyLinesProvider.getStickyLines(sourceViewer, stickyLinesProperties); assertThat(stickyLines, contains(new StickyLine("line 1", 0), new StickyLine(" line 2", 2))); } @Test public void testLinesWithTabs() { - stickyLinesProvider.setTabWidth(2); + stickyLinesProperties = new StickyLinesProperties(2); String text = """ line 1 \tline 2 \t\tline 3<"""; setText(text); - List stickyLines = stickyLinesProvider.get(CALCULATE, sourceViewer); + List stickyLines = stickyLinesProvider.getStickyLines(sourceViewer, stickyLinesProperties); assertThat(stickyLines, contains(new StickyLine("line 1", 0), new StickyLine("\tline 2", 1))); @@ -139,7 +141,7 @@ public void testStartAtEmptyLineWithNext() { textWidget.setText(text); textWidget.setTopIndex(3); - List stickyLines = stickyLinesProvider.get(CALCULATE, sourceViewer); + List stickyLines = stickyLinesProvider.getStickyLines(sourceViewer, stickyLinesProperties); assertThat(stickyLines, contains(new StickyLine("line 1", 0), new StickyLine(" line 2", 2))); @@ -154,7 +156,7 @@ public void testStartAtEmptyLineWithPrevious() { line 4"""; setText(text); - List stickyLines = stickyLinesProvider.get(CALCULATE, sourceViewer); + List stickyLines = stickyLinesProvider.getStickyLines(sourceViewer, stickyLinesProperties); assertThat(stickyLines, contains(new StickyLine("line 1", 0))); } @@ -168,7 +170,7 @@ public void testRemoveStickyLines() { line 4<"""; setText(text); - List stickyLines = stickyLinesProvider.get(CALCULATE, sourceViewer); + List stickyLines = stickyLinesProvider.getStickyLines(sourceViewer, stickyLinesProperties); assertThat(stickyLines, contains(new StickyLine("line 3", 2))); } @@ -183,7 +185,7 @@ public void testSourceViewerWithDifferentModelAndWindgetLines() { line 2<"""; setText(text); - List stickyLines = stickyLinesProvider.get(CALCULATE, sourceViewer); + List stickyLines = stickyLinesProvider.getStickyLines(sourceViewer, stickyLinesProperties); assertThat(stickyLines, contains(new StickyLine("line 1", 42))); } diff --git a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandlerTest.java b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandlerTest.java index 3ac679d012f..5d82241ae01 100644 --- a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandlerTest.java +++ b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandlerTest.java @@ -48,6 +48,8 @@ import org.eclipse.jface.text.source.CompositeRuler; import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.ui.internal.texteditor.stickyscroll.IStickyLinesProvider.StickyLinesProperties; + public class StickyScrollingHandlerTest { private Shell shell; @@ -56,8 +58,9 @@ public class StickyScrollingHandlerTest { private Color hoverColor; private CompositeRuler ruler; private IPreferenceStore store; - private StickyLinesProvider linesProvider; + private IStickyLinesProvider linesProvider; private StickyScrollingHandler stickyScrollingHandler; + private StickyLinesProperties stickyLinesProperties; @Before public void setup() { @@ -71,9 +74,10 @@ public void setup() { hoverColor = new Color(1, 1, 1); store = createPreferenceStore(); - linesProvider = mock(StickyLinesProvider.class); + linesProvider = mock(IStickyLinesProvider.class); stickyScrollingHandler = new StickyScrollingHandler(sourceViewer, ruler, store, linesProvider); + stickyLinesProperties = new StickyLinesProperties(4); } @After @@ -83,7 +87,8 @@ public void teardown() { @Test public void testShowStickyLines() { - when(linesProvider.get(100, sourceViewer)).thenReturn(List.of(new StickyLine("line 10", 9))); + when(linesProvider.getStickyLines(sourceViewer, stickyLinesProperties)) + .thenReturn(List.of(new StickyLine("line 10", 9))); stickyScrollingHandler.viewportChanged(100); @@ -106,7 +111,8 @@ public void testUnistallStickyLines() { @Test public void testPreferencesLoaded() { - when(linesProvider.get(100, sourceViewer)).thenReturn(List.of(new StickyLine("line 10", 9))); + when(linesProvider.getStickyLines(sourceViewer, stickyLinesProperties)) + .thenReturn(List.of(new StickyLine("line 10", 9))); stickyScrollingHandler.viewportChanged(100); @@ -116,7 +122,7 @@ public void testPreferencesLoaded() { @Test public void testPreferencesUpdated() { - when(linesProvider.get(100, sourceViewer)) + when(linesProvider.getStickyLines(sourceViewer, stickyLinesProperties)) .thenReturn(List.of(new StickyLine("line 10", 9), new StickyLine("line 20", 19))); stickyScrollingHandler.viewportChanged(100); @@ -134,10 +140,14 @@ public void testPreferencesUpdated() { @Test public void testThrottledExecution() throws InterruptedException { - when(linesProvider.get(100, sourceViewer)).thenReturn(List.of(new StickyLine("line 10", 9))); - when(linesProvider.get(200, sourceViewer)).thenReturn(List.of(new StickyLine("line 10", 9))); - when(linesProvider.get(300, sourceViewer)).thenReturn(List.of(new StickyLine("line 10", 9))); - when(linesProvider.get(400, sourceViewer)).thenReturn(List.of(new StickyLine("line 10", 9))); + when(linesProvider.getStickyLines(sourceViewer, stickyLinesProperties)) + .thenReturn(List.of(new StickyLine("line 10", 9))); + when(linesProvider.getStickyLines(sourceViewer, stickyLinesProperties)) + .thenReturn(List.of(new StickyLine("line 10", 9))); + when(linesProvider.getStickyLines(sourceViewer, stickyLinesProperties)) + .thenReturn(List.of(new StickyLine("line 10", 9))); + when(linesProvider.getStickyLines(sourceViewer, stickyLinesProperties)) + .thenReturn(List.of(new StickyLine("line 10", 9))); stickyScrollingHandler.viewportChanged(100); Thread.sleep(10); @@ -150,10 +160,7 @@ public void testThrottledExecution() throws InterruptedException { waitInUi(300); // Call to lines provider should be throttled - verify(linesProvider, times(1)).get(100, sourceViewer); - verify(linesProvider, times(0)).get(200, sourceViewer); - verify(linesProvider, times(0)).get(300, sourceViewer); - verify(linesProvider, times(1)).get(400, sourceViewer); + verify(linesProvider, times(2)).getStickyLines(sourceViewer, stickyLinesProperties); } private void waitInUi(int ms) throws InterruptedException {