import org.eclipse.jface.text.IDocument;\r
\r
public final class BackwardWordExecution extends TextEditorExecution {\r
-\r
- @Override\r
- public void execute() throws BadLocationException {\r
- int current = cursor.offset();\r
- cursor.move(getPreviousWordPosition(doc, current));\r
- }\r
- \r
- public static int getPreviousWordPosition(IDocument doc, int offset) throws BadLocationException {\r
+ @Override\r
+ public void execute() throws BadLocationException {\r
+ int current = cursor.offset();\r
+ cursor.move(getPreviousWordPosition(doc, current));\r
+ }\r
+ \r
+ public static int getPreviousWordPosition(IDocument doc, int offset) throws BadLocationException {\r
CharSequence seq = new DocumentCharSequence(doc, 0, offset);\r
CodePointIterator itr = new CodePointIterator(seq, seq.length());\r
-\r
+ \r
for(; itr.hasPrevious(); ) {\r
if (Character.isLetterOrDigit(itr.previous())) {\r
itr.next();\r
break;\r
}\r
}\r
- \r
- return itr.index();\r
- }\r
-\r
+ return itr.index();\r
+ }\r
}\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
+ \r
+ @Override\r
+ public void execute() throws BadLocationException {\r
if(!textEditor.isEditable()) {\r
return;\r
}\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
+ doc.replace(start, end - start, "");\r
+ }\r
+ \r
+ int skipBackwardSpaces(IDocument doc, int offset) throws BadLocationException {\r
IRegion line = doc.getLineInformationOfOffset(offset);\r
-\r
+ \r
CharSequence seq = new DocumentCharSequence(doc, \r
line.getOffset(), offset-line.getOffset());\r
-\r
+ \r
int result = offset;\r
for(CodePointIterator itr = new CodePointIterator(seq, seq.length()); itr.hasPrevious(); ) {\r
int codePoint = itr.previous();\r
}\r
result = line.getOffset() + itr.index();\r
}\r
- return result;\r
- }\r
- \r
- int skipForwardSpaces(IDocument doc, int offset) throws BadLocationException {\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
}\r
result = offset + itr.index();\r
}\r
- return result;\r
- }\r
+ return result;\r
+ }\r
}\r
import org.eclipse.swt.dnd.Transfer;\r
\r
public final class KillLineExecution extends TextEditorExecution {\r
-\r
- @Override\r
- public void execute() throws BadLocationException {\r
+ @Override\r
+ public void execute() throws BadLocationException {\r
if(!textEditor.isEditable()) {\r
return;\r
}\r
-\r
- int current = cursor.offset();\r
- int linePos = doc.getLineOfOffset(current);\r
- IRegion line = doc.getLineInformation(linePos);\r
- String delim = doc.getLineDelimiter(linePos);\r
-\r
- int length = line.getOffset() + line.getLength() - current;\r
- boolean allSpaces = isAllSpaces(doc, current, length);\r
-\r
- int cutLength = length;\r
- if (allSpaces && delim != null) {\r
- cutLength += delim.length();\r
- }\r
-\r
- String cut = doc.get(current, cutLength);\r
- Clipboard c = new Clipboard(window.getShell().getDisplay());\r
- c.setContents(\r
- new String[] { cut }, \r
- new Transfer[] { TextTransfer.getInstance() });\r
- doc.replace(current, cutLength, "");\r
- }\r
- \r
- private boolean isAllSpaces(IDocument doc, int offset, int length) throws BadLocationException {\r
+ \r
+ int current = cursor.offset();\r
+ int linePos = doc.getLineOfOffset(current);\r
+ IRegion line = doc.getLineInformation(linePos);\r
+ String delim = doc.getLineDelimiter(linePos);\r
+ \r
+ int length = line.getOffset() + line.getLength() - current;\r
+ boolean allSpaces = isAllSpaces(doc, current, length);\r
+ \r
+ int cutLength = length;\r
+ if (allSpaces && delim != null) {\r
+ cutLength += delim.length();\r
+ }\r
+ \r
+ String cut = doc.get(current, cutLength);\r
+ Clipboard c = new Clipboard(window.getShell().getDisplay());\r
+ c.setContents(\r
+ new String[] { cut }, \r
+ new Transfer[] { TextTransfer.getInstance() });\r
+ doc.replace(current, cutLength, "");\r
+ }\r
+ \r
+ private boolean isAllSpaces(IDocument doc, int offset, int length) throws BadLocationException {\r
CharSequence seq = new DocumentCharSequence(doc, offset, length);\r
for(int codePoint : CodePointIterator.each(seq)) {\r
if (!Character.isWhitespace(codePoint)) {\r
}\r
}\r
return true;\r
- }\r
+ }\r
}\r
import org.eclipse.jface.text.IRegion;\r
\r
public final class MoveBeginningOfLineExecution extends TextEditorExecution {\r
- @Override\r
- public void execute() throws BadLocationException {\r
- IRegion line = doc.getLineInformationOfOffset(cursor.offset());\r
- cursor.move(line.getOffset());\r
- }\r
+ @Override\r
+ public void execute() throws BadLocationException {\r
+ IRegion line = doc.getLineInformationOfOffset(cursor.offset());\r
+ cursor.move(line.getOffset());\r
+ }\r
}\r
\r
int current = selection.getOffset();\r
\r
int start = (mark < current) ? mark : current;\r
- //textEditor.selectAndReveal(start, Math.abs(mark - current));\r
textViewer.setSelectedRange(start, Math.abs(mark - current));\r
-\r
\r
return (ITextSelection) textEditor\r
.getSelectionProvider().getSelection();\r
doc.replace(line.getOffset()+line.getLength(), 0, builder.toString());\r
return line.getOffset()+line.getLength()+builder.length();\r
}\r
-\r
}\r
-\r
-\r