mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Fix for bugzilla bug 24648 - Editor displaying text in reverse on Eclipse 2.1 platform
This commit is contained in:
parent
d783a4c703
commit
4d7d5904b5
2 changed files with 138 additions and 123 deletions
|
@ -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
|
2002-12-11 Alain Magloire
|
||||||
|
|
||||||
Fix PR 27937. NPE in the C Editor preference page.
|
Fix PR 27937. NPE in the C Editor preference page.
|
||||||
|
|
|
@ -15,138 +15,145 @@ import org.eclipse.jface.util.Assert;
|
||||||
*/
|
*/
|
||||||
public final class BufferedDocumentScanner implements ICharacterScanner {
|
public final class BufferedDocumentScanner implements ICharacterScanner {
|
||||||
|
|
||||||
/** The document being scanned. */
|
/** The document being scanned. */
|
||||||
private IDocument fDocument;
|
private IDocument fDocument;
|
||||||
/** The offset of the document range to scan. */
|
/** The offset of the document range to scan. */
|
||||||
private int fRangeOffset;
|
private int fRangeOffset;
|
||||||
/** The length of the document range to scan. */
|
/** The length of the document range to scan. */
|
||||||
private int fRangeLength;
|
private int fRangeLength;
|
||||||
/** The delimiters of the document. */
|
/** The delimiters of the document. */
|
||||||
private char[][] fDelimiters;
|
private char[][] fDelimiters;
|
||||||
|
|
||||||
/** The buffer. */
|
/** The buffer. */
|
||||||
private final char[] fBuffer;
|
private final char[] fBuffer;
|
||||||
/** The offset of the buffer within the document. */
|
/** The offset of the buffer within the document. */
|
||||||
private int fBufferOffset;
|
private int fBufferOffset;
|
||||||
/** The valid length of the buffer for access. */
|
/** The valid length of the buffer for access. */
|
||||||
private int fBufferLength;
|
private int fBufferLength;
|
||||||
/** The offset of the scanner within the buffer. */
|
/** The offset of the scanner within the buffer. */
|
||||||
private int fOffset;
|
private int fOffset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new buffered document scanner.
|
* Creates a new buffered document scanner.
|
||||||
* The buffer size is set to the given number of characters.
|
* The buffer size is set to the given number of characters.
|
||||||
*
|
*
|
||||||
* @param size the buffer size
|
* @param size the buffer size
|
||||||
*/
|
*/
|
||||||
public BufferedDocumentScanner(int size) {
|
public BufferedDocumentScanner(int size) {
|
||||||
Assert.isTrue(size >= 1);
|
Assert.isTrue(size >= 1);
|
||||||
fBuffer= new char[size];
|
fBuffer= new char[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills the buffer with the contens of the document starting at the given offset.
|
* Fills the buffer with the contents of the document starting at the given offset.
|
||||||
*
|
*
|
||||||
* @param offset the document offset at which the buffer starts
|
* @param offset the document offset at which the buffer starts
|
||||||
*/
|
*/
|
||||||
private final void updateBuffer(int offset) {
|
private final void updateBuffer(int offset) {
|
||||||
|
|
||||||
fBufferOffset= offset;
|
// Clamp at start of the file document range
|
||||||
|
if (offset < 0)
|
||||||
|
offset = 0;
|
||||||
|
|
||||||
if (fBufferOffset + fBuffer.length > fRangeLength)
|
fBufferOffset= offset;
|
||||||
fBufferLength= fRangeLength - fBufferOffset;
|
fBufferLength= fBuffer.length;
|
||||||
else
|
|
||||||
fBufferLength= fBuffer.length;
|
|
||||||
|
|
||||||
try {
|
// assert(offset >= fRangeOffset && offset < fRangeOffset + fRangeLength);
|
||||||
final String content= fDocument.get(fBufferOffset, fBufferLength);
|
|
||||||
content.getChars(0, fBufferLength, fBuffer, 0);
|
|
||||||
|
|
||||||
} catch (BadLocationException e) {
|
if (fBufferOffset + fBufferLength > fRangeOffset + fRangeLength)
|
||||||
}
|
fBufferLength= fRangeOffset + fRangeLength - fBufferOffset;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
try {
|
||||||
* Configures the scanner by providing access to the document range over which to scan.
|
final String content= fDocument.get(fBufferOffset, fBufferLength);
|
||||||
*
|
content.getChars(0, fBufferLength, fBuffer, 0);
|
||||||
* @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;
|
} catch (BadLocationException e) {
|
||||||
fRangeOffset= offset;
|
}
|
||||||
fRangeLength= length;
|
}
|
||||||
|
|
||||||
String[] delimiters= document.getLegalLineDelimiters();
|
/**
|
||||||
fDelimiters= new char[delimiters.length][];
|
* Configures the scanner by providing access to the document range over which to scan.
|
||||||
for (int i= 0; i < delimiters.length; i++)
|
*
|
||||||
fDelimiters[i]= delimiters[i].toCharArray();
|
* @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) {
|
||||||
|
|
||||||
updateBuffer(offset);
|
fDocument= document;
|
||||||
fOffset= 0;
|
fRangeOffset= offset;
|
||||||
}
|
fRangeLength= length;
|
||||||
|
|
||||||
/*
|
// Clamp at end of the real document
|
||||||
* @see ICharacterScanner#read()
|
if (fRangeLength > fDocument.getLength())
|
||||||
*/
|
fRangeLength = fDocument.getLength();
|
||||||
public final int read() {
|
|
||||||
|
|
||||||
if (fOffset == fBufferLength) {
|
String[] delimiters= document.getLegalLineDelimiters();
|
||||||
if (fBufferOffset + fBufferLength == fDocument.getLength())
|
fDelimiters= new char[delimiters.length][];
|
||||||
return EOF;
|
for (int i= 0; i < delimiters.length; i++)
|
||||||
else {
|
fDelimiters[i]= delimiters[i].toCharArray();
|
||||||
updateBuffer(fBufferOffset + fBufferLength);
|
|
||||||
fOffset= 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fBuffer[fOffset++];
|
updateBuffer(offset);
|
||||||
}
|
fOffset= 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see ICharacterScanner#unread
|
* @see ICharacterScanner#read()
|
||||||
*/
|
*/
|
||||||
public final void unread() {
|
public final int read() {
|
||||||
|
|
||||||
if (fOffset == 0) {
|
if (fOffset >= fBufferLength) {
|
||||||
if (fBufferOffset == fRangeOffset) {
|
if (fBufferOffset + fBufferLength >= fRangeOffset + fRangeLength)
|
||||||
// error: BOF
|
return EOF;
|
||||||
} else {
|
else {
|
||||||
updateBuffer(fBufferOffset - fBuffer.length);
|
updateBuffer(fBufferOffset + fBufferLength);
|
||||||
fOffset= fBuffer.length - 1;
|
fOffset= 0;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
--fOffset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
return fBuffer[fOffset++];
|
||||||
* @see ICharacterScanner#getColumn()
|
}
|
||||||
*/
|
|
||||||
public final int getColumn() {
|
|
||||||
|
|
||||||
try {
|
/*
|
||||||
final int offset= fBufferOffset + fOffset;
|
* @see ICharacterScanner#unread
|
||||||
final int line= fDocument.getLineOfOffset(offset);
|
*/
|
||||||
final int start= fDocument.getLineOffset(line);
|
public final void unread() {
|
||||||
|
|
||||||
return offset - start;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (BadLocationException e) {
|
/*
|
||||||
}
|
* @see ICharacterScanner#getColumn()
|
||||||
|
*/
|
||||||
|
public final int getColumn() {
|
||||||
|
|
||||||
return -1;
|
try {
|
||||||
}
|
final int offset= fBufferOffset + fOffset;
|
||||||
|
final int line= fDocument.getLineOfOffset(offset);
|
||||||
|
final int start= fDocument.getLineOffset(line);
|
||||||
|
|
||||||
/*
|
return offset - start;
|
||||||
* @see ICharacterScanner#getLegalLineDelimiters()
|
|
||||||
*/
|
} catch (BadLocationException e) {
|
||||||
public final char[][] getLegalLineDelimiters() {
|
}
|
||||||
return fDelimiters;
|
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see ICharacterScanner#getLegalLineDelimiters()
|
||||||
|
*/
|
||||||
|
public final char[][] getLegalLineDelimiters() {
|
||||||
|
return fDelimiters;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue