本文整理匯總了Java中org.eclipse.jface.text.TextSelection.getLength方法的典型用法代碼示例。如果您正苦於以下問題:Java TextSelection.getLength方法的具體用法?Java TextSelection.getLength怎麽用?Java TextSelection.getLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jface.text.TextSelection
的用法示例。
在下文中一共展示了TextSelection.getLength方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: commentSelection
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
public void commentSelection(TextSelection selection, IDocument doc){
if (selection.getLength() > 0) {
try {
int offset;
offset = selection.getOffset();
doc.replace(offset, 0, commentBegin);
offset += selection.getLength() + commentBegin.length();
doc.replace(offset, 0, commentEnd);
} catch (BadLocationException e) {
e.printStackTrace();
}
} else {
// TODO: Comment the range!
System.out.println("Comment the range!");
}
}
示例2: execute
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
markSpec = getMark();
IEditorPart edPart = HandlerUtil.getActiveEditor(event);
if (edPart instanceof FluentMkEditor) {
editor = (FluentMkEditor) edPart;
doc = editor.getDocument();
if (doc != null) {
ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel instanceof TextSelection) {
TextSelection tsel = (TextSelection) sel;
int beg = tsel.getOffset();
int len = tsel.getLength();
cpos = editor.getCursorOffset();
if (len == 0) beg = cpos;
try {
if (samePartition(beg, len)) {
toggle(beg, len);
}
} catch (BadLocationException e) {}
}
}
}
return null;
}
示例3: execute
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart edPart = HandlerUtil.getActiveEditor(event);
if (edPart instanceof FluentMkEditor) {
FluentMkEditor editor = (FluentMkEditor) edPart;
IDocument doc = editor.getDocument();
if (doc != null) {
ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel instanceof TextSelection) {
TextSelection tsel = (TextSelection) sel;
int beg = tsel.getOffset();
int len = tsel.getLength();
switch (checkPartition(doc, beg, len)) {
case NONE:
addComment(doc, beg, len);
break;
case SAME:
removeComment(doc, beg);
break;
}
}
}
}
return null;
}
示例4: run
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public void run() {
IXtextDocument document = editor.getDocument();
ISelection selection = editor.getSelectionProvider().getSelection();
if (selection instanceof TextSelection) {
TextSelection textSelection = (TextSelection) selection;
if (textSelection.getLength()==0) {
IRegion region = matcher.match(document, textSelection.getOffset());
if (region != null) {
if (region.getOffset()+1==textSelection.getOffset()) {
editor.selectAndReveal(region.getOffset()+region.getLength(),0);
} else {
editor.selectAndReveal(region.getOffset()+1,0);
}
}
}
}
}
示例5: execute
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public @Nullable Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
if (!(editorPart instanceof RustEditor)) {
return null;
}
RustEditor editor = (RustEditor) editorPart;
TextSelection sel = (TextSelection) editor.getSelectionProvider().getSelection();
int startLine = sel.getStartLine();
Optional<IDocument> docOpt = editor.getDocumentOpt();
if (!docOpt.isPresent()) {
return null;
}
IDocument doc = docOpt.get();
try {
int startOffset = doc.getLineOffset(startLine);
int endOffset = sel.getOffset() + sel.getLength();
int len = endOffset - startOffset;
String text = doc.get(startOffset, len);
if (text.matches("^(//(.*)(\\r?\\n|\\r))*//.*$")) {
// remove comments
text = text.substring(2).replaceAll("(\\r?\\n|\\r)//", "$1");
} else {
// add comments
text = "//" + text.replaceAll("(\\r?\\n|\\r)", "$1//");
}
doc.replace(startOffset, len, text);
// select new text
editor.selectAndReveal(startOffset, text.length());
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
return null;
}
示例6: execute
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
NCLEditor editor = ((NCLMultiPageEditor) page.getActiveEditor())
.getNCLEditor();
TextSelection selection = (TextSelection) editor.getSelectionProvider()
.getSelection();
IDocument doc = editor.getInputDocument();
String commentBegin = "<!--";
String commentEnd = "-->";
// TODO: Check if the line is already commented. If it is uncomment the
// line(off
if (selection.getLength() > 0) {
try {
int offset;
int line = selection.getStartLine();
offset = doc.getLineOffset(line);
String rest = doc.get(offset, selection.getOffset() - offset);
int index = rest.indexOf(commentBegin);
if (index != -1){
doc.replace(offset + index, commentBegin.length(), "");
line = selection.getEndLine();
offset = doc.getLineOffset(line) + doc.getLineLength(line);
rest = doc.get (selection.getOffset() + selection.getLength() -
commentBegin.length(), offset);
index = rest.indexOf(commentEnd);
if (index != -1)
doc.replace(selection.getOffset() + selection.getLength() -
commentBegin.length() + index, commentEnd.length(), "");
return null;
}
offset = selection.getOffset();
doc.replace(offset, 0, commentBegin);
offset += selection.getLength() + commentBegin.length();
doc.replace(offset, 0, commentEnd);
} catch (BadLocationException e) {
e.printStackTrace();
}
} else {
// TODO: Comment the range!
System.out.println("Comment the range!");
}
return null;
}
示例7: run
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public void run(IAction action) {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
NCLEditor editor = ((NCLMultiPageEditor) page.getActiveEditor())
.getNCLEditor();
TextSelection selection = (TextSelection) editor.getSelectionProvider()
.getSelection();
IDocument doc = editor.getInputDocument();
String commentBegin = "<!--";
String commentEnd = "-->";
int startLine = selection.getStartLine();
int endLine = selection.getEndLine();
if (selection.getLength() > 0) {
try {
int offset;
offset = selection.getOffset();
IRegion region = doc.getLineInformationOfOffset(offset);
String text = doc.get(doc.getLineOffset(startLine), offset - region.getOffset());
int index = text.lastIndexOf(commentBegin);
if (index != -1)
doc.replace(doc.getLineOffset(startLine) + index, commentBegin.length(), "");
else{
text = selection.getText();
index = text.indexOf(commentBegin);
doc.replace(offset + index, commentBegin.length(), "");
}
offset += selection.getLength();
region = doc.getLineInformationOfOffset(offset);
text = doc.get(offset, doc.getLineLength(endLine) - (offset - region.getOffset()) );
index = text.indexOf(commentEnd);
if (index != -1)
doc.replace(offset, commentEnd.length(), "");
else{
text = selection.getText();
index = text.lastIndexOf(commentEnd);
if (index != -1)
doc.replace(selection.getOffset() + index, commentEnd.length(), "");
}
} catch (BadLocationException e) {
e.printStackTrace();
}
} else {
// TODO: Comment the range!
System.out.println("Comment the range!");
}
return;
}
示例8: getSelectionSR
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
public static SourceRange getSelectionSR(ITextEditor editor) {
TextSelection sel = getSelection(editor);
return new SourceRange(sel.getOffset(), sel.getLength());
}