Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Part of PIVOT-696: Add a property to control whether tabs are expanded

to spaces during program operations (that is, "setText" and "insertText"):

get/setExpandTabs()

The default value is false, which will restore the previous functionality.


git-svn-id: https://svn.apache.org/repos/asf/pivot/trunk@1417258 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit d7d549051bbd351b4a681642a8dea57a86bc08e1 1 parent d5079f6
Roger Lee Whitcomb authored
Showing with 25 additions and 2 deletions.
  1. +25 −2 wtk/src/org/apache/pivot/wtk/TextArea.java
View
27 wtk/src/org/apache/pivot/wtk/TextArea.java
@@ -580,6 +580,8 @@ public void textBindMappingChanged(TextArea textArea, TextBindMapping previousTe
private int selectionStart = 0;
private int selectionLength = 0;
+ private boolean expandTabs = false;
+
private int maximumLength = Integer.MAX_VALUE;
private boolean editable = true;
@@ -728,7 +730,7 @@ public void setText(Reader textReader) throws IOException {
paragraphsLocal.add(paragraph);
paragraph = new Paragraph();
tabPosition = 0;
- } else if (c == '\t') {
+ } else if (c == '\t' && expandTabs) {
int spaces = tabWidth - (tabPosition % tabWidth);
for (int i = 0; i < spaces; i++) {
if (++characterCountLocal > maximumLength) {
@@ -798,7 +800,7 @@ private void insertText(CharSequence text, int index, boolean addToEditHistory)
tabPosition = 0;
textBuilder = new StringBuilder();
- } else if (c == '\t') {
+ } else if (c == '\t' && expandTabs) {
int spaces = tabWidth - (tabPosition % tabWidth);
for (int j = 0; j < spaces; j++) {
textBuilder.append(' ');
@@ -1241,6 +1243,27 @@ public void clear() {
}
}
+ public boolean getExpandTabs() {
+ return expandTabs;
+ }
+
+ /**
+ * Sets whether tab characters (<code>\t</code>) are expanded to
+ * an appropriate number of spaces during {@link #setText} and
+ * {@link #insertText} operations.
+ * @param expandTabs <code>true</code> to replace tab characters
+ * with space characters (depending on the
+ * setting of the {@link TextArea.Skin#getTabWidth}
+ * value) or <code>false</code> to leave tabs alone.
+ * Note: this only affects tabs encountered during
+ * program operations; tabs entered via the keyboard
+ * by the user are always expanded, regardless of
+ * this setting.
+ */
+ public void setExpandTabs(boolean expandTabs) {
+ this.expandTabs = expandTabs;
+ }
+
public int getInsertionPoint(int x, int y) {
TextArea.Skin textAreaSkin = (TextArea.Skin)getSkin();
return textAreaSkin.getInsertionPoint(x, y);
Please sign in to comment.
Something went wrong with that request. Please try again.