Lines 10-19
Link Here
|
10 |
* QNX Software System |
10 |
* QNX Software System |
11 |
* Anton Leherbauer (Wind River Systems) |
11 |
* Anton Leherbauer (Wind River Systems) |
12 |
* Markus Schorn (Wind River Systems) |
12 |
* Markus Schorn (Wind River Systems) |
|
|
13 |
* Sergey Prigogin, Google |
13 |
*******************************************************************************/ |
14 |
*******************************************************************************/ |
14 |
package org.eclipse.cdt.internal.ui.editor; |
15 |
package org.eclipse.cdt.internal.ui.editor; |
15 |
|
16 |
|
16 |
|
17 |
|
|
|
18 |
import java.text.CharacterIterator; |
17 |
import java.util.Iterator; |
19 |
import java.util.Iterator; |
18 |
import java.util.ResourceBundle; |
20 |
import java.util.ResourceBundle; |
19 |
|
21 |
|
Lines 21-26
Link Here
|
21 |
import org.eclipse.core.runtime.CoreException; |
23 |
import org.eclipse.core.runtime.CoreException; |
22 |
import org.eclipse.core.runtime.content.IContentType; |
24 |
import org.eclipse.core.runtime.content.IContentType; |
23 |
import org.eclipse.jface.action.Action; |
25 |
import org.eclipse.jface.action.Action; |
|
|
26 |
import org.eclipse.jface.action.IAction; |
24 |
import org.eclipse.jface.action.IMenuManager; |
27 |
import org.eclipse.jface.action.IMenuManager; |
25 |
import org.eclipse.jface.action.IStatusLineManager; |
28 |
import org.eclipse.jface.action.IStatusLineManager; |
26 |
import org.eclipse.jface.preference.IPreferenceStore; |
29 |
import org.eclipse.jface.preference.IPreferenceStore; |
Lines 72-77
Link Here
|
72 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
75 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
73 |
import org.eclipse.search.ui.actions.TextSearchGroup; |
76 |
import org.eclipse.search.ui.actions.TextSearchGroup; |
74 |
import org.eclipse.swt.SWT; |
77 |
import org.eclipse.swt.SWT; |
|
|
78 |
import org.eclipse.swt.custom.ST; |
75 |
import org.eclipse.swt.custom.StyledText; |
79 |
import org.eclipse.swt.custom.StyledText; |
76 |
import org.eclipse.swt.dnd.DND; |
80 |
import org.eclipse.swt.dnd.DND; |
77 |
import org.eclipse.swt.dnd.DragSource; |
81 |
import org.eclipse.swt.dnd.DragSource; |
Lines 104-115
Link Here
|
104 |
import org.eclipse.ui.texteditor.ITextEditorActionConstants; |
108 |
import org.eclipse.ui.texteditor.ITextEditorActionConstants; |
105 |
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; |
109 |
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; |
106 |
import org.eclipse.ui.texteditor.ITextEditorDropTargetListener; |
110 |
import org.eclipse.ui.texteditor.ITextEditorDropTargetListener; |
|
|
111 |
import org.eclipse.ui.texteditor.IUpdate; |
107 |
import org.eclipse.ui.texteditor.ResourceAction; |
112 |
import org.eclipse.ui.texteditor.ResourceAction; |
108 |
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; |
113 |
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; |
109 |
import org.eclipse.ui.texteditor.TextEditorAction; |
114 |
import org.eclipse.ui.texteditor.TextEditorAction; |
|
|
115 |
import org.eclipse.ui.texteditor.TextNavigationAction; |
110 |
import org.eclipse.ui.texteditor.TextOperationAction; |
116 |
import org.eclipse.ui.texteditor.TextOperationAction; |
111 |
import org.eclipse.ui.views.contentoutline.IContentOutlinePage; |
117 |
import org.eclipse.ui.views.contentoutline.IContentOutlinePage; |
112 |
|
118 |
|
|
|
119 |
import com.ibm.icu.text.BreakIterator; |
120 |
|
113 |
import org.eclipse.cdt.core.CCorePlugin; |
121 |
import org.eclipse.cdt.core.CCorePlugin; |
114 |
import org.eclipse.cdt.core.CCorePreferenceConstants; |
122 |
import org.eclipse.cdt.core.CCorePreferenceConstants; |
115 |
import org.eclipse.cdt.core.model.CModelException; |
123 |
import org.eclipse.cdt.core.model.CModelException; |
Lines 138-143
Link Here
|
138 |
import org.eclipse.cdt.internal.ui.text.CPairMatcher; |
146 |
import org.eclipse.cdt.internal.ui.text.CPairMatcher; |
139 |
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; |
147 |
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; |
140 |
import org.eclipse.cdt.internal.ui.text.CTextTools; |
148 |
import org.eclipse.cdt.internal.ui.text.CTextTools; |
|
|
149 |
import org.eclipse.cdt.internal.ui.text.CWordIterator; |
150 |
import org.eclipse.cdt.internal.ui.text.DocumentCharacterIterator; |
141 |
import org.eclipse.cdt.internal.ui.text.HTMLTextPresenter; |
151 |
import org.eclipse.cdt.internal.ui.text.HTMLTextPresenter; |
142 |
import org.eclipse.cdt.internal.ui.text.ICPartitions; |
152 |
import org.eclipse.cdt.internal.ui.text.ICPartitions; |
143 |
import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl; |
153 |
import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl; |
Lines 512-517
Link Here
|
512 |
/** Listener to annotation model changes that updates the error tick in the tab image */ |
522 |
/** Listener to annotation model changes that updates the error tick in the tab image */ |
513 |
private CEditorErrorTickUpdater fCEditorErrorTickUpdater; |
523 |
private CEditorErrorTickUpdater fCEditorErrorTickUpdater; |
514 |
|
524 |
|
|
|
525 |
/** Preference key for sub-word navigation, aka smart caret positioning */ |
526 |
public final static String SUB_WORD_NAVIGATION= "subWordNavigation"; //$NON-NLS-1$ |
515 |
/** Preference key for matching brackets */ |
527 |
/** Preference key for matching brackets */ |
516 |
public final static String MATCHING_BRACKETS = "matchingBrackets"; //$NON-NLS-1$ |
528 |
public final static String MATCHING_BRACKETS = "matchingBrackets"; //$NON-NLS-1$ |
517 |
/** Preference key for matching brackets color */ |
529 |
/** Preference key for matching brackets color */ |
Lines 1396-1401
Link Here
|
1396 |
return store.getBoolean(SPACES_FOR_TABS); |
1408 |
return store.getBoolean(SPACES_FOR_TABS); |
1397 |
} |
1409 |
} |
1398 |
|
1410 |
|
|
|
1411 |
/* |
1412 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#createNavigationActions() |
1413 |
*/ |
1414 |
protected void createNavigationActions() { |
1415 |
super.createNavigationActions(); |
1416 |
|
1417 |
final StyledText textWidget = getSourceViewer().getTextWidget(); |
1418 |
|
1419 |
IAction action = new NavigatePreviousSubWordAction(); |
1420 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS); |
1421 |
setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action); |
1422 |
textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_LEFT, SWT.NULL); |
1423 |
|
1424 |
action = new NavigateNextSubWordAction(); |
1425 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT); |
1426 |
setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action); |
1427 |
textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_RIGHT, SWT.NULL); |
1428 |
|
1429 |
action = new SelectPreviousSubWordAction(); |
1430 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS); |
1431 |
setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action); |
1432 |
textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_LEFT, SWT.NULL); |
1433 |
|
1434 |
action = new SelectNextSubWordAction(); |
1435 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT); |
1436 |
setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action); |
1437 |
textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_RIGHT, SWT.NULL); |
1438 |
|
1439 |
action= new DeletePreviousSubWordAction(); |
1440 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD); |
1441 |
setAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD, action); |
1442 |
textWidget.setKeyBinding(SWT.CTRL | SWT.BS, SWT.NULL); |
1443 |
markAsStateDependentAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD, true); |
1444 |
|
1445 |
action= new DeleteNextSubWordAction(); |
1446 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD); |
1447 |
setAction(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD, action); |
1448 |
textWidget.setKeyBinding(SWT.CTRL | SWT.DEL, SWT.NULL); |
1449 |
markAsStateDependentAction(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD, true); |
1450 |
} |
1451 |
|
1399 |
interface ITextConverter { |
1452 |
interface ITextConverter { |
1400 |
void customizeDocumentCommand(IDocument document, DocumentCommand command); |
1453 |
void customizeDocumentCommand(IDocument document, DocumentCommand command); |
1401 |
} |
1454 |
} |
Lines 1669-1672
Link Here
|
1669 |
System.arraycopy(parentPrefPageIds, 0, prefPageIds, nIds, parentPrefPageIds.length); |
1722 |
System.arraycopy(parentPrefPageIds, 0, prefPageIds, nIds, parentPrefPageIds.length); |
1670 |
return prefPageIds; |
1723 |
return prefPageIds; |
1671 |
} |
1724 |
} |
|
|
1725 |
|
1726 |
/** |
1727 |
* Text navigation action to navigate to the next sub-word. |
1728 |
* |
1729 |
* @since 3.0 |
1730 |
*/ |
1731 |
protected abstract class NextSubWordAction extends TextNavigationAction { |
1732 |
|
1733 |
protected CWordIterator fIterator = new CWordIterator(); |
1734 |
|
1735 |
/** |
1736 |
* Creates a new next sub-word action. |
1737 |
* |
1738 |
* @param code Action code for the default operation. Must be an action code from @see org.eclipse.swt.custom.ST. |
1739 |
*/ |
1740 |
protected NextSubWordAction(int code) { |
1741 |
super(getSourceViewer().getTextWidget(), code); |
1742 |
} |
1743 |
|
1744 |
/* |
1745 |
* @see org.eclipse.jface.action.IAction#run() |
1746 |
*/ |
1747 |
public void run() { |
1748 |
// Check whether sub word navigation is enabled. |
1749 |
final IPreferenceStore store = getPreferenceStore(); |
1750 |
if (!store.getBoolean(SUB_WORD_NAVIGATION)) { |
1751 |
super.run(); |
1752 |
return; |
1753 |
} |
1754 |
|
1755 |
final ISourceViewer viewer = getSourceViewer(); |
1756 |
final IDocument document = viewer.getDocument(); |
1757 |
fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document)); |
1758 |
int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
1759 |
if (position == -1) |
1760 |
return; |
1761 |
|
1762 |
int next = findNextPosition(position); |
1763 |
if (next != BreakIterator.DONE) { |
1764 |
setCaretPosition(next); |
1765 |
getTextWidget().showSelection(); |
1766 |
fireSelectionChanged(); |
1767 |
} |
1768 |
|
1769 |
} |
1770 |
|
1771 |
/** |
1772 |
* Finds the next position after the given position. |
1773 |
* |
1774 |
* @param position the current position |
1775 |
* @return the next position |
1776 |
*/ |
1777 |
protected int findNextPosition(int position) { |
1778 |
ISourceViewer viewer = getSourceViewer(); |
1779 |
int widget = -1; |
1780 |
while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize |
1781 |
position = fIterator.following(position); |
1782 |
if (position != BreakIterator.DONE) |
1783 |
widget = modelOffset2WidgetOffset(viewer, position); |
1784 |
} |
1785 |
return position; |
1786 |
} |
1787 |
|
1788 |
/** |
1789 |
* Sets the caret position to the sub-word boundary given with <code>position</code>. |
1790 |
* |
1791 |
* @param position Position where the action should move the caret |
1792 |
*/ |
1793 |
protected abstract void setCaretPosition(int position); |
1794 |
} |
1795 |
|
1796 |
/** |
1797 |
* Text navigation action to navigate to the next sub-word. |
1798 |
* |
1799 |
* @since 3.0 |
1800 |
*/ |
1801 |
protected class NavigateNextSubWordAction extends NextSubWordAction { |
1802 |
|
1803 |
/** |
1804 |
* Creates a new navigate next sub-word action. |
1805 |
*/ |
1806 |
public NavigateNextSubWordAction() { |
1807 |
super(ST.WORD_NEXT); |
1808 |
} |
1809 |
|
1810 |
/* |
1811 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int) |
1812 |
*/ |
1813 |
protected void setCaretPosition(final int position) { |
1814 |
getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position)); |
1815 |
} |
1816 |
} |
1817 |
|
1818 |
/** |
1819 |
* Text operation action to delete the next sub-word. |
1820 |
* |
1821 |
* @since 3.0 |
1822 |
*/ |
1823 |
protected class DeleteNextSubWordAction extends NextSubWordAction implements IUpdate { |
1824 |
|
1825 |
/** |
1826 |
* Creates a new delete next sub-word action. |
1827 |
*/ |
1828 |
public DeleteNextSubWordAction() { |
1829 |
super(ST.DELETE_WORD_NEXT); |
1830 |
} |
1831 |
|
1832 |
/* |
1833 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int) |
1834 |
*/ |
1835 |
protected void setCaretPosition(final int position) { |
1836 |
if (!validateEditorInputState()) |
1837 |
return; |
1838 |
|
1839 |
final ISourceViewer viewer = getSourceViewer(); |
1840 |
final int caret, length; |
1841 |
Point selection = viewer.getSelectedRange(); |
1842 |
if (selection.y != 0) { |
1843 |
caret = selection.x; |
1844 |
length = selection.y; |
1845 |
} else { |
1846 |
caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
1847 |
length = position - caret; |
1848 |
} |
1849 |
|
1850 |
try { |
1851 |
viewer.getDocument().replace(caret, length, ""); //$NON-NLS-1$ |
1852 |
} catch (BadLocationException exception) { |
1853 |
// Should not happen |
1854 |
} |
1855 |
} |
1856 |
|
1857 |
/* |
1858 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#findNextPosition(int) |
1859 |
*/ |
1860 |
protected int findNextPosition(int position) { |
1861 |
return fIterator.following(position); |
1862 |
} |
1863 |
|
1864 |
/* |
1865 |
* @see org.eclipse.ui.texteditor.IUpdate#update() |
1866 |
*/ |
1867 |
public void update() { |
1868 |
setEnabled(isEditorInputModifiable()); |
1869 |
} |
1870 |
} |
1871 |
|
1872 |
/** |
1873 |
* Text operation action to select the next sub-word. |
1874 |
* |
1875 |
* @since 3.0 |
1876 |
*/ |
1877 |
protected class SelectNextSubWordAction extends NextSubWordAction { |
1878 |
|
1879 |
/** |
1880 |
* Creates a new select next sub-word action. |
1881 |
*/ |
1882 |
public SelectNextSubWordAction() { |
1883 |
super(ST.SELECT_WORD_NEXT); |
1884 |
} |
1885 |
|
1886 |
/* |
1887 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int) |
1888 |
*/ |
1889 |
protected void setCaretPosition(final int position) { |
1890 |
final ISourceViewer viewer = getSourceViewer(); |
1891 |
|
1892 |
final StyledText text = viewer.getTextWidget(); |
1893 |
if (text != null && !text.isDisposed()) { |
1894 |
|
1895 |
final Point selection = text.getSelection(); |
1896 |
final int caret = text.getCaretOffset(); |
1897 |
final int offset = modelOffset2WidgetOffset(viewer, position); |
1898 |
|
1899 |
if (caret == selection.x) |
1900 |
text.setSelectionRange(selection.y, offset - selection.y); |
1901 |
else |
1902 |
text.setSelectionRange(selection.x, offset - selection.x); |
1903 |
} |
1904 |
} |
1905 |
} |
1906 |
|
1907 |
/** |
1908 |
* Text navigation action to navigate to the previous sub-word. |
1909 |
* |
1910 |
* @since 3.0 |
1911 |
*/ |
1912 |
protected abstract class PreviousSubWordAction extends TextNavigationAction { |
1913 |
|
1914 |
protected CWordIterator fIterator = new CWordIterator(); |
1915 |
|
1916 |
/** |
1917 |
* Creates a new previous sub-word action. |
1918 |
* |
1919 |
* @param code Action code for the default operation. Must be an action code from @see org.eclipse.swt.custom.ST. |
1920 |
*/ |
1921 |
protected PreviousSubWordAction(final int code) { |
1922 |
super(getSourceViewer().getTextWidget(), code); |
1923 |
} |
1924 |
|
1925 |
/* |
1926 |
* @see org.eclipse.jface.action.IAction#run() |
1927 |
*/ |
1928 |
public void run() { |
1929 |
// Check whether sub word navigation is enabled. |
1930 |
final IPreferenceStore store = getPreferenceStore(); |
1931 |
if (!store.getBoolean(SUB_WORD_NAVIGATION)) { |
1932 |
super.run(); |
1933 |
return; |
1934 |
} |
1935 |
|
1936 |
final ISourceViewer viewer = getSourceViewer(); |
1937 |
final IDocument document = viewer.getDocument(); |
1938 |
fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document)); |
1939 |
int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
1940 |
if (position == -1) |
1941 |
return; |
1942 |
|
1943 |
int previous = findPreviousPosition(position); |
1944 |
if (previous != BreakIterator.DONE) { |
1945 |
setCaretPosition(previous); |
1946 |
getTextWidget().showSelection(); |
1947 |
fireSelectionChanged(); |
1948 |
} |
1949 |
|
1950 |
} |
1951 |
|
1952 |
/** |
1953 |
* Finds the previous position before the given position. |
1954 |
* |
1955 |
* @param position the current position |
1956 |
* @return the previous position |
1957 |
*/ |
1958 |
protected int findPreviousPosition(int position) { |
1959 |
ISourceViewer viewer = getSourceViewer(); |
1960 |
int widget = -1; |
1961 |
while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize |
1962 |
position = fIterator.preceding(position); |
1963 |
if (position != BreakIterator.DONE) |
1964 |
widget = modelOffset2WidgetOffset(viewer, position); |
1965 |
} |
1966 |
return position; |
1967 |
} |
1968 |
|
1969 |
/** |
1970 |
* Sets the caret position to the sub-word boundary given with <code>position</code>. |
1971 |
* |
1972 |
* @param position Position where the action should move the caret |
1973 |
*/ |
1974 |
protected abstract void setCaretPosition(int position); |
1975 |
} |
1976 |
|
1977 |
/** |
1978 |
* Text navigation action to navigate to the previous sub-word. |
1979 |
* |
1980 |
* @since 3.0 |
1981 |
*/ |
1982 |
protected class NavigatePreviousSubWordAction extends PreviousSubWordAction { |
1983 |
|
1984 |
/** |
1985 |
* Creates a new navigate previous sub-word action. |
1986 |
*/ |
1987 |
public NavigatePreviousSubWordAction() { |
1988 |
super(ST.WORD_PREVIOUS); |
1989 |
} |
1990 |
|
1991 |
/* |
1992 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int) |
1993 |
*/ |
1994 |
protected void setCaretPosition(final int position) { |
1995 |
getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position)); |
1996 |
} |
1997 |
} |
1998 |
|
1999 |
/** |
2000 |
* Text operation action to delete the previous sub-word. |
2001 |
* |
2002 |
* @since 3.0 |
2003 |
*/ |
2004 |
protected class DeletePreviousSubWordAction extends PreviousSubWordAction implements IUpdate { |
2005 |
|
2006 |
/** |
2007 |
* Creates a new delete previous sub-word action. |
2008 |
*/ |
2009 |
public DeletePreviousSubWordAction() { |
2010 |
super(ST.DELETE_WORD_PREVIOUS); |
2011 |
} |
2012 |
|
2013 |
/* |
2014 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int) |
2015 |
*/ |
2016 |
protected void setCaretPosition(int position) { |
2017 |
if (!validateEditorInputState()) |
2018 |
return; |
2019 |
|
2020 |
final int length; |
2021 |
final ISourceViewer viewer = getSourceViewer(); |
2022 |
Point selection = viewer.getSelectedRange(); |
2023 |
if (selection.y != 0) { |
2024 |
position = selection.x; |
2025 |
length = selection.y; |
2026 |
} else { |
2027 |
length = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()) - position; |
2028 |
} |
2029 |
|
2030 |
try { |
2031 |
viewer.getDocument().replace(position, length, ""); //$NON-NLS-1$ |
2032 |
} catch (BadLocationException exception) { |
2033 |
// Should not happen |
2034 |
} |
2035 |
} |
2036 |
|
2037 |
/* |
2038 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#findPreviousPosition(int) |
2039 |
*/ |
2040 |
protected int findPreviousPosition(int position) { |
2041 |
return fIterator.preceding(position); |
2042 |
} |
2043 |
|
2044 |
/* |
2045 |
* @see org.eclipse.ui.texteditor.IUpdate#update() |
2046 |
*/ |
2047 |
public void update() { |
2048 |
setEnabled(isEditorInputModifiable()); |
2049 |
} |
2050 |
} |
2051 |
|
2052 |
/** |
2053 |
* Text operation action to select the previous sub-word. |
2054 |
* |
2055 |
* @since 3.0 |
2056 |
*/ |
2057 |
protected class SelectPreviousSubWordAction extends PreviousSubWordAction { |
2058 |
|
2059 |
/** |
2060 |
* Creates a new select previous sub-word action. |
2061 |
*/ |
2062 |
public SelectPreviousSubWordAction() { |
2063 |
super(ST.SELECT_WORD_PREVIOUS); |
2064 |
} |
2065 |
|
2066 |
/* |
2067 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int) |
2068 |
*/ |
2069 |
protected void setCaretPosition(final int position) { |
2070 |
final ISourceViewer viewer = getSourceViewer(); |
2071 |
|
2072 |
final StyledText text = viewer.getTextWidget(); |
2073 |
if (text != null && !text.isDisposed()) { |
2074 |
|
2075 |
final Point selection = text.getSelection(); |
2076 |
final int caret = text.getCaretOffset(); |
2077 |
final int offset = modelOffset2WidgetOffset(viewer, position); |
2078 |
|
2079 |
if (caret == selection.x) |
2080 |
text.setSelectionRange(selection.y, offset - selection.y); |
2081 |
else |
2082 |
text.setSelectionRange(selection.x, offset - selection.x); |
2083 |
} |
2084 |
} |
2085 |
} |
1672 |
} |
2086 |
} |