private final ITextEditor textEditor;\r
private final ITextViewerExtension5 textViewerEx5;\r
private final StyledText styledText;\r
+ private final ITextViewer textViewer;\r
\r
Cursor(ITextEditor textEditor, ITextViewer textViewer) {\r
this.textEditor = textEditor;\r
+ this.textViewer = textViewer;\r
this.styledText = textViewer.getTextWidget();\r
this.textViewerEx5 = (textViewer instanceof ITextViewerExtension5)\r
? (ITextViewerExtension5) textViewer: null;\r
}\r
\r
void move(int offset) {\r
+ textViewer.setSelectedRange(offset, 0);\r
+ textViewer.revealRange(offset, 0);\r
+\r
+// workaround for ISourceViewer\r
+// sourceViewer.setRangeIndication(offset, 0, true);\r
+\r
+// workaround for ITextViewerExtension5\r
// if(textViewerEx5 != null) {\r
// styledText.setCaretOffset(textViewerEx5.modelOffset2WidgetOffset(offset));\r
+//\r
// return;\r
// }\r
\r
- textEditor.resetHighlightRange();\r
- textEditor.setHighlightRange(offset, 0, true);\r
+// workaround for ITextEditor\r
+// textEditor.resetHighlightRange();\r
+// textEditor.setHighlightRange(offset, 0, true);\r
}\r
}\r
endColumn = work;\r
}\r
\r
+ int offset = cursor.offset();\r
DocumentTransaction transaction = new DocumentTransaction(doc); \r
transaction.begin();\r
try {\r
- List<String> rectangle = killRectangle(doc, startRow, startColumn, endRow, endColumn);\r
+ List<String> rectangle = new ArrayList<String>();\r
+ offset = killRectangle(doc, startRow, startColumn, endRow, endColumn, rectangle);\r
RectangleStorage.setRectangle(rectangle);\r
} finally {\r
transaction.end();\r
}\r
+ cursor.move(offset);\r
}\r
- private List<String> killRectangle(IDocument doc,\r
+ private int killRectangle(IDocument doc,\r
int startRow, int startColumn,\r
- int endRow, int endColumn)\r
+ int endRow, int endColumn, List<String> rectangle)\r
throws BadLocationException {\r
\r
- List<String> rectangle = new ArrayList<String>();\r
\r
+ int result = cursor.offset();\r
for(int i = startRow; i <= endRow; i++) {\r
- String str = killString(doc, i, startColumn, endColumn);\r
- rectangle.add(str);\r
+ result = killString(doc, i, startColumn, endColumn, rectangle);\r
}\r
- return rectangle;\r
+ return result;\r
}\r
- private String killString(IDocument doc, int row,\r
- int startColumn, int endColumn) throws BadLocationException {\r
+ private int killString(IDocument doc, int row,\r
+ int startColumn, int endColumn, List<String> rectangle) throws BadLocationException {\r
IRegion line = doc.getLineInformation(row);\r
\r
StringBuilder builder = new StringBuilder();\r
}\r
\r
doc.replace(cutOffset, cutLength, "");\r
- cursor.move(cutOffset);\r
\r
\r
for(int i = 0; i < endColumn-column; i++) {\r
builder.append(' ');\r
}\r
\r
- return builder.toString();\r
+ rectangle.add(builder.toString());\r
+ return cutOffset;\r
}\r
\r
}\r
int row = doc.getLineOfOffset(current);\r
int column = ColumnUtils.getColumn(doc, current, getTabStop());\r
\r
- ensureLines(doc, row + rectangle.size());\r
- \r
+\r
+ int offset = cursor.offset();\r
DocumentTransaction transaction = new DocumentTransaction(doc); \r
transaction.begin();\r
try {\r
- yankRectangle(doc, row, column, rectangle);\r
+ ensureLines(doc, row + rectangle.size());\r
+ offset = yankRectangle(doc, row, column, rectangle);\r
} finally {\r
transaction.end();\r
}\r
+ cursor.move(offset);\r
}\r
\r
private void ensureLines(IDocument doc, int lines) throws BadLocationException {\r
\r
}\r
\r
- private void yankRectangle(IDocument doc,\r
+ private int yankRectangle(IDocument doc,\r
int row, int column, List<String> rectangle)\r
throws BadLocationException {\r
+ int offset = cursor.offset();\r
for(int i = 0; i < rectangle.size(); i++) {\r
- yankString(doc, row+i, column, rectangle.get(i));\r
+ offset = yankString(doc, row+i, column, rectangle.get(i));\r
}\r
+ return offset;\r
}\r
\r
- private void yankString(IDocument doc, int row, int column, String str)\r
+ private int yankString(IDocument doc, int row, int column, String str)\r
throws BadLocationException\r
{\r
IRegion line = doc.getLineInformation(row);\r
int codePoint = itr.next();\r
if(col >= column) {\r
doc.replace(offset, 0, str);\r
- cursor.move(offset+str.length());\r
- return;\r
+ return offset+str.length();\r
}\r
col = ColumnUtils.getNextColumn(col, codePoint, getTabStop());\r
}\r
}\r
builder.append(str);\r
doc.replace(line.getOffset()+line.getLength(), 0, builder.toString());\r
- cursor.move(line.getOffset()+line.getLength()+builder.length());\r
+ return line.getOffset()+line.getLength()+builder.length();\r
}\r
\r
}\r