本文整理汇总了Java中com.intellij.openapi.editor.CaretModel.moveToOffset方法的典型用法代码示例。如果您正苦于以下问题:Java CaretModel.moveToOffset方法的具体用法?Java CaretModel.moveToOffset怎么用?Java CaretModel.moveToOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.editor.CaretModel
的用法示例。
在下文中一共展示了CaretModel.moveToOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doEnter
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified) {
if (isModified) {
return false;
}
final CaretModel caretModel = editor.getCaretModel();
PsiElement atCaret = psiElement.getContainingFile().findElementAt(caretModel.getOffset());
if (atCaret instanceof PsiWhiteSpace) {
atCaret = atCaret.getPrevSibling();
}
final PsiElement comment = PsiTreeUtil.getParentOfType(atCaret, PsiComment.class, false);
if (comment != null) {
SmartEnterUtil.plainEnter(editor);
editor.getDocument().insertString(caretModel.getOffset(), "# ");
caretModel.moveToOffset(caretModel.getOffset() + 2);
return true;
}
return false;
}
示例2: doCreateAndNavigate
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
PsiElement[] doCreateAndNavigate(String newName, PsiDirectory directory, String rootTagName, boolean chooseTagName, boolean navigate)
throws Exception {
final XmlFile file = AndroidResourceUtil
.createFileResource(newName, directory, rootTagName, myResourceType.getName(), myValuesResourceFile);
if (navigate) {
doNavigate(file);
}
if (chooseTagName) {
XmlDocument document = file.getDocument();
if (document != null) {
XmlTag rootTag = document.getRootTag();
if (rootTag != null) {
final Project project = file.getProject();
final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor != null) {
CaretModel caretModel = editor.getCaretModel();
caretModel.moveToOffset(rootTag.getTextOffset() + 1);
XmlTagInplaceRenamer.rename(editor, rootTag);
}
}
}
}
return new PsiElement[]{file};
}
示例3: getDialogAction
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@NotNull
protected Runnable getDialogAction(@NotNull final T dialog, @NotNull final TextEditor editor) {
return new Runnable() {
@Override
public void run() {
final Document document = editor.getEditor().getDocument();
final CaretModel caretModel = editor.getEditor().getCaretModel();
final String content = getContent(dialog);
int offset = caretModel.getOffset();
document.insertString(offset, content);
caretModel.moveToOffset(offset + content.length());
}
};
}
示例4: wrap
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
/**
* Wraps selection.
*
* @param editor Current editor.
*/
private void wrap(@NotNull TextEditor editor) {
final Document document = editor.getEditor().getDocument();
final SelectionModel selectionModel = editor.getEditor().getSelectionModel();
final CaretModel caretModel = editor.getEditor().getCaretModel();
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
final String text = StringUtil.notNullize(selectionModel.getSelectedText());
String newText = getLeftText() + text + getRightText();
int newStart = start + getLeftText().length();
int newEnd = StringUtil.isEmpty(text) ? newStart : end + getLeftText().length();
document.replaceString(start, end, newText);
selectionModel.setSelection(newStart, newEnd);
caretModel.moveToOffset(newEnd);
}
示例5: unwrap
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
/**
* Unwraps selection.
*
* @param editor Current editor.
* @param matched Matched PSI element.
*/
private void unwrap(@NotNull final TextEditor editor, @NotNull final PsiElement matched) {
final Document document = editor.getEditor().getDocument();
final SelectionModel selectionModel = editor.getEditor().getSelectionModel();
final CaretModel caretModel = editor.getEditor().getCaretModel();
final int start = matched.getTextRange().getStartOffset();
final int end = matched.getTextRange().getEndOffset();
final String text = StringUtil.notNullize(matched.getText());
String newText = StringUtil.trimEnd(StringUtil.trimStart(text, getLeftText()), getRightText());
int newStart = selectionModel.getSelectionStart() - getLeftText().length();
int newEnd = selectionModel.getSelectionEnd() - getLeftText().length();
document.replaceString(start, end, newText);
selectionModel.setSelection(newStart, newEnd);
caretModel.moveToOffset(newEnd);
}
示例6: execute
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void execute(Editor editor, DataContext dataContext) {
if (!(editor instanceof EditorEx)) {
return;
}
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
return;
}
EditorEx editorEx = (EditorEx)editor;
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
final CaretModel caretModel = editor.getCaretModel();
boolean moveToEnd = caretModel.getOffset() == start;
editorEx.setStickySelection(false);
editorEx.setStickySelection(true);
if (moveToEnd) {
caretModel.moveToOffset(end);
}
else {
caretModel.moveToOffset(start);
}
}
示例7: processIntention
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
final PsiNameValuePair attribute = (PsiNameValuePair)element;
final int textOffset = attribute.getTextOffset();
final Project project = attribute.getProject();
final String text = buildReplacementText(attribute);
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
final PsiAnnotation newAnnotation = factory.createAnnotationFromText("@A(" + text +" )", attribute);
attribute.replace(newAnnotation.getParameterList().getAttributes()[0]);
final FileEditorManager editorManager = FileEditorManager.getInstance(project);
final Editor editor = editorManager.getSelectedTextEditor();
if (editor == null) {
return;
}
final CaretModel caretModel = editor.getCaretModel();
caretModel.moveToOffset(textOffset + text.length() - 1);
}
示例8: highlightAndOfferHint
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
public void highlightAndOfferHint(Editor editor, int offset,
Interval sourceInterval,
JBColor color,
EffectType effectType, String hintText) {
CaretModel caretModel = editor.getCaretModel();
final TextAttributes attr = new TextAttributes();
attr.setForegroundColor(color);
attr.setEffectColor(color);
attr.setEffectType(effectType);
MarkupModel markupModel = editor.getMarkupModel();
markupModel.addRangeHighlighter(
sourceInterval.a,
sourceInterval.b,
InputPanel.TOKEN_INFO_LAYER, // layer
attr,
HighlighterTargetArea.EXACT_RANGE
);
if ( hintText.contains("<") ) {
hintText = hintText.replaceAll("<", "<");
}
// HINT
caretModel.moveToOffset(offset); // info tooltip only shows at cursor :(
HintManager.getInstance().showInformationHint(editor, hintText);
}
示例9: execute
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void execute(Editor editor, DataContext dataContext) {
if (!(editor instanceof EditorEx)) {
return;
}
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
return;
}
EditorEx editorEx = (EditorEx)editor;
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
final CaretModel caretModel = editor.getCaretModel();
boolean moveToEnd = caretModel.getOffset() == start;
editorEx.setStickySelection(false);
editorEx.setStickySelection(true);
if (moveToEnd) {
caretModel.moveToOffset(end);
}
else {
caretModel.moveToOffset(start);
}
}
示例10: moveCaretToTheLineEndIfPossible
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
private static void moveCaretToTheLineEndIfPossible(@NotNull Editor editor, int line) {
final Document document = editor.getDocument();
final CaretModel caretModel = editor.getCaretModel();
int offset;
if (line >= document.getLineCount()) {
offset = document.getTextLength();
}
else {
offset = document.getLineEndOffset(line);
}
caretModel.moveToOffset(offset);
}
示例11: moveCaret
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
protected static int moveCaret(final Editor editor, final int tailOffset, final int delta) {
final CaretModel model = editor.getCaretModel();
if (model.getOffset() == tailOffset) {
model.moveToOffset(tailOffset + delta);
}
return tailOffset + delta;
}
示例12: beforeCharTyped
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public Result beforeCharTyped(final char charTyped, final Project project, final Editor editor, final PsiFile file, final FileType fileType) {
// TODO[oleg] remove this hack when API changes
if (myReplacedTextRange != null) {
if (myReplacedTextRange.getEndOffset() <= editor.getDocument().getTextLength()) {
if (myRestoreStickySelection && editor instanceof EditorEx) {
EditorEx editorEx = (EditorEx)editor;
CaretModel caretModel = editorEx.getCaretModel();
caretModel.moveToOffset(myLtrSelection ? myReplacedTextRange.getStartOffset() : myReplacedTextRange.getEndOffset());
editorEx.setStickySelection(true);
caretModel.moveToOffset(myLtrSelection ? myReplacedTextRange.getEndOffset() : myReplacedTextRange.getStartOffset());
}
else {
if (myLtrSelection || editor instanceof EditorWindow) {
editor.getSelectionModel().setSelection(myReplacedTextRange.getStartOffset(), myReplacedTextRange.getEndOffset());
}
else {
editor.getSelectionModel().setSelection(myReplacedTextRange.getEndOffset(), myReplacedTextRange.getStartOffset());
}
if (Registry.is("editor.smarterSelectionQuoting")) {
editor.getCaretModel().moveToOffset(myLtrSelection ? myReplacedTextRange.getEndOffset() : myReplacedTextRange.getStartOffset());
}
}
}
myReplacedTextRange = null;
return Result.STOP;
}
return Result.CONTINUE;
}
示例13: handleInsert
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
super.handleInsert(context, item);
context.setAddCompletionChar(false);
final CaretModel caretModel = context.getEditor().getCaretModel();
context.getEditor().getDocument().insertString(caretModel.getOffset(), ";");
caretModel.moveToOffset(caretModel.getOffset() + 1);
}
示例14: processIntention
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
protected void processIntention(Editor editor, @NotNull PsiElement element) {
final CaretModel caretModel = editor.getCaretModel();
final int offset = caretModel.getOffset();
super.processIntention(editor, element);
caretModel.moveToOffset(offset);
}
示例15: handleInsert
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement element)
{
Editor editor = context.getEditor();
CaretModel caretModel = editor.getCaretModel();
Document document = context.getEditor().getDocument();
PhpFile file = (PhpFile) context.getFile();
PsiElement currElement = file.findElementAt(editor.getCaretModel().getOffset());
StringBuilder buffer = new StringBuilder();
int newOffset = caretModel.getOffset();
if (insertSpace) {
buffer.append(' ');
newOffset++;
}
PsiElement testElement = currElement;
if (testElement!= null && !(testElement.getNode().getElementType().equals(PhpDocPropertyTagParser.DOC_WHITESPACE))) {
testElement = testElement.getNextSibling();
}
if (testElement != null && !(testElement.getNode().getElementType().equals(PhpDocPropertyTagParser.DOC_RBRACE))) {
buffer.append('}');
}
document.insertString(caretModel.getOffset(), buffer.toString());
caretModel.moveToOffset(newOffset);
}