Permalink
Browse files

Part of PIVOT-696: Add support for viewing tab characters in TextArea.

Already the TerraTextAreaSkin has a "tabWidth" style, and supports
Ctrl-Tab entering a "tab" which is a number of spaces up to the tab
width.

The previous change added conversion of tab to spaces in "setText".
This change extends that to "insertText", so that (in particular)
"paste" looks right too.


git-svn-id: https://svn.apache.org/repos/asf/pivot/trunk@1410555 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 0ba3f2c commit 57bc1ec166df72fd87b2fcd0945116d9099ba9d4 Roger Lee Whitcomb committed Nov 16, 2012
Showing with 11 additions and 1 deletion.
  1. +11 −1 wtk/src/org/apache/pivot/wtk/TextArea.java
@@ -735,8 +735,8 @@ public void setText(Reader textReader) throws IOException {
throw new IllegalArgumentException("Text length is greater than maximum length.");
}
paragraph.append(' ');
- tabPosition++;
}
+ tabPosition += spaces;
} else {
paragraph.append((char)c);
tabPosition++;
@@ -775,6 +775,8 @@ private void insertText(CharSequence text, int index, boolean addToEditHistory)
Paragraph paragraph = paragraphs.get(paragraphIndex);
int characterOffset = index - paragraph.offset;
+ int tabPosition = characterOffset;
+ int tabWidth = ((TextArea.Skin)getSkin()).getTabWidth();
StringBuilder textBuilder = new StringBuilder();
@@ -793,11 +795,19 @@ private void insertText(CharSequence text, int index, boolean addToEditHistory)
paragraph.insertText(trailingCharacters, 0);
paragraphSequence.insert(paragraph, ++paragraphIndex);
characterOffset = 0;
+ tabPosition = 0;
textBuilder = new StringBuilder();
+ } else if (c == '\t') {
+ int spaces = tabWidth - (tabPosition % tabWidth);
+ for (int j = 0; j < spaces; j++) {
+ textBuilder.append(' ');
+ }
+ tabPosition += spaces;
} else {
// Append character
textBuilder.append(c);
+ tabPosition++;
}
}

0 comments on commit 57bc1ec

Please sign in to comment.