Author: rwhitcomb Date: Fri Nov 16 20:20:02 2012 New Revision: 1410556 URL: http://svn.apache.org/viewvc?rev=1410556&view=rev Log: 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. This is a merge of revision 1410555 from trunk to branches/2.0.x. Modified: pivot/branches/2.0.x/ (props changed) pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/TextArea.java Propchange: pivot/branches/2.0.x/ ------------------------------------------------------------------------------ Merged /pivot/trunk:r1410555 Modified: pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/TextArea.java URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/TextArea.java?rev=1410556&r1=1410555&r2=1410556&view=diff ============================================================================== --- pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/TextArea.java (original) +++ pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/TextArea.java Fri Nov 16 20:20:02 2012 @@ -735,8 +735,8 @@ public class TextArea extends Component 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 @@ public class TextArea extends Component 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 @@ public class TextArea extends Component 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++; } }