Author: rwhitcomb Date: Fri Nov 16 20:18:20 2012 New Revision: 1410555 URL: http://svn.apache.org/viewvc?rev=1410555&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. Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java?rev=1410555&r1=1410554&r2=1410555&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Fri Nov 16 20:18:20 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++; } }