本文整理匯總了Java中com.intellij.openapi.editor.Document.getLineStartOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.getLineStartOffset方法的具體用法?Java Document.getLineStartOffset怎麽用?Java Document.getLineStartOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.editor.Document
的用法示例。
在下文中一共展示了Document.getLineStartOffset方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateGherkinRunIcons
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public void generateGherkinRunIcons(Document rootDocument, Editor rootEditor) {
for (int i = 0; i < rootDocument.getLineCount(); i++) {
int startOffset = rootDocument.getLineStartOffset(i);
int endOffset = rootDocument.getLineEndOffset(i);
String lineText = rootDocument.getText(new TextRange(startOffset, endOffset)).trim();
Icon icon;
if (lineText.matches(SCENARIO_REGEX)) {
icon = GherkinIconRenderer.SCENARIO_ICON;
} else if (lineText.matches(FEATURE_REGEX)) {
icon = GherkinIconRenderer.FEATURE_ICON;
} else {
// System.out.println();
continue;
}
GherkinIconRenderer gherkinIconRenderer = new GherkinIconRenderer(rootEditor.getProject(), fileName);
gherkinIconRenderer.setLine(i);
gherkinIconRenderer.setIcon(icon);
RangeHighlighter rangeHighlighter = createRangeHighlighter(rootDocument, rootEditor, i, i, new TextAttributes());
rangeHighlighter.setGutterIconRenderer(gherkinIconRenderer);
}
}
示例2: postProcessEnter
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
@Override
public Result postProcessEnter(
@NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) {
if (file.getFileType() != SoyFileType.INSTANCE) {
return Result.Continue;
}
int caretOffset = editor.getCaretModel().getOffset();
PsiElement element = file.findElementAt(caretOffset);
Document document = editor.getDocument();
int lineNumber = document.getLineNumber(caretOffset) - 1;
int lineStartOffset = document.getLineStartOffset(lineNumber);
String lineTextBeforeCaret = document.getText(new TextRange(lineStartOffset, caretOffset));
if (element instanceof PsiComment && element.getTextOffset() < caretOffset) {
handleEnterInComment(element, file, editor);
} else if (lineTextBeforeCaret.startsWith("/*")) {
insertText(file, editor, " * \n ", 3);
}
return Result.Continue;
}
示例3: saveIndent
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private static void saveIndent(AnswerPlaceholder placeholder, CCState state, boolean visible) {
Document document = state.getEditor().getDocument();
int offset = placeholder.getOffset();
int lineNumber = document.getLineNumber(offset);
int nonSpaceCharOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber);
int newOffset = offset;
int endOffset = offset + placeholder.getRealLength();
if (!visible && nonSpaceCharOffset == offset) {
newOffset = document.getLineStartOffset(lineNumber);
}
if (visible) {
newOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, offset, endOffset);
}
placeholder.setOffset(newOffset);
int delta = offset - newOffset;
placeholder.setPossibleAnswer(document.getText(TextRange.create(newOffset, newOffset + delta + placeholder.getRealLength())));
String oldTaskText = placeholder.getTaskText();
if (delta >= 0) {
placeholder.setTaskText(StringUtil.repeat(" ", delta) + oldTaskText);
}
else {
String newTaskText = oldTaskText.substring(Math.abs(delta));
placeholder.setTaskText(newTaskText);
}
}
示例4: createRangeHighlighter
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private RangeHighlighter createRangeHighlighter(Document document, Editor editor, int fromLine, int toLine, TextAttributes attributes) {
int lineStartOffset = document.getLineStartOffset(Math.max(0, fromLine));
int lineEndOffset = document.getLineEndOffset(Math.max(0, toLine));
return editor.getMarkupModel().addRangeHighlighter(
lineStartOffset, lineEndOffset, 3333, attributes, HighlighterTargetArea.LINES_IN_RANGE
);
}
示例5: getCurrentWords
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private String getCurrentWords(Editor editor) {
Document document = editor.getDocument();
CaretModel caretModel = editor.getCaretModel();
int caretOffset = caretModel.getOffset();
int lineNum = document.getLineNumber(caretOffset);
int lineStartOffset = document.getLineStartOffset(lineNum);
int lineEndOffset = document.getLineEndOffset(lineNum);
String lineContent = document.getText(new TextRange(lineStartOffset, lineEndOffset));
char[] chars = lineContent.toCharArray();
int start = 0, end = 0, cursor = caretOffset - lineStartOffset;
if (!Character.isLetter(chars[cursor])) {
return null;
}
for (int ptr = cursor; ptr >= 0; ptr--) {
if (!Character.isLetter(chars[ptr])) {
start = ptr + 1;
break;
}
}
int lastLetter = 0;
for (int ptr = cursor; ptr < lineEndOffset - lineStartOffset; ptr++) {
lastLetter = ptr;
if (!Character.isLetter(chars[ptr])) {
end = ptr;
break;
}
}
if (end == 0) {
end = lastLetter + 1;
}
return new String(chars, start, end - start);
}
示例6: addInitialState
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public static void addInitialState(Document document, Element placeholder) throws StudyUnrecognizedFormatException {
Element initialState = getChildWithName(placeholder, INITIAL_STATE).getChild(MY_INITIAL_STATE);
int initialLine = getAsInt(initialState, MY_LINE);
int initialStart = getAsInt(initialState, MY_START);
int initialOffset = document.getLineStartOffset(initialLine) + initialStart;
addChildWithName(initialState, OFFSET, initialOffset);
renameElement(getChildWithName(initialState, MY_LENGTH), LENGTH);
}
示例7: loadState
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
@Override
public void loadState(Element state) {
try {
Element courseElement = getChildWithName(state, COURSE).getChild(COURSE_TITLED);
for (Element lesson : getChildList(courseElement, LESSONS, true)) {
int lessonIndex = getAsInt(lesson, INDEX);
for (Element task : getChildList(lesson, TASK_LIST, true)) {
int taskIndex = getAsInt(task, INDEX);
Map<String, Element> taskFiles = getChildMap(task, TASK_FILES, true);
for (Map.Entry<String, Element> entry : taskFiles.entrySet()) {
Element taskFileElement = entry.getValue();
String name = entry.getKey();
String answerName = FileUtil.getNameWithoutExtension(name) + CCUtils.ANSWER_EXTENSION_DOTTED + FileUtilRt.getExtension(name);
Document document = StudyUtils.getDocument(myProject.getBasePath(), lessonIndex, taskIndex, answerName);
if (document == null) {
document = StudyUtils.getDocument(myProject.getBasePath(), lessonIndex, taskIndex, name);
if (document == null) {
continue;
}
}
for (Element placeholder : getChildList(taskFileElement, ANSWER_PLACEHOLDERS, true)) {
Element lineElement = getChildWithName(placeholder, LINE, true);
int line = lineElement != null ? Integer.valueOf(lineElement.getAttributeValue(VALUE)) : 0;
Element startElement = getChildWithName(placeholder, START, true);
int start = startElement != null ? Integer.valueOf(startElement.getAttributeValue(VALUE)) : 0;
int offset = document.getLineStartOffset(line) + start;
addChildWithName(placeholder, OFFSET, offset);
addChildWithName(placeholder, "useLength", "false");
}
}
}
}
XmlSerializer.deserializeInto(this, state);
} catch (StudyUnrecognizedFormatException e) {
LOG.error(e);
}
}
示例8: getCurrentWords
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public String getCurrentWords(Editor editor) {
Document document = editor.getDocument();
CaretModel caretModel = editor.getCaretModel();
int caretOffset = caretModel.getOffset();
int lineNum = document.getLineNumber(caretOffset);
int lineStartOffset = document.getLineStartOffset(lineNum);
int lineEndOffset = document.getLineEndOffset(lineNum);
String lineContent = document.getText(new TextRange(lineStartOffset, lineEndOffset));
char[] chars = lineContent.toCharArray();
int start = 0, end = 0, cursor = caretOffset - lineStartOffset;
if (!Character.isLetter(chars[cursor])) {
Logger.warn("Caret not in a word");
return null;
}
for (int ptr = cursor; ptr >= 0; ptr--) {
if (!Character.isLetter(chars[ptr])) {
start = ptr + 1;
break;
}
}
int lastLetter = 0;
for (int ptr = cursor; ptr < lineEndOffset - lineStartOffset; ptr++) {
lastLetter = ptr;
if (!Character.isLetter(chars[ptr])) {
end = ptr;
break;
}
}
if (end == 0) {
end = lastLetter + 1;
}
String ret = new String(chars, start, end-start);
Logger.info("Selected words: " + ret);
return ret;
}
示例9: addOffset
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public static void addOffset(Document document, Element placeholder) throws StudyUnrecognizedFormatException {
int line = getAsInt(placeholder, LINE);
int start = getAsInt(placeholder, START);
int offset = document.getLineStartOffset(line) + start;
addChildWithName(placeholder, OFFSET, offset);
}