1 package jp.sourceforge.moreemacs.handlers;
3 import jp.sourceforge.moreemacs.utils.CodePointIterator;
4 import jp.sourceforge.moreemacs.utils.DocumentCharSequence;
6 import org.eclipse.jface.text.BadLocationException;
7 import org.eclipse.jface.text.IDocument;
8 import org.eclipse.jface.text.IRegion;
10 public final class DeleteHorizontalSpaceExecution extends TextEditorExecution {
13 public void execute() throws BadLocationException {
14 if(!textEditor.isEditable()) {
18 int current = cursor.offset();
19 int start = skipBackwardSpaces(doc, current);
20 int end = skipForwardSpaces(doc, current);
21 doc.replace(start, end - start, "");
24 int skipBackwardSpaces(IDocument doc, int offset) throws BadLocationException {
25 IRegion line = doc.getLineInformationOfOffset(offset);
27 CharSequence seq = new DocumentCharSequence(doc,
28 line.getOffset(), offset-line.getOffset());
31 for(CodePointIterator itr = new CodePointIterator(seq, seq.length()); itr.hasPrevious(); ) {
32 int codePoint = itr.previous();
33 if (!Character.isWhitespace(codePoint)) {
36 result = line.getOffset() + itr.index();
41 int skipForwardSpaces(IDocument doc, int offset) throws BadLocationException {
42 IRegion line = doc.getLineInformationOfOffset(offset);
43 CharSequence seq = new DocumentCharSequence(doc,
44 offset,line.getOffset()+line.getLength()-offset);
46 for(CodePointIterator itr = new CodePointIterator(seq); itr.hasNext(); ) {
47 int codePoint = itr.next();
48 if (!Character.isWhitespace(codePoint)) {
51 result = offset + itr.index();