-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move text and style calculation to StickyLine
- Loading branch information
1 parent
86b314e
commit d75a726
Showing
8 changed files
with
258 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...g.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/IStickyLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/******************************************************************************* | ||
* 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 org.eclipse.swt.custom.StyleRange; | ||
|
||
/** | ||
* Representation of a sticky line. | ||
*/ | ||
public interface IStickyLine { | ||
|
||
/** | ||
* Returns the line number of the sticky line. | ||
* | ||
* @return the line number of the sticky line | ||
*/ | ||
int getLineNumber(); | ||
|
||
/** | ||
* Returns the text of the sticky line. | ||
* | ||
* @return the text of the sticky line | ||
*/ | ||
String getText(); | ||
|
||
/** | ||
* Returns the style ranges of the sticky line. | ||
* | ||
* @return the style ranges of the sticky line | ||
*/ | ||
StyleRange[] getStyleRanges(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
....ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLineTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/******************************************************************************* | ||
* 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 static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.custom.StyleRange; | ||
import org.eclipse.swt.custom.StyledText; | ||
import org.eclipse.swt.graphics.Color; | ||
import org.eclipse.swt.widgets.Shell; | ||
|
||
public class StickyLineTest { | ||
|
||
private Shell shell; | ||
private StyledText textWidget; | ||
private Color color; | ||
|
||
@Before | ||
public void setUp() { | ||
shell = new Shell(); | ||
textWidget = new StyledText(shell, SWT.NONE); | ||
color = new Color(0, 0, 0); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
shell.dispose(); | ||
color.dispose(); | ||
} | ||
|
||
@Test | ||
public void testGetLineNumber() { | ||
StickyLine stickyLine = new StickyLine(1, textWidget); | ||
|
||
assertEquals(1, stickyLine.getLineNumber()); | ||
} | ||
|
||
@Test | ||
public void testGetText() { | ||
textWidget.setText("line1\nline2\nline3"); | ||
StickyLine stickyLine = new StickyLine(1, textWidget); | ||
|
||
assertEquals("line2", stickyLine.getText()); | ||
} | ||
|
||
@Test | ||
public void testGetStyleRanges() { | ||
textWidget.setText("line1\nline2\nline3"); | ||
|
||
// line1 | ||
textWidget.setStyleRange(new StyleRange(2, 1, color, null)); | ||
|
||
// line2 | ||
textWidget.setStyleRange(new StyleRange(6, 1, color, null)); | ||
textWidget.setStyleRange(new StyleRange(8, 2, color, null)); | ||
|
||
// line3 | ||
textWidget.setStyleRange(new StyleRange(15, 1, color, null)); | ||
|
||
StickyLine stickyLine = new StickyLine(1, textWidget); | ||
StyleRange[] styleRanges = stickyLine.getStyleRanges(); | ||
|
||
assertEquals(2, styleRanges.length); | ||
assertEquals(0, styleRanges[0].start); | ||
assertEquals(1, styleRanges[0].length); | ||
assertEquals(2, styleRanges[1].start); | ||
assertEquals(2, styleRanges[1].length); | ||
} | ||
|
||
} |
Oops, something went wrong.