Bug 33629 Double-quote as character value broken in RC1
There is a series of related bugs under the category of it's really hard to enter a character value containing a double-quote character and when you try it strange things can happen. 1. Single-quote balancing seems not to work at all. When you type a single quote you get a single quote. 2. When you type the character sequence '" the result is '"" (!) 3. When you try to backspace over the extra unwanted " (either the first or the second) both are erased. The only way to get the desired result seems to be to copy and paste the " character. 4. If you try to cut and paste in the ", you can get in some weird mode where the editor thinks a string exists where there is none. I'm still trying to figure out the sequence that produced the following lines: if (c == ''' || c == '"') {" + "} (Leading tabs removed for sake of example.) I only know that the last two " characters were not typed. No doubt another illustration why editor modes are a bad idea.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/CompilationUnitEditor.java
*/
	protected void restoreSelection() {
		
		try {
			
			if (getSourceViewer() == null || fRememberedSelection == null)
				return;
				
			IJavaElement newElement= findElement(fRememberedElement);
			int newOffset= getOffset(newElement);
			int delta= (newOffset > -1 && fRememberedElementOffset > -1) ? newOffset - fRememberedElementOffset : 0;
			if (isValidSelection(delta + fRememberedSelection.getOffset(), fRememberedSelection.getLength()))
				selectAndReveal(delta + fRememberedSelection.getOffset(), fRememberedSelection.getLength());			
			
		} finally {
			fRememberedSelection= null;
			fRememberedElement= null;
			fRememberedElementOffset= -1;
		}
	}
	
	private boolean isValidSelection(int offset, int length) {
		IDocumentProvider provider= getDocumentProvider();
		if (provider != null) {
			IDocument document= provider.getDocument(getEditorInput());
			if (document != null) {
				int end= offset + length;
				int documentLength= document.getLength();
				return 0 <= offset  && offset <= documentLength && 0 <= end && end <= documentLength;
			}