1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00

Fix for bugzilla bug 24648 - Editor displaying text in reverse on Eclipse 2.1 platform

This commit is contained in:
Judy N. Green 2002-12-11 15:37:31 +00:00
parent d783a4c703
commit 4d7d5904b5
2 changed files with 138 additions and 123 deletions

View file

@ -1,3 +1,11 @@
2002-12-11 Judy N Green
* src/org/eclipse/cdt/internal/ui/text/BufferedDocumentScanner.java
Fix for the backwards display of typed text when the CDT ran within
Eclipse 2.1.
Patch submitted by Ed Burnette.
Tested on M1, 2.1 (20021204 integration build) and 2.0.1
Bugzilla Bug 24648
2002-12-11 Alain Magloire
Fix PR 27937. NPE in the C Editor preference page.

View file

@ -15,138 +15,145 @@ import org.eclipse.jface.util.Assert;
*/
public final class BufferedDocumentScanner implements ICharacterScanner {
/** The document being scanned. */
private IDocument fDocument;
/** The offset of the document range to scan. */
private int fRangeOffset;
/** The length of the document range to scan. */
private int fRangeLength;
/** The delimiters of the document. */
private char[][] fDelimiters;
/** The buffer. */
private final char[] fBuffer;
/** The offset of the buffer within the document. */
private int fBufferOffset;
/** The valid length of the buffer for access. */
private int fBufferLength;
/** The offset of the scanner within the buffer. */
private int fOffset;
/**
* Creates a new buffered document scanner.
* The buffer size is set to the given number of characters.
*
* @param size the buffer size
*/
public BufferedDocumentScanner(int size) {
Assert.isTrue(size >= 1);
fBuffer= new char[size];
}
/**
* Fills the buffer with the contens of the document starting at the given offset.
*
* @param offset the document offset at which the buffer starts
*/
private final void updateBuffer(int offset) {
/** The document being scanned. */
private IDocument fDocument;
/** The offset of the document range to scan. */
private int fRangeOffset;
/** The length of the document range to scan. */
private int fRangeLength;
/** The delimiters of the document. */
private char[][] fDelimiters;
/** The buffer. */
private final char[] fBuffer;
/** The offset of the buffer within the document. */
private int fBufferOffset;
/** The valid length of the buffer for access. */
private int fBufferLength;
/** The offset of the scanner within the buffer. */
private int fOffset;
/**
* Creates a new buffered document scanner.
* The buffer size is set to the given number of characters.
*
* @param size the buffer size
*/
public BufferedDocumentScanner(int size) {
Assert.isTrue(size >= 1);
fBuffer= new char[size];
}
/**
* Fills the buffer with the contents of the document starting at the given offset.
*
* @param offset the document offset at which the buffer starts
*/
private final void updateBuffer(int offset) {
// Clamp at start of the file document range
if (offset < 0)
offset = 0;
fBufferOffset= offset;
fBufferOffset= offset;
fBufferLength= fBuffer.length;
// assert(offset >= fRangeOffset && offset < fRangeOffset + fRangeLength);
if (fBufferOffset + fBuffer.length > fRangeLength)
fBufferLength= fRangeLength - fBufferOffset;
else
fBufferLength= fBuffer.length;
try {
final String content= fDocument.get(fBufferOffset, fBufferLength);
content.getChars(0, fBufferLength, fBuffer, 0);
} catch (BadLocationException e) {
}
}
/**
* Configures the scanner by providing access to the document range over which to scan.
*
* @param document the document to scan
* @param offset the offset of the document range to scan
* @param length the length of the document range to scan
*/
public final void setRange(IDocument document, int offset, int length) {
if (fBufferOffset + fBufferLength > fRangeOffset + fRangeLength)
fBufferLength= fRangeOffset + fRangeLength - fBufferOffset;
try {
final String content= fDocument.get(fBufferOffset, fBufferLength);
content.getChars(0, fBufferLength, fBuffer, 0);
} catch (BadLocationException e) {
}
}
/**
* Configures the scanner by providing access to the document range over which to scan.
*
* @param document the document to scan
* @param offset the offset of the document range to scan
* @param length the length of the document range to scan
*/
public final void setRange(IDocument document, int offset, int length) {
fDocument= document;
fRangeOffset= offset;
fRangeLength= length;
fDocument= document;
fRangeOffset= offset;
fRangeLength= length;
// Clamp at end of the real document
if (fRangeLength > fDocument.getLength())
fRangeLength = fDocument.getLength();
String[] delimiters= document.getLegalLineDelimiters();
fDelimiters= new char[delimiters.length][];
for (int i= 0; i < delimiters.length; i++)
fDelimiters[i]= delimiters[i].toCharArray();
String[] delimiters= document.getLegalLineDelimiters();
fDelimiters= new char[delimiters.length][];
for (int i= 0; i < delimiters.length; i++)
fDelimiters[i]= delimiters[i].toCharArray();
updateBuffer(offset);
fOffset= 0;
}
/*
* @see ICharacterScanner#read()
*/
public final int read() {
if (fOffset == fBufferLength) {
if (fBufferOffset + fBufferLength == fDocument.getLength())
return EOF;
else {
updateBuffer(fBufferOffset + fBufferLength);
fOffset= 0;
}
}
return fBuffer[fOffset++];
}
/*
* @see ICharacterScanner#unread
*/
public final void unread() {
updateBuffer(offset);
fOffset= 0;
}
/*
* @see ICharacterScanner#read()
*/
public final int read() {
if (fOffset >= fBufferLength) {
if (fBufferOffset + fBufferLength >= fRangeOffset + fRangeLength)
return EOF;
else {
updateBuffer(fBufferOffset + fBufferLength);
fOffset= 0;
}
}
return fBuffer[fOffset++];
}
/*
* @see ICharacterScanner#unread
*/
public final void unread() {
if (fOffset == 0) {
if (fBufferOffset == fRangeOffset) {
// error: BOF
} else {
updateBuffer(fBufferOffset - fBuffer.length);
fOffset= fBuffer.length - 1;
}
} else {
--fOffset;
}
}
if (fOffset <= 0) {
if (fBufferOffset <= fRangeOffset) {
// error: BOF
} else {
updateBuffer(fBufferOffset - fBuffer.length);
fOffset = fBuffer.length - 1; // should always be a valid place
}
} else {
--fOffset;
}
}
/*
* @see ICharacterScanner#getColumn()
*/
public final int getColumn() {
/*
* @see ICharacterScanner#getColumn()
*/
public final int getColumn() {
try {
final int offset= fBufferOffset + fOffset;
final int line= fDocument.getLineOfOffset(offset);
final int start= fDocument.getLineOffset(line);
return offset - start;
} catch (BadLocationException e) {
}
try {
final int offset= fBufferOffset + fOffset;
final int line= fDocument.getLineOfOffset(offset);
final int start= fDocument.getLineOffset(line);
return offset - start;
} catch (BadLocationException e) {
}
return -1;
}
return -1;
}
/*
* @see ICharacterScanner#getLegalLineDelimiters()
*/
public final char[][] getLegalLineDelimiters() {
return fDelimiters;
}
/*
* @see ICharacterScanner#getLegalLineDelimiters()
*/
public final char[][] getLegalLineDelimiters() {
return fDelimiters;
}
}