-package jp.sourceforge.moreemacs.handlers;\r
-\r
-import jp.sourceforge.moreemacs.utils.DocumentCharSequence;\r
-\r
-import org.eclipse.jface.text.BadLocationException;\r
-import org.eclipse.jface.text.IRegion;\r
-\r
-public final class TransposeCharsExecution extends TextEditorExecution {\r
- @Override\r
- public void execute() throws BadLocationException {\r
- if(!textEditor.isEditable()) {\r
- return;\r
- }\r
-\r
- int current = cursor.offset();\r
- if(current == 0) {\r
- // beginning of document\r
- return;\r
- }\r
-\r
- int linePos = doc.getLineOfOffset(current);\r
- IRegion line = doc.getLineInformation(linePos);\r
- \r
- DocumentCharSequence seq = new DocumentCharSequence(doc);\r
-\r
- if(line.getOffset() + line.getLength() == current) {\r
- // if end of line, adjust current position\r
- current = (line.getOffset() == current)\r
- ? current - doc.getLineDelimiter(linePos-1).length() \r
- : seq.previousCodePointIndex(current);\r
- linePos = doc.getLineOfOffset(current);\r
- line = doc.getLineInformation(linePos);\r
- }\r
- if(current == 0) {\r
- // beginning of document again\r
- return;\r
- }\r
-\r
- int nextIndex = seq.nextCodePointIndex(current);\r
- String forwardChars = (line.getOffset() + line.getLength() == current) \r
- ? doc.getLineDelimiter(linePos) : doc.get(current, nextIndex - current);\r
- \r
- int prevIndex = seq.previousCodePointIndex(current);\r
- String backwardChars = (line.getOffset() == current) \r
- ? doc.getLineDelimiter(linePos-1) : doc.get(prevIndex, current-prevIndex);\r
-\r
- doc.replace(current-backwardChars.length(), \r
- backwardChars.length() + forwardChars.length(),\r
- forwardChars+backwardChars);\r
- }\r
- \r
-}\r
+package jp.sourceforge.moreemacs.handlers;
+
+import jp.sourceforge.moreemacs.utils.DocumentCharSequence;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IRegion;
+
+public final class TransposeCharsExecution extends TextEditorExecution {
+ @Override
+ public void execute() throws BadLocationException {
+ if(!textEditor.isEditable()) {
+ return;
+ }
+
+ int current = cursor.offset();
+ if(current == 0) {
+ // beginning of document
+ return;
+ }
+
+ int linePos = doc.getLineOfOffset(current);
+ IRegion line = doc.getLineInformation(linePos);
+
+ DocumentCharSequence seq = new DocumentCharSequence(doc);
+
+ if(line.getOffset() + line.getLength() == current) {
+ // if end of line, adjust current position
+ current = (line.getOffset() == current)
+ ? current - doc.getLineDelimiter(linePos-1).length()
+ : seq.previousCodePointIndex(current);
+ linePos = doc.getLineOfOffset(current);
+ line = doc.getLineInformation(linePos);
+ }
+ if(current == 0) {
+ // beginning of document again
+ return;
+ }
+
+ int nextIndex = seq.nextCodePointIndex(current);
+ String forwardChars = (line.getOffset() + line.getLength() == current)
+ ? doc.getLineDelimiter(linePos) : doc.get(current, nextIndex - current);
+
+ int prevIndex = seq.previousCodePointIndex(current);
+ String backwardChars = (line.getOffset() == current)
+ ? doc.getLineDelimiter(linePos-1) : doc.get(prevIndex, current-prevIndex);
+
+ doc.replace(current-backwardChars.length(),
+ backwardChars.length() + forwardChars.length(),
+ forwardChars+backwardChars);
+ }
+
+}