-package jp.sourceforge.moreemacs.handlers;\r
-\r
-import jp.sourceforge.moreemacs.utils.CodePointIterator;\r
-import jp.sourceforge.moreemacs.utils.DocumentCharSequence;\r
-\r
-import org.eclipse.jface.text.BadLocationException;\r
-import org.eclipse.jface.text.IDocument;\r
-import org.eclipse.jface.text.IRegion;\r
-\r
-public final class DeleteHorizontalSpaceExecution extends TextEditorExecution {\r
- \r
- @Override\r
- public void execute() throws BadLocationException {\r
- if(!textEditor.isEditable()) {\r
- return;\r
- }\r
- \r
- int current = cursor.offset();\r
- int start = skipBackwardSpaces(doc, current);\r
- int end = skipForwardSpaces(doc, current);\r
- doc.replace(start, end - start, "");\r
- }\r
- \r
- int skipBackwardSpaces(IDocument doc, int offset) throws BadLocationException {\r
- IRegion line = doc.getLineInformationOfOffset(offset);\r
- \r
- CharSequence seq = new DocumentCharSequence(doc, \r
- line.getOffset(), offset-line.getOffset());\r
- \r
- int result = offset;\r
- for(CodePointIterator itr = new CodePointIterator(seq, seq.length()); itr.hasPrevious(); ) {\r
- int codePoint = itr.previous();\r
- if (!Character.isWhitespace(codePoint)) {\r
- break;\r
- }\r
- result = line.getOffset() + itr.index();\r
- }\r
- return result;\r
- }\r
- \r
- int skipForwardSpaces(IDocument doc, int offset) throws BadLocationException {\r
- IRegion line = doc.getLineInformationOfOffset(offset);\r
- CharSequence seq = new DocumentCharSequence(doc, \r
- offset,line.getOffset()+line.getLength()-offset);\r
- int result = offset;\r
- for(CodePointIterator itr = new CodePointIterator(seq); itr.hasNext(); ) {\r
- int codePoint = itr.next();\r
- if (!Character.isWhitespace(codePoint)) {\r
- break;\r
- }\r
- result = offset + itr.index();\r
- }\r
- return result;\r
- }\r
-}\r
+package jp.sourceforge.moreemacs.handlers;
+
+import jp.sourceforge.moreemacs.utils.CodePointIterator;
+import jp.sourceforge.moreemacs.utils.DocumentCharSequence;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+
+public final class DeleteHorizontalSpaceExecution extends TextEditorExecution {
+
+ @Override
+ public void execute() throws BadLocationException {
+ if(!textEditor.isEditable()) {
+ return;
+ }
+
+ int current = cursor.offset();
+ int start = skipBackwardSpaces(doc, current);
+ int end = skipForwardSpaces(doc, current);
+ doc.replace(start, end - start, "");
+ }
+
+ int skipBackwardSpaces(IDocument doc, int offset) throws BadLocationException {
+ IRegion line = doc.getLineInformationOfOffset(offset);
+
+ CharSequence seq = new DocumentCharSequence(doc,
+ line.getOffset(), offset-line.getOffset());
+
+ int result = offset;
+ for(CodePointIterator itr = new CodePointIterator(seq, seq.length()); itr.hasPrevious(); ) {
+ int codePoint = itr.previous();
+ if (!Character.isWhitespace(codePoint)) {
+ break;
+ }
+ result = line.getOffset() + itr.index();
+ }
+ return result;
+ }
+
+ int skipForwardSpaces(IDocument doc, int offset) throws BadLocationException {
+ IRegion line = doc.getLineInformationOfOffset(offset);
+ CharSequence seq = new DocumentCharSequence(doc,
+ offset,line.getOffset()+line.getLength()-offset);
+ int result = offset;
+ for(CodePointIterator itr = new CodePointIterator(seq); itr.hasNext(); ) {
+ int codePoint = itr.next();
+ if (!Character.isWhitespace(codePoint)) {
+ break;
+ }
+ result = offset + itr.index();
+ }
+ return result;
+ }
+}