Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSzymon Ptaszkiewicz2012-10-19 09:46:12 +0000
committerDani Megert2012-10-19 09:46:12 +0000
commit43580e947ec1a3976d4ffba0ba2108d27fec4536 (patch)
treee09e10fe6c75917a91e296336a97a93e2842cd27
parent975ad886c356c8c88144c9327d2c28a3ef5b2ccc (diff)
downloadeclipse.platform.text-20121019-094612.tar.gz
eclipse.platform.text-20121019-094612.tar.xz
eclipse.platform.text-20121019-094612.zip
Fixed bug 386472: [block selection] Block selection editing does notv20121019-094612I20121023-0800
work with Korean encoding
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/SelectionProcessor.java67
1 files changed, 56 insertions, 11 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/SelectionProcessor.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/SelectionProcessor.java
index a7733f55af8..f8a6cce99ed 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/SelectionProcessor.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/SelectionProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Avaloq Evolution AG and others.
+ * Copyright (c) 2009, 2012 Avaloq Evolution AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,6 +12,9 @@ package org.eclipse.jface.internal.text;
import java.util.Arrays;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.GC;
+
import org.eclipse.core.runtime.Assert;
import org.eclipse.text.edits.DeleteEdit;
@@ -216,7 +219,7 @@ public final class SelectionProcessor {
};
private final Implementation COLUMN_IMPLEMENTATION= new Implementation() {
- TextEdit replace(ISelection selection, String replacement) throws BadLocationException {
+ private TextEdit replace(ISelection selection, String replacement, boolean delete) throws BadLocationException {
try {
MultiTextEdit root;
IBlockTextSelection cts= (IBlockTextSelection)selection;
@@ -244,7 +247,7 @@ public final class SelectionProcessor {
lastDelim= index[0] + delimiters[index[1]].length();
}
}
- TextEdit replace= createReplaceEdit(line, visualStartColumn, visualEndColumn, string);
+ TextEdit replace= createReplaceEdit(line, visualStartColumn, visualEndColumn, string, delete);
root.addChild(replace);
}
while (lastDelim != -1) {
@@ -261,7 +264,7 @@ public final class SelectionProcessor {
endLine++;
TextEdit edit;
if (endLine < fDocument.getNumberOfLines()) {
- edit= createReplaceEdit(endLine, visualStartColumn, visualEndColumn, string);
+ edit= createReplaceEdit(endLine, visualStartColumn, visualEndColumn, string, delete);
} else {
// insertion reaches beyond the last line
int insertLocation= root.getExclusiveEnd();
@@ -281,6 +284,10 @@ public final class SelectionProcessor {
}
}
+ TextEdit replace(ISelection selection, String replacement) throws BadLocationException {
+ return replace(selection, replacement, false);
+ }
+
String getText(ISelection selection) throws BadLocationException {
IBlockTextSelection cts= (IBlockTextSelection)selection;
StringBuffer buf= new StringBuffer(cts.getLength());
@@ -321,7 +328,7 @@ public final class SelectionProcessor {
IBlockTextSelection cts= (IBlockTextSelection)selection;
selection= new BlockTextSelection(fDocument, cts.getStartLine(), cts.getStartColumn(), cts.getEndLine(), cts.getEndColumn() + 1, fTabWidth);
}
- return replace(selection, ""); //$NON-NLS-1$
+ return replace(selection, "", true); //$NON-NLS-1$
}
TextEdit backspace(ISelection selection) throws BadLocationException {
@@ -392,7 +399,7 @@ public final class SelectionProcessor {
return ts.getEndLine() - ts.getStartLine() + 1;
}
- private TextEdit createReplaceEdit(int line, int visualStartColumn, int visualEndColumn, String replacement) throws BadLocationException {
+ private TextEdit createReplaceEdit(int line, int visualStartColumn, int visualEndColumn, String replacement, boolean delete) throws BadLocationException {
IRegion info= fDocument.getLineInformation(line);
int lineLength= info.getLength();
String content= fDocument.get(info.getOffset(), lineLength);
@@ -400,11 +407,30 @@ public final class SelectionProcessor {
int endColumn= -1;
int visual= 0;
for (int offset= 0; offset < lineLength; offset++) {
- if (startColumn == -1 && visual >= visualStartColumn)
- startColumn= offset;
- if (visual >= visualEndColumn) {
- endColumn= offset;
- break;
+ if (startColumn == -1) {
+ if (visual == visualStartColumn)
+ if (!delete && isWider(content.charAt(offset), visual) && replacement.length() == 0)
+ startColumn= offset - 1;
+ else
+ startColumn= offset;
+ else if (visual > visualStartColumn) {
+ if (isWider(content.charAt(offset - 1), visual))
+ startColumn= offset - 1;
+ else
+ startColumn= offset;
+ }
+ }
+ if (startColumn != -1) {
+ if (visual == visualEndColumn) {
+ endColumn= offset;
+ break;
+ } else if (visual > visualEndColumn) {
+ if (!delete && isWider(content.charAt(offset - 1), visual))
+ endColumn= offset - 1;
+ else
+ endColumn= offset;
+ break;
+ }
}
visual+= visualSizeIncrement(content.charAt(offset), visual);
}
@@ -476,6 +502,10 @@ public final class SelectionProcessor {
return lineLength + Math.max(0, visualColumn - visual);
}
+ private boolean isWider(char character, int visual) {
+ return visualSizeIncrement(character, visual) > 1;
+ }
+
/**
* Returns the increment in visual length represented by <code>character</code> given the
* current visual length. The visual length is <code>1</code> unless <code>character</code>
@@ -487,6 +517,18 @@ public final class SelectionProcessor {
* <code>[0,fTabWidth]</code>
*/
private int visualSizeIncrement(char character, int visual) {
+ if (character > 255 && fStyledText != null) {
+ GC gc= null;
+ try {
+ gc= new GC(fStyledText);
+ int charWidth= gc.stringExtent(new String(Character.toString(character))).x;
+ int singleCharWidth= gc.stringExtent(" ").x; //$NON-NLS-1$
+ return (int)Math.ceil(charWidth / singleCharWidth);
+ } finally {
+ if (gc != null)
+ gc.dispose();
+ }
+ }
if (character != '\t')
return 1;
if (fTabWidth <= 0)
@@ -503,6 +545,8 @@ public final class SelectionProcessor {
private ISelectionProvider fSelectionProvider;
+ private StyledText fStyledText;
+
/**
* Creates a new processor on the given viewer.
*
@@ -515,6 +559,7 @@ public final class SelectionProcessor {
fRewriteTarget= ext.getRewriteTarget();
}
fSelectionProvider= viewer.getSelectionProvider();
+ fStyledText= viewer.getTextWidget();
}
/**

Back to the top