本文整理汇总了Java中org.eclipse.jface.text.IFindReplaceTarget.getSelection方法的典型用法代码示例。如果您正苦于以下问题:Java IFindReplaceTarget.getSelection方法的具体用法?Java IFindReplaceTarget.getSelection怎么用?Java IFindReplaceTarget.getSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.IFindReplaceTarget
的用法示例。
在下文中一共展示了IFindReplaceTarget.getSelection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findNext
import org.eclipse.jface.text.IFindReplaceTarget; //导入方法依赖的package包/类
/**
* Find the next occurrence of empty line(s)
* Will match all valid lines except single ^$
*
* @param editor
* @param forward true if moving forward
* @return -1 if not found, else offset of match in widget coords
*/
protected int findNext(ITextEditor editor, boolean forward) {
IFindReplaceTarget frt = getTarget(editor);
Point selection = frt.getSelection();
// don't move past eob
int offset = Math.min(MarkUtils.getCharCount(editor), Math.max(0,MarkUtils.getCaretOffset(editor) + (forward ? 1 : -2)));
int result = ((IFindReplaceTargetExtension3)frt).findAndSelect(offset, PARAGRAPH_START, forward, false, false, true);
if (result != -1) {
if ((forward && offset > result) || (!forward && offset < result)) {
// reset if we've wrapped around in the search
MarkUtils.setWidgetSelection(editor, selection.x, selection.x + selection.y);
result = -1;
}
}
return result;
}
示例2: findTarget
import org.eclipse.jface.text.IFindReplaceTarget; //导入方法依赖的package包/类
/**
* Refine target search to not proceed beyond a region limit, if present
*
* @see com.mulgasoft.emacsplus.minibuffer.SearchMinibuffer#findTarget(org.eclipse.jface.text.IFindReplaceTarget, java.lang.String, int, boolean)
*/
protected int findTarget(IFindReplaceTarget target, String searchStr, int searchIndex, boolean forward) {
int result = WRAP_INDEX;
StyledText text = getTextWidget();
try {
text.setRedraw(false);
result = super.findTarget(target,searchStr,searchIndex,forward);
// if present, check if we've gone past the end of the region
if (getLimit() != WRAP_INDEX && result != WRAP_INDEX) {
int pos = MarkUtils.widget2ModelOffset(getViewer(), result);
// include length of search result in check
if (pos + target.getSelection().y > getLimit()) {
result = WRAP_INDEX;
// restore last position the region
setSelection(searchIndex);
}
}
} finally {
text.setRedraw(true);
}
return result;
}
示例3: getSelection
import org.eclipse.jface.text.IFindReplaceTarget; //导入方法依赖的package包/类
protected Point getSelection() {
Point result = null;
IFindReplaceTarget target = getTarget();
if (target != null) {
result = target.getSelection();
}
return result;
}
示例4: findNextEmpty
import org.eclipse.jface.text.IFindReplaceTarget; //导入方法依赖的package包/类
/**
* Find the next occurrence of empty line consisting of ^$
* Since findNext will find multiple sequential ^$'s, we only need find one
*
* @param editor
* @param forward
* @return offset of match in widget coords
*/
protected int findNextEmpty(ITextEditor editor, boolean forward) {
IFindReplaceTarget frt = getTarget(editor);
Point selection = frt.getSelection();
int count = MarkUtils.getCharCount(editor);
int coffset = MarkUtils.getCaretOffset(editor);
// don't move past EOB
int offset = Math.min(count,coffset + (forward ? 1 : -1)); //(forward ? selection.x + selection.y+1 : selection.x-2);
int next = 0;
int prev = -1;
do {
next = ((IFindReplaceTargetExtension3)frt).findAndSelect(offset, REGEX_BOL_HACK, forward, false, false, true);
if (next == -1 || prev == next){
// we've run out of buffer
offset = (forward ? count : 0);
MarkUtils.setWidgetSelection(editor, offset, offset);
return offset;
} else if (forward && offset > next) {
// protect against overrun
MarkUtils.setWidgetSelection(editor, count, count);
return count;
} else if (!forward && offset < next) {
// protect against overrun
MarkUtils.setWidgetSelection(editor, 0, 0);
return 0;
} else {
selection = frt.getSelection();
// Eclipse internals (frda) return different regions depending on whether the file has a
// single or double line delimiter e.g. \r\n or \n. In the former it returns a 0 length
// region, and in the latter a length of 1
if (selection.y == 0 || (!forward && selection.x == 0)) {
// found it, or reached the top
return selection.x;
} if (selection.y == 1) {
// check for single line delimiter
char c = frt.getSelectionText().charAt(0);
if (c == '\n' || c == '\r'){
return selection.x;
}
}
// the widget count could change if a folded region expands automatically
count = MarkUtils.getCharCount(editor);
// don't move past EOB
offset = Math.min(count,(forward ? selection.x + selection.y+1 : selection.x-1));
prev = next;
}
} while (next != -1);
return next;
}
示例5: replaceIt
import org.eclipse.jface.text.IFindReplaceTarget; //导入方法依赖的package包/类
/**
* Perform one replacement
*
* @return the replacement index
*/
private boolean replaceIt() {
boolean result = false;
boolean forward = true;
if (!checkPaused()) {
findCount++;
try {
result = true;
int index = getSearchOffset();
IFindReplaceTarget target = getTarget();
int fpos = findTarget(target,getSearchStr(), index, forward);
if (fpos > -1) {
boolean initial = false;
boolean all = false;
String replacer = replaceStr;
if (!isCaseSensitive() && replacer.length() > 0) {
// Preserve case using the emacs definition
// - Preserving case means that if the string matched is all caps, or capitalized,
// then its replacement is upper cased or capitalized.)
String replacee = target.getSelectionText().trim();
if (replacee != null && replacee.length() > 0) {
initial = Character.isUpperCase(replacee.charAt(0));
all = initial;
if (initial) {
for (int i = 1; i < replacee.length(); i++) {
if (!Character.isUpperCase(replacee.charAt(i))) {
all = false;
break;
}
}
}
}
}
int adjust = 0;
if (all || initial) {
caseReplace(replacer,index,all);
} else {
if (isRegexLD()) {
adjust = replacer.length(); // prevents repetitious find of same EOL
// now we need the offset in model coords
ITextSelection sel = (ITextSelection)getEditor().getSelectionProvider().getSelection();
// use document 'insert' instead of broken target replace
getDocument().replace(sel.getOffset(),0,replacer);
// search uses cursor position - s/r is always forward
MarkUtils.setCursorOffset(getEditor(), sel.getOffset()+adjust);
} else {
((IFindReplaceTargetExtension3)target).replaceSelection(replacer, isRegexp());
}
}
Point p = target.getSelection();
int rIndex = p.x + p.y + adjust;
setSearchOffset(rIndex);
}
} catch (Exception e) {
setResultString(e.getLocalizedMessage(), true);
finish();
beep();
}
}
return result;
}