Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAparna Argade2019-05-24 08:15:18 -0400
committerPatrick Tasse2019-05-29 13:22:03 -0400
commite36ff52c3ce02f5e46489a543bb1d5de5d363035 (patch)
tree06a7f6e519a121380c9b504235e76731f811936b
parent6c054cd1e0c53bd3223332be02a4625bff423fe3 (diff)
downloadorg.eclipse.swtbot-e36ff52c3ce02f5e46489a543bb1d5de5d363035.tar.gz
org.eclipse.swtbot-e36ff52c3ce02f5e46489a543bb1d5de5d363035.tar.xz
org.eclipse.swtbot-e36ff52c3ce02f5e46489a543bb1d5de5d363035.zip
Bug 547624- StyledText.cursorPos should use getCaretOffset
After some text is selected, the caret actually points at the end of selection. But cursorPos API was returning start column of selection, because it was using x of selection range. The API now uses StyledText's getCaretOffset. Change-Id: I9ce73db82f6ab01e6ce2fa65a44486bf0f99431f Signed-off-by: Aparna Argade <aprsac@yahoo.com> Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
-rw-r--r--org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotStyledTextTest.java8
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotStyledText.java27
2 files changed, 14 insertions, 21 deletions
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotStyledTextTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotStyledTextTest.java
index b451ab0c..12ff67c9 100644
--- a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotStyledTextTest.java
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotStyledTextTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2018 Ketan Padegaonkar and others.
+ * Copyright (c) 2008, 2019 Ketan Padegaonkar and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -293,7 +293,7 @@ public class SWTBotStyledTextTest extends AbstractCustomControlExampleTest {
styledText.setText("This is sample text");
bot.button("Clear").click();
styledText.click(line, column, SWT.MOD2);
- assertEquals(new Position(0, 0), styledText.cursorPosition(true));
+ assertEquals(new Position(line, column), styledText.cursorPosition(true));
assertEquals("This is sample te", styledText.getSelection());
verifyNotifyClick(SWT.MOD2);
}
@@ -318,8 +318,8 @@ public class SWTBotStyledTextTest extends AbstractCustomControlExampleTest {
bot.button("Clear").click();
styledText.doubleClick(line, column);
// Default behavior: word is selected upon doubleClick, so cursor position needs
- // to be compared with start column of the word
- assertEquals(new Position(line, column - 1), styledText.cursorPosition(true));
+ // to be compared with end of the word
+ assertEquals(new Position(line, column + 1), styledText.cursorPosition(true));
assertEquals(styledText.getSelection(), "is");
verifyNotifyClick(0);
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotStyledText.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotStyledText.java
index 3f72fc8f..dbc0492a 100644
--- a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotStyledText.java
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotStyledText.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2018 Ketan Padegaonkar and others.
+ * Copyright (c) 2008, 2019 Ketan Padegaonkar and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -179,30 +179,23 @@ public class SWTBotStyledText extends AbstractSWTBotControl<StyledText> {
}
/**
- * Gets the current position of the cursor. The returned position will contain a 0-based line and column.
+ * Gets the current position of the cursor. The returned position will contain a
+ * 0-based line and column, with tabs counting as 1 column.
*
* @return the position of the cursor in the styled text.
* @see SWTBotStyledText#cursorPosition(boolean)
*/
public Position cursorPosition() {
- return syncExec(new Result<Position>() {
- @Override
- public Position run() {
- widget.setFocus();
- int offset = widget.getSelectionRange().x;
- int line = widget.getContent().getLineAtOffset(offset);
- int offsetAtLine = widget.getContent().getOffsetAtLine(line);
- int column = offset - offsetAtLine;
- return new Position(line, column);
- }
- });
+ return cursorPosition(false);
}
/**
- * Gets the current position of the cursor. The returned position will contain a 0-based line and column.
+ * Gets the current position of the cursor. The returned position will contain a
+ * 0-based line and column.
*
- * @param withTabWidth <code>true</code> if column in the returned position should consider tab width preference;
- * <code>false</code> if column in the returned position should count tab as 1.
+ * @param withTabWidth <code>true</code> if column in the returned position
+ * should consider tab width preference; <code>false</code>
+ * if column in the returned position should count tab as 1.
* @return the position of the cursor in the styled text.
* @since 2.8
*/
@@ -211,7 +204,7 @@ public class SWTBotStyledText extends AbstractSWTBotControl<StyledText> {
@Override
public Position run() {
widget.setFocus();
- int offset = widget.getSelectionRange().x;
+ int offset = widget.getCaretOffset();
int line = widget.getContent().getLineAtOffset(offset);
int offsetAtLine = widget.getContent().getOffsetAtLine(line);
int column = offset - offsetAtLine;

Back to the top