mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Bug 324838: Workaround for platform issue in commenting code.
This commit is contained in:
parent
e18bd9cc26
commit
83aed16ff8
1 changed files with 17 additions and 8 deletions
|
@ -24,6 +24,7 @@ import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.text.ITypedRegion;
|
import org.eclipse.jface.text.ITypedRegion;
|
||||||
import org.eclipse.jface.text.Region;
|
import org.eclipse.jface.text.Region;
|
||||||
import org.eclipse.jface.text.TextUtilities;
|
import org.eclipse.jface.text.TextUtilities;
|
||||||
|
import org.eclipse.jface.text.TextViewer;
|
||||||
import org.eclipse.jface.text.source.ISourceViewer;
|
import org.eclipse.jface.text.source.ISourceViewer;
|
||||||
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
@ -173,16 +174,25 @@ public final class ToggleCommentAction extends TextEditorAction {
|
||||||
* Creates a region describing the text block (something that starts at
|
* Creates a region describing the text block (something that starts at
|
||||||
* the beginning of a line) completely containing the current selection.
|
* the beginning of a line) completely containing the current selection.
|
||||||
*
|
*
|
||||||
|
* Note, the implementation has to match {@link TextViewer}.getTextBlockFromSelection().
|
||||||
|
*
|
||||||
* @param selection The selection to use
|
* @param selection The selection to use
|
||||||
* @param document The document
|
* @param document The document
|
||||||
* @return the region describing the text block comprising the given selection
|
* @return the region describing the text block comprising the given selection
|
||||||
*/
|
*/
|
||||||
private IRegion getTextBlockFromSelection(ITextSelection selection, IDocument document) {
|
private IRegion getTextBlockFromSelection(ITextSelection selection, IDocument document) {
|
||||||
try {
|
try {
|
||||||
IRegion line= document.getLineInformationOfOffset(selection.getOffset());
|
// Until https://bugs.eclipse.org/bugs/show_bug.cgi?id=325438 is fixed, work around it
|
||||||
int length= selection.getLength() == 0 ?
|
int start= document.getLineOffset(selection.getStartLine());
|
||||||
line.getLength() : selection.getLength() + (selection.getOffset() - line.getOffset());
|
int endLine= selection.getEndLine();
|
||||||
return new Region(line.getOffset(), length);
|
IRegion endLineInfo= document.getLineInformation(endLine);
|
||||||
|
int end= endLineInfo.getOffset() + endLineInfo.getLength();
|
||||||
|
return new Region(start, end - start);
|
||||||
|
|
||||||
|
// IRegion line= document.getLineInformationOfOffset(selection.getOffset());
|
||||||
|
// int length= selection.getLength() == 0 ?
|
||||||
|
// line.getLength() : selection.getLength() + (selection.getOffset() - line.getOffset());
|
||||||
|
// return new Region(line.getOffset(), length);
|
||||||
|
|
||||||
} catch (BadLocationException e) {
|
} catch (BadLocationException e) {
|
||||||
CUIPlugin.log(e); // Should not happen
|
CUIPlugin.log(e); // Should not happen
|
||||||
|
@ -298,13 +308,12 @@ public final class ToggleCommentAction extends TextEditorAction {
|
||||||
|
|
||||||
String[] types= configuration.getConfiguredContentTypes(sourceViewer);
|
String[] types= configuration.getConfiguredContentTypes(sourceViewer);
|
||||||
Map<String, String[]> prefixesMap= new HashMap<String, String[]>(types.length);
|
Map<String, String[]> prefixesMap= new HashMap<String, String[]>(types.length);
|
||||||
for (int i= 0; i < types.length; i++) {
|
for (String type : types) {
|
||||||
String type= types[i];
|
|
||||||
String[] prefixes= configuration.getDefaultPrefixes(sourceViewer, type);
|
String[] prefixes= configuration.getDefaultPrefixes(sourceViewer, type);
|
||||||
if (prefixes != null && prefixes.length > 0) {
|
if (prefixes != null && prefixes.length > 0) {
|
||||||
int emptyPrefixes= 0;
|
int emptyPrefixes= 0;
|
||||||
for (int j= 0; j < prefixes.length; j++) {
|
for (String prefixe : prefixes) {
|
||||||
if (prefixes[j].length() == 0)
|
if (prefixe.length() == 0)
|
||||||
emptyPrefixes++;
|
emptyPrefixes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue