/** * Calculates the indexes of each line in the text store. Assumes no gap exists. * Optimized to do less checking. */ void indexLines(){ int start = 0; lineCount = 0; int textLength = textStore.length; int i; for (i = start; i < textLength; i++) { char ch = textStore[i]; if (ch == SWT.CR) { // see if the next character is a LF if (i + 1 < textLength) { ch = 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); } /**
if (text.length() == 0) 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); gapLine = getLineAtPhysicalOffset(gapStart);
if ((charPosition > getCharCount()) || (charPosition < 0)) error(SWT.ERROR_INVALID_ARGUMENT); int position; if (charPosition < gapStart) {
if (length == 0) 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 + (gapEnd - gapStart), numLines); if (j < gapStart || j >= gapEnd) { char ch = textStore[j]; if (isDelimiter(ch)) { if (j + 1 < textStore.length) { if (ch == SWT.CR && (textStore[j+1] == SWT.LF)) { gapLine = getLineAtPhysicalOffset(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)) SWT.error(SWT.ERROR_INVALID_ARGUMENT); event.type = ST.TextChanging; event.start = start; event.replaceLineCount = lineCount(start, replaceLength); event.text = newText; event.newLineCount = lineCount(newText); event.replaceCharCount = replaceLength; event.newCharCount = newText.length(); sendTextEvent(event); delete(start, replaceLength, event.replaceLineCount + 1); insert(start, newText); sendTextEvent(event);
if ((index >= lineCount) || (index < 0)) error(SWT.ERROR_INVALID_ARGUMENT); int start = lines[index][0]; int length = lines[index][1]; int end = start + length - 1; if (!gapExists() || (end < gapStart) || (start >= gapEnd)) { while ((length - 1 >= 0) && isDelimiter(textStore[start+length-1])) { length--; buf.append(textStore, gapEnd, length - gapLength - (gapStart - start)); length = buf.length(); while ((length - 1 >=0) && isDelimiter(buf.charAt(length - 1))) { length--;
/** * Returns the logical offset of the given line. * <p> * * @param lineIndex index of line * @return the logical starting offset of the line. When there are not any lines, * getOffsetAtLine(0) is a valid call that should answer 0. * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT when lineIndex is out of range</li> * </ul> */ public int getOffsetAtLine(int lineIndex) { if (lineIndex == 0) return 0; if ((lineIndex >= lineCount) || (lineIndex < 0)) error(SWT.ERROR_INVALID_ARGUMENT); int start = lines[lineIndex][0]; if (start > gapEnd) { return start - (gapEnd - gapStart); } else { return start; } } /**
/** * 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 = lines[index][0]; int length = lines[index][1]; int end = start + length - 1; if (!gapExists() || (end < gapStart) || (start >= gapEnd)) { // line is before or after the gap return new String(textStore, start, length); } else { // gap is in the specified range, strip out the gap StringBuffer buffer = new StringBuffer(); int gapLength = gapEnd - gapStart; buffer.append(textStore, start, gapStart - start); buffer.append(textStore, gapEnd, length - gapLength - (gapStart - start)); return buffer.toString(); } } /**
/** * Creates content change listeners and set the default content model. */ void installDefaultContent() { textChangeListener = new TextChangeListener() { public void textChanging(TextChangingEvent event) { handleTextChanging(event); } public void textChanged(TextChangedEvent event) { handleTextChanged(event); } public void textSet(TextChangedEvent event) { handleTextSet(event); } }; content = new DefaultContent(); content.addTextChangeListener(textChangeListener); } /**
if (length == 0) 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 + (gapEnd - gapStart), numLines); if (j < gapStart || j >= gapEnd) { char ch = textStore[j]; if (isDelimiter(ch)) { if (j + 1 < textStore.length) { if (ch == SWT.CR && (textStore[j+1] == SWT.LF)) { gapLine = getLineAtPhysicalOffset(gapStart);
public void replaceTextRange(int start, int replaceLength, String newText){ if (!isValidReplace(start, replaceLength, newText)) SWT.error(SWT.ERROR_INVALID_ARGUMENT); event.type = ST.TextChanging; event.start = start; event.replaceLineCount = lineCount(start, replaceLength); event.text = newText; event.newLineCount = lineCount(newText); event.replaceCharCount = replaceLength; event.newCharCount = newText.length(); sendTextEvent(event); delete(start, replaceLength, event.replaceLineCount + 1); insert(start, newText); sendTextEvent(event);
if ((index >= lineCount) || (index < 0)) error(SWT.ERROR_INVALID_ARGUMENT); int start = lines[index][0]; int length = lines[index][1]; int end = start + length - 1; if (!gapExists() || (end < gapStart) || (start >= gapEnd)) { while ((length - 1 >= 0) && isDelimiter(textStore[start+length-1])) { length--; buf.append(textStore, gapEnd, length - gapLength - (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;
/** * Returns the logical offset of the given line. * <p> * * @param lineIndex index of line * @return the logical starting offset of the line. When there are not any lines, * getOffsetAtLine(0) is a valid call that should answer 0. * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT when lineIndex is out of range</li> * </ul> */ @Override public int getOffsetAtLine(int lineIndex) { if (lineIndex == 0) return 0; if ((lineIndex >= lineCount) || (lineIndex < 0)) error(SWT.ERROR_INVALID_ARGUMENT); int start = lines[lineIndex][0]; if (start > gapEnd) { return start - (gapEnd - gapStart); } else { return start; } } /**
/** * 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 = lines[index][0]; int length = lines[index][1]; int end = start + length - 1; if (!gapExists() || (end < gapStart) || (start >= gapEnd)) { // line is before or after the gap return new String(textStore, start, length); } else { // gap is in the specified range, strip out the gap StringBuffer buffer = new StringBuffer(); int gapLength = gapEnd - gapStart; buffer.append(textStore, start, gapStart - start); buffer.append(textStore, gapEnd, length - gapLength - (gapStart - start)); return buffer.toString(); } } /**
/** * Creates content change listeners and set the default content model. */ void installDefaultContent() { textChangeListener = new TextChangeListener() { @Override public void textChanging(TextChangingEvent event) { handleTextChanging(event); } @Override public void textChanged(TextChangedEvent event) { handleTextChanged(event); } @Override public void textSet(TextChangedEvent event) { handleTextSet(event); } }; content = new DefaultContent(); content.addTextChangeListener(textChangeListener); } /**
if (text.length() == 0) 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); gapLine = getLineAtPhysicalOffset(gapStart);
if (length == 0) 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 + (gapEnd - gapStart), numLines); if (j < gapStart || j >= gapEnd) { char ch = textStore[j]; if (isDelimiter(ch)) { if (j + 1 < textStore.length) { if (ch == SWT.CR && (textStore[j+1] == SWT.LF)) { gapLine = getLineAtPhysicalOffset(gapStart);
public void replaceTextRange(int start, int replaceLength, String newText){ if (!isValidReplace(start, replaceLength, newText)) SWT.error(SWT.ERROR_INVALID_ARGUMENT); event.type = ST.TextChanging; event.start = start; event.replaceLineCount = lineCount(start, replaceLength); event.text = newText; event.newLineCount = lineCount(newText); event.replaceCharCount = replaceLength; event.newCharCount = newText.length(); sendTextEvent(event); delete(start, replaceLength, event.replaceLineCount + 1); insert(start, newText); sendTextEvent(event);