Skip to content

Commit

Permalink
Part of PIVOT-696: Add support for viewing tab characters in TextArea.
Browse files Browse the repository at this point in the history
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
Roger Lee Whitcomb committed Nov 16, 2012
1 parent 0ba3f2c commit 57bc1ec
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion wtk/src/org/apache/pivot/wtk/TextArea.java
Expand Up @@ -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++;
Expand Down Expand Up @@ -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();

Expand All @@ -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++;
}
}

Expand Down

0 comments on commit 57bc1ec

Please sign in to comment.