1) Fixed the Cross Plattform debugging bug. The path separator was not translated.
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / ui / text / TextDoubleClickStrategy.java
1 /*
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://solareclipse.sourceforge.net/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Igor Malinin - initial contribution
10  * 
11  * $Id: TextDoubleClickStrategy.java,v 1.1 2004-09-02 18:26:49 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.ui.text;
15
16 import org.eclipse.jface.text.BadLocationException;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.jface.text.ITextDoubleClickStrategy;
19 import org.eclipse.jface.text.ITextViewer;
20
21 /**
22  * @author Igor Malinin
23  */
24 public class TextDoubleClickStrategy implements ITextDoubleClickStrategy {
25
26         /*
27          * @see org.eclipse.jface.text.ITextDoubleClickStrategy#doubleClicked(ITextViewer)
28          */
29         public void doubleClicked(ITextViewer viewer) {
30                 int offset = viewer.getSelectedRange().x;
31                 if (offset < 0) { return; }
32
33                 selectWord(viewer, viewer.getDocument(), offset);
34         }
35
36         protected void selectWord(ITextViewer textViewer, IDocument document,
37                         int offset) {
38                 try {
39                         int start = offset;
40                         while (start >= 0) {
41                                 char c = document.getChar(start);
42
43                                 if (!Character.isUnicodeIdentifierPart(c)) {
44                                         break;
45                                 }
46
47                                 --start;
48                         }
49
50                         int length = document.getLength();
51
52                         int end = offset;
53                         while (end < length) {
54                                 char c = document.getChar(end);
55
56                                 if (!Character.isUnicodeIdentifierPart(c)) {
57                                         break;
58                                 }
59
60                                 ++end;
61                         }
62
63                         if (start == end) {
64                                 textViewer.setSelectedRange(start, 0);
65                         } else {
66                                 textViewer.setSelectedRange(start + 1, end - start - 1);
67                         }
68                 } catch (BadLocationException x) {
69                 }
70         }
71 }