2 * Copyright (c) 2002-2004 Widespace, OU and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Igor Malinin - initial contribution
11 * $Id: TagDoubleClickStrategy.java,v 1.1 2004-09-02 18:28:03 jsurfer Exp $
14 package net.sourceforge.phpeclipse.xml.ui.internal.text;
16 import org.eclipse.jface.text.BadLocationException;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.jface.text.ITextViewer;
19 import org.eclipse.jface.text.ITypedRegion;
21 import net.sourceforge.phpeclipse.ui.text.TextDoubleClickStrategy;
27 * @author Igor Malinin
29 public class TagDoubleClickStrategy extends TextDoubleClickStrategy {
31 * @see org.eclipse.jface.text.ITextDoubleClickStrategy#doubleClicked(ITextViewer)
33 public void doubleClicked( ITextViewer viewer ) {
34 int offset = viewer.getSelectedRange().x;
40 IDocument document = viewer.getDocument();
42 ITypedRegion region = document.getPartition( offset );
44 int start = region.getOffset();
46 if ( offset == start && document.getChar(offset) == '<' ) {
47 region = document.getPartition( offset );
48 offset = region.getOffset() + region.getLength();
50 if ( document.getChar(offset - 1) != '>' ) {
52 if ( offset >= document.getLength() ) {
56 region = document.getPartition( offset );
57 offset = region.getOffset() + region.getLength();
59 if ( XMLPartitionScanner.XML_ATTRIBUTE
60 .equals(region.getType()) ) {
64 if ( XMLPartitionScanner.XML_TAG
65 .equals(region.getType()) ) {
66 if ( document.getChar(region.getOffset()) == '<' ) {
70 if ( document.getChar(offset - 1) == '>' ) {
77 offset = region.getOffset();
82 viewer.setSelectedRange( start, offset - start );
86 int end = start + region.getLength();
88 if ( offset == end - 1 && document.getChar(offset) == '>' ) {
89 region = document.getPartition( offset );
90 offset = region.getOffset();
92 if ( document.getChar(offset) != '<' ) {
98 region = document.getPartition( offset - 1 );
99 offset = region.getOffset();
101 if ( XMLPartitionScanner.XML_ATTRIBUTE
102 .equals(region.getType()) ) {
106 if ( XMLPartitionScanner.XML_TAG
107 .equals(region.getType()) ) {
108 if ( document.getChar(offset) == '<' ) {
115 offset += region.getLength();
120 viewer.setSelectedRange( offset, end - offset );
124 super.doubleClicked( viewer );
125 } catch ( BadLocationException e ) {}