/** * Calculates the indexes of each line in the text store. Assumes no gap * exists. Optimized to do less checking. */ void indexLines() { int start = 0; this.lineCount = 0; int textLength = this.textStore.length; int i; for (i = start; i < textLength; i++) { char ch = this.textStore[i]; if (ch == SWT.CR) { // see if the next character is a LF if (i + 1 < textLength) { ch = this.textStore[i + 1]; if (ch == SWT.LF) { i++; } } addLineIndex(start, i - start + 1); start = i + 1; } else if (ch == SWT.LF) { addLineIndex(start, i - start + 1); start = i + 1; } } addLineIndex(start, i - start); }
return; int startLine = getLineAtOffset(position); int change = text.length(); boolean endInsert = position == getCharCount(); adjustGap(position, change, startLine); int startLineOffset = getOffsetAtLine(startLine); int startLineLength = getPhysicalLine(startLine).length(); int[][] newLines = indexLines(startLineOffset, startLineLength, 10); expandLinesBy(numNewLines); this.gapLine = getLineAtPhysicalOffset(this.gapStart);
/** * Returns the line at the given index with delimiters. * <p> * * @param index * the index of the line to return * @return the logical line text (i.e., without the gap) with delimiters */ String getFullLine(int index) { int start = this.lines[index][0]; int length = this.lines[index][1]; int end = start + length - 1; if (!gapExists() || (end < this.gapStart) || (start >= this.gapEnd)) { // line is before or after the gap return new String(this.textStore, start, length); } else { // gap is in the specified range, strip out the gap StringBuffer buffer = new StringBuffer(); int gapLength = this.gapEnd - this.gapStart; buffer.append(this.textStore, start, this.gapStart - start); buffer.append(this.textStore, this.gapEnd, length - gapLength - (this.gapStart - start)); return buffer.toString(); } }
return; int startLine = getLineAtOffset(position); int startLineOffset = getOffsetAtLine(startLine); int endLine = getLineAtOffset(position + length); if (position + length < getCharCount()) { endText = getTextRange(position + length - 1, 2); if ((endText.charAt(0) == SWT.CR) && (endText.charAt(1) == SWT.LF)) { splittingDelimiter = true; adjustGap(position + length, -length, startLine); int[][] oldLines = indexLines(position, length + (this.gapEnd - this.gapStart), numLines); if (j < this.gapStart || j >= this.gapEnd) { char ch = this.textStore[j]; if (isDelimiter(ch)) { if (j + 1 < this.textStore.length) { if (ch == SWT.CR && (this.textStore[j + 1] == SWT.LF)) { this.gapLine = getLineAtPhysicalOffset(this.gapStart);
if (start == getCharCount()) return true; char before = getTextRange(start - 1, 1).charAt(0); if (before == '\r') { char after = getTextRange(start, 1).charAt(0); if (after == '\n') return false; char startChar = getTextRange(start, 1).charAt(0); if (startChar == '\n') { char before = getTextRange(start - 1, 1).charAt(0); if (before == '\r') return false; char endChar = getTextRange(start + replaceLength - 1, 1).charAt(0); if (endChar == '\r') { if (start + replaceLength != getCharCount()) { char after = getTextRange(start + replaceLength, 1).charAt(0); if (after == '\n') return false;
public void replaceTextRange(int start, int replaceLength, String newText) { if (!isValidReplace(start, replaceLength, newText)) throw new IllegalArgumentException(); TextChangingEvent event = TextChangingEvent.textChanging(this, start, replaceLength, lineCount(start, replaceLength), newText, newText.length(), lineCount(newText)); for (TextChangeListener l : this.textListeners) { l.textChanging(event); delete(start, replaceLength, event.replaceLineCount + 1); insert(start, newText); l.textChanged(textChanged); System.err.println(getTextRange(0, getCharCount()));
public void replaceTextRange(int start, int replaceLength, String newText) { if (!isValidReplace(start, replaceLength, newText)) throw new IllegalArgumentException(); TextChangingEvent event = TextChangingEvent.textChanging(this, start, replaceLength, lineCount(start, replaceLength), newText, newText.length(), lineCount(newText)); for (TextChangeListener l : this.textListeners) { l.textChanging(event); delete(start, replaceLength, event.replaceLineCount + 1); insert(start, newText);
int length = this.lines[index][1]; int end = start + length - 1; if (!gapExists() || (end < this.gapStart) || (start >= this.gapEnd)) { while ((length - 1 >= 0) && isDelimiter(this.textStore[start + length - 1])) { length--; buf.append(this.textStore, this.gapEnd, length - gapLength - (this.gapStart - start)); length = buf.length(); while ((length - 1 >= 0) && isDelimiter(buf.charAt(length - 1))) { length--;
/** * Create a new control */ public StyledTextArea() { this.getStyleClass().add("styled-text-area"); //$NON-NLS-1$ this.contentProperty = new ContentProperty(this, "content", new DefaultContent()); //$NON-NLS-1$ setFocusTraversable(true); }
if ((charPosition > getCharCount()) || (charPosition < 0)) throw new IllegalArgumentException(); int position;
return; int startLine = getLineAtOffset(position); int startLineOffset = getOffsetAtLine(startLine); int endLine = getLineAtOffset(position + length); if (position + length < getCharCount()) { endText = getTextRange(position + length - 1, 2); if ((endText.charAt(0) == SWT.CR) && (endText.charAt(1) == SWT.LF)) { splittingDelimiter = true; adjustGap(position + length, -length, startLine); int[][] oldLines = indexLines(position, length + (this.gapEnd - this.gapStart), numLines); if (j < this.gapStart || j >= this.gapEnd) { char ch = this.textStore[j]; if (isDelimiter(ch)) { if (j + 1 < this.textStore.length) { if (ch == SWT.CR && (this.textStore[j + 1] == SWT.LF)) { this.gapLine = getLineAtPhysicalOffset(this.gapStart);
int length = this.lines[index][1]; int end = start + length - 1; if (!gapExists() || (end < this.gapStart) || (start >= this.gapEnd)) { while ((length - 1 >= 0) && isDelimiter(this.textStore[start + length - 1])) { length--; buf.append(this.textStore, this.gapEnd, length - gapLength - (this.gapStart - start)); length = buf.length(); while ((length - 1 >= 0) && isDelimiter(buf.charAt(length - 1))) { length--;
if (start == getCharCount()) return true; char before = getTextRange(start - 1, 1).charAt(0); if (before == '\r') { char after = getTextRange(start, 1).charAt(0); if (after == '\n') return false; char startChar = getTextRange(start, 1).charAt(0); if (startChar == '\n') { char before = getTextRange(start - 1, 1).charAt(0); if (before == '\r') return false; char endChar = getTextRange(start + replaceLength - 1, 1).charAt(0); if (endChar == '\r') { if (start + replaceLength != getCharCount()) { char after = getTextRange(start + replaceLength, 1).charAt(0); if (after == '\n') return false;
/** * Create a new control */ public StyledTextArea() { this.getStyleClass().add("styled-text-area"); //$NON-NLS-1$ this.contentProperty = new ContentProperty(this, "content", new DefaultContent()); //$NON-NLS-1$ setFocusTraversable(true); //FIXME This rules out the CSS-Setting! // we cannot change remove it because the dynamic zoom depends on it -.- DoubleBinding lineHeight = org.eclipse.fx.ui.controls.Util.createTextHeightBinding("Pj", fontProperty(), this.fontZoomFactor); //$NON-NLS-1$ fixedLineHeightProperty().bind(lineHeight.multiply(1.3)); }
if ((charPosition > getCharCount()) || (charPosition < 0)) throw new IllegalArgumentException(); int position;
return; int startLine = getLineAtOffset(position); int change = text.length(); boolean endInsert = position == getCharCount(); adjustGap(position, change, startLine); int startLineOffset = getOffsetAtLine(startLine); int startLineLength = getPhysicalLine(startLine).length(); int[][] newLines = indexLines(startLineOffset, startLineLength, 10); expandLinesBy(numNewLines); this.gapLine = getLineAtPhysicalOffset(this.gapStart);
/** * Returns the line at the given index with delimiters. * <p> * * @param index * the index of the line to return * @return the logical line text (i.e., without the gap) with delimiters */ String getFullLine(int index) { int start = this.lines[index][0]; int length = this.lines[index][1]; int end = start + length - 1; if (!gapExists() || (end < this.gapStart) || (start >= this.gapEnd)) { // line is before or after the gap return new String(this.textStore, start, length); } else { // gap is in the specified range, strip out the gap StringBuffer buffer = new StringBuffer(); int gapLength = this.gapEnd - this.gapStart; buffer.append(this.textStore, start, this.gapStart - start); buffer.append(this.textStore, this.gapEnd, length - gapLength - (this.gapStart - start)); return buffer.toString(); } }
/** * Calculates the indexes of each line in the text store. Assumes no gap * exists. Optimized to do less checking. */ void indexLines() { int start = 0; this.lineCount = 0; int textLength = this.textStore.length; int i; for (i = start; i < textLength; i++) { char ch = this.textStore[i]; if (ch == SWT.CR) { // see if the next character is a LF if (i + 1 < textLength) { ch = this.textStore[i + 1]; if (ch == SWT.LF) { i++; } } addLineIndex(start, i - start + 1); start = i + 1; } else if (ch == SWT.LF) { addLineIndex(start, i - start + 1); start = i + 1; } } addLineIndex(start, i - start); }
/** * Returns a string representing the logical content of the text store * (i.e., gap stripped out). * <p> * * @param start * the logical start offset of the text to return * @param length * the logical length of the text to return * @return the text */ @SuppressWarnings("null") @Override public String getTextRange(int start, int length) { if (this.textStore == null) return ""; //$NON-NLS-1$ if (length == 0) return ""; //$NON-NLS-1$ int end = start + length; if (!gapExists() || (end < this.gapStart)) return new String(this.textStore, start, length); if (this.gapStart < start) { int gapLength = this.gapEnd - this.gapStart; return new String(this.textStore, start + gapLength, length); } StringBuffer buf = new StringBuffer(); buf.append(this.textStore, start, this.gapStart - start); buf.append(this.textStore, this.gapEnd, end - this.gapStart); return buf.toString(); }
indexedLines = addLineIndex(start, i - start + 1, indexedLines, lineCount); lineCount++; start = i + 1; } else if (ch == SWT.LF) { indexedLines = addLineIndex(start, i - start + 1, indexedLines, lineCount); lineCount++; start = i + 1;