本文整理汇总了Java中com.intellij.openapi.editor.CaretModel.getLogicalPosition方法的典型用法代码示例。如果您正苦于以下问题:Java CaretModel.getLogicalPosition方法的具体用法?Java CaretModel.getLogicalPosition怎么用?Java CaretModel.getLogicalPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.editor.CaretModel
的用法示例。
在下文中一共展示了CaretModel.getLogicalPosition方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: satisfiedBy
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public boolean satisfiedBy(PsiElement element, @Nullable Editor editor) {
if (editor == null) {
return false;
}
final SelectionModel selectionModel = editor.getSelectionModel();
final Document document = editor.getDocument();
if (selectionModel.hasSelection()) {
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
if (start < 0 || end < 0 || start > end) {
// shouldn't happen but http://ea.jetbrains.com/browser/ea_problems/50192
return false;
}
final String text = document.getCharsSequence().subSequence(start, end).toString();
return indexOfUnicodeEscape(text, 1) >= 0;
}
else {
final CaretModel caretModel = editor.getCaretModel();
final int lineNumber = document.getLineNumber(caretModel.getOffset());
final String line = document.getText(new TextRange(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber)));
final int column = caretModel.getLogicalPosition().column;
final int index = indexOfUnicodeEscape(line, column);
return index >= 0 && column >= index;
}
}
示例2: getWordAtCaretStart
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
private static int getWordAtCaretStart( Project project, String filePath )
{
Editor[] editor = new Editor[1];
editor[0] = getActiveEditor( project );
if( !(editor[0] instanceof EditorImpl) )
{
return -1;
}
EditorImpl editorImpl = (EditorImpl)editor[0];
if( !editorImpl.getVirtualFile().getPath().equals( filePath ) )
{
return -1;
}
CaretModel cm = editorImpl.getCaretModel();
Document document = editorImpl.getDocument();
int offset = cm.getOffset();
if( offset == 0 )
{
return 0;
}
int lineNumber = cm.getLogicalPosition().line;
int newOffset = offset - 1;
int minOffset = lineNumber > 0 ? document.getLineEndOffset( lineNumber - 1 ) : 0;
for( ; newOffset > minOffset; newOffset-- )
{
if( EditorActionUtil.isWordOrLexemeStart( editorImpl, newOffset, false ) )
{
break;
}
}
return newOffset;
}
示例3: executeWriteAction
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
CaretModel caretModel = editor.getCaretModel();
int caretOffset = caretModel.getOffset();
Document document = editor.getDocument();
if (caretOffset >= document.getTextLength()) {
return;
}
int caretLine = caretModel.getLogicalPosition().line;
int lineEndOffset = document.getLineEndOffset(caretLine);
boolean camel = editor.getSettings().isCamelWords();
for (int i = caretOffset + 1; i < lineEndOffset; i++) {
if (EditorActionUtil.isWordOrLexemeEnd(editor, i, camel)) {
KillRingUtil.cut(editor, caretOffset, i);
return;
}
}
int end = lineEndOffset;
if (caretLine < document.getLineCount() - 1 && CharArrayUtil.isEmptyOrSpaces(document.getImmutableCharSequence(), caretOffset, end)) {
// No word end found between the current position and line end, hence, remove line feed sign if possible.
end++;
}
if (end > caretOffset) {
KillRingUtil.cut(editor, caretOffset, end);
}
}
示例4: executeWriteAction
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
CaretModel caretModel = editor.getCaretModel();
int caretOffset = caretModel.getOffset();
Document document = editor.getDocument();
if (caretOffset >= document.getTextLength()) {
return;
}
int caretLine = caretModel.getLogicalPosition().line;
int lineEndOffset = document.getLineEndOffset(caretLine);
CharSequence text = document.getCharsSequence();
boolean camel = editor.getSettings().isCamelWords();
for (int i = caretOffset + 1; i < lineEndOffset; i++) {
if (EditorActionUtil.isWordEnd(text, i, camel)) {
KillRingUtil.cut(editor, caretOffset, i);
return;
}
}
int end = lineEndOffset;
if (caretLine < document.getLineCount() - 1) {
// No word end found between the current position and line end, hence, remove line feed sign if possible.
end++;
}
if (end > caretOffset) {
KillRingUtil.cut(editor, caretOffset, end);
}
}
示例5: actionPerformed
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent event, Project project, FloobitsPlugin plugin, ContextImpl context) {
String projectPath = project.getBasePath();
int line = 0;
String path = null;
Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
Editor editor = PlatformDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext(owner));
if (editor != null) {
Document document = editor.getDocument();
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
CaretModel caretModel = editor.getCaretModel();
LogicalPosition logicalPosition = caretModel.getLogicalPosition();
line = logicalPosition.line + 1;
String absPath = virtualFile != null ? virtualFile.getPath() : null;
path = Utils.toProjectRelPath(absPath, projectPath);
}
FlooUrl flooUrl = DotFloo.read(projectPath);
if (flooUrl == null) {
context.errorMessage(String.format("Could not determine the Floobits workspace for %s, did you create it and join it previously?", path));
return;
}
String urlStr = flooUrl.toString();
if (path != null) {
urlStr = String.format("%s/file/%s:%d", flooUrl, path, line);
}
URI uri;
try {
uri = new URI(urlStr);
} catch (URISyntaxException e) {
Flog.info("Couldn't open settings in browser", e);
return;
}
BrowserOpener.getInstance().openInBrowser(uri, "Click here to go your project's settings.", context);
}
示例6: executeWriteAction
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@RequiredWriteAction
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
CaretModel caretModel = editor.getCaretModel();
int caretOffset = caretModel.getOffset();
Document document = editor.getDocument();
if (caretOffset >= document.getTextLength()) {
return;
}
int caretLine = caretModel.getLogicalPosition().line;
int lineEndOffset = document.getLineEndOffset(caretLine);
CharSequence text = document.getCharsSequence();
boolean camel = editor.getSettings().isCamelWords();
for (int i = caretOffset + 1; i < lineEndOffset; i++) {
if (EditorActionUtil.isWordEnd(text, i, camel)) {
KillRingUtil.cut(editor, caretOffset, i);
return;
}
}
int end = lineEndOffset;
if (caretLine < document.getLineCount() - 1) {
// No word end found between the current position and line end, hence, remove line feed sign if possible.
end++;
}
if (end > caretOffset) {
KillRingUtil.cut(editor, caretOffset, end);
}
}
示例7: navigateToLineEnd
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
public static Result navigateToLineEnd(@NotNull Editor editor, @NotNull PsiFile psiFile)
{
final Document document = editor.getDocument();
final CaretModel caretModel = editor.getCaretModel();
final int offset = caretModel.getOffset();
final CharSequence text = document.getCharsSequence();
int line = caretModel.getLogicalPosition().line;
final int endLineOffset = document.getLineEndOffset(line);
final LogicalPosition endLineLogicalPosition = editor.offsetToLogicalPosition(endLineOffset);
// Stop processing if there are non-white space symbols after the current caret position.
final int lastNonWsSymbolOffset = CharArrayUtil.shiftBackward(text, endLineOffset, " \t");
if(lastNonWsSymbolOffset > offset || caretModel.getLogicalPosition().column > endLineLogicalPosition.column)
{
return Result.CONTINUE;
}
final Pair<JavadocHelper.JavadocParameterInfo, List<JavadocHelper.JavadocParameterInfo>> pair = ourHelper.parse(psiFile, editor, offset);
if(pair.first == null || pair.first.parameterDescriptionStartPosition != null)
{
return Result.CONTINUE;
}
final LogicalPosition position = ourHelper.calculateDescriptionStartPosition(psiFile, pair.second, pair.first);
ourHelper.navigate(position, editor, psiFile.getProject());
return Result.STOP;
}
示例8: actionPerformed
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
public void actionPerformed(AnActionEvent event) {
SourcetrailOptions options = SourcetrailOptions.getInstance();
String MESSAGE_SPLIT_STRING = ">>";
VirtualFile vFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
String fileName = vFile != null ? vFile.getPath() : null;
LogicalPosition logicalPosition = new LogicalPosition(0,0);
final Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor != null)
{
CaretModel caretModel = editor.getCaretModel();
if ( caretModel != null)
{
logicalPosition = caretModel.getLogicalPosition();
}
}
String text = "setActiveToken" + MESSAGE_SPLIT_STRING +
fileName + MESSAGE_SPLIT_STRING
+ (logicalPosition.line + 1) + MESSAGE_SPLIT_STRING + logicalPosition.column + "<EOM>";
try
{
Socket socket = new Socket(options.getIp(), options.getSourcetrailPort());
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
writer.write(text);
writer.flush();
socket.close();
}
catch(Exception e)
{
String errorMsg =
"No connection to a Sourcetrail instance\n\n Make sure Sourcetrail is running and the right address is used("
+ options.getIp() + ":" + options.getSourcetrailPort() + ")";
Messages.showMessageDialog(errorMsg, "SourcetrailPluginError", Messages.getErrorIcon());
e.printStackTrace();
}
StatusBar statusbar = WindowManager.getInstance().getStatusBar(PlatformDataKeys.PROJECT.getData(event.getDataContext()));
JBPopupFactory.getInstance()
.createHtmlTextBalloonBuilder("Location sent to Sourcetrail", MessageType.INFO, null)
.setFadeoutTime(3000)
.createBalloon()
.show(RelativePoint.getCenterOf(statusbar.getComponent()), Balloon.Position.atRight);
}
示例9: getWordAtCaretEnd
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
private static int getWordAtCaretEnd( Project project, String filePath )
{
Editor[] editor = new Editor[1];
editor[0] = getActiveEditor( project );
if( !(editor[0] instanceof EditorImpl) )
{
return -1;
}
EditorImpl editorImpl = (EditorImpl)editor[0];
if( !editorImpl.getVirtualFile().getPath().equals( filePath ) )
{
return -1;
}
CaretModel cm = editorImpl.getCaretModel();
Document document = editorImpl.getDocument();
int offset = cm.getOffset();
if( offset >= document.getTextLength() - 1 || document.getLineCount() == 0 )
{
return offset;
}
int newOffset = offset + 1;
int lineNumber = cm.getLogicalPosition().line;
int maxOffset = document.getLineEndOffset( lineNumber );
if( newOffset > maxOffset )
{
if( lineNumber + 1 >= document.getLineCount() )
{
return offset;
}
maxOffset = document.getLineEndOffset( lineNumber + 1 );
}
for( ; newOffset < maxOffset; newOffset++ )
{
if( EditorActionUtil.isWordOrLexemeEnd( editorImpl, newOffset, false ) )
{
break;
}
}
return newOffset;
}
示例10: postProcessEnter
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public Result postProcessEnter(@NotNull final PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) {
if (!CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER
|| !CodeStyleSettingsManager.getSettings(file.getProject()).JD_ALIGN_PARAM_COMMENTS)
{
return Result.Continue;
}
final CaretModel caretModel = editor.getCaretModel();
final int caretOffset = caretModel.getOffset();
final Pair<JavadocHelper.JavadocParameterInfo,List<JavadocHelper.JavadocParameterInfo>> pair
= myHelper.parse(file, editor, caretOffset);
if (pair.first == null || pair.first.parameterDescriptionStartPosition == null) {
return Result.Continue;
}
final LogicalPosition caretPosition = caretModel.getLogicalPosition();
final LogicalPosition nameEndPosition = pair.first.parameterNameEndPosition;
if (nameEndPosition.line == caretPosition.line && caretPosition.column <= nameEndPosition.column) {
return Result.Continue;
}
final int descriptionStartColumn = pair.first.parameterDescriptionStartPosition.column;
final LogicalPosition desiredPosition = new LogicalPosition(caretPosition.line, descriptionStartColumn);
final Document document = editor.getDocument();
final CharSequence text = document.getCharsSequence();
final int offsetAfterLastWs = CharArrayUtil.shiftForward(text, caretOffset, " \t");
if (editor.offsetToLogicalPosition(offsetAfterLastWs).column < desiredPosition.column) {
final int lineStartOffset = document.getLineStartOffset(desiredPosition.line);
final String toInsert = StringUtil.repeat(" ", desiredPosition.column - (offsetAfterLastWs - lineStartOffset));
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
document.insertString(caretOffset, toInsert);
PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);
}
});
}
myHelper.navigate(desiredPosition, editor, file.getProject());
return Result.Stop;
}
示例11: doBeforeCharDeleted
import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
protected void doBeforeCharDeleted(char c, PsiFile file, Editor editor) {
Project project = file.getProject();
Document document = editor.getDocument();
CharSequence charSequence = document.getImmutableCharSequence();
CaretModel caretModel = editor.getCaretModel();
int caretOffset = caretModel.getOffset();
LogicalPosition pos = caretModel.getLogicalPosition();
int lineStartOffset = document.getLineStartOffset(pos.line);
int beforeWhitespaceOffset = CharArrayUtil.shiftBackward(charSequence, caretOffset - 1, " \t") + 1;
if (beforeWhitespaceOffset != lineStartOffset) {
myReplacement = null;
return;
}
PsiDocumentManager.getInstance(project).commitDocument(document);
CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(project);
myReplacement = codeStyleFacade.getLineIndent(document, lineStartOffset);
if (myReplacement == null) {
return;
}
int tabSize = codeStyleFacade.getTabSize(file.getFileType());
int targetColumn = getWidth(myReplacement, tabSize);
int endOffset = CharArrayUtil.shiftForward(charSequence, caretOffset, " \t");
LogicalPosition logicalPosition = caretOffset < endOffset ? editor.offsetToLogicalPosition(endOffset) : pos;
int currentColumn = logicalPosition.column;
if (currentColumn > targetColumn) {
myStartOffset = lineStartOffset;
}
else if (logicalPosition.line == 0) {
myStartOffset = 0;
myReplacement = "";
}
else {
int prevLineEndOffset = document.getLineEndOffset(logicalPosition.line - 1);
myStartOffset = CharArrayUtil.shiftBackward(charSequence, prevLineEndOffset - 1, " \t") + 1;
if (myStartOffset != document.getLineStartOffset(logicalPosition.line - 1)) {
int spacing = CodeStyleManager.getInstance(project).getSpacing(file, endOffset);
myReplacement = StringUtil.repeatSymbol(' ', Math.max(0, spacing));
}
}
}