Java Code Examples for com.intellij.openapi.editor.ex.EditorEx

The following examples show how to use com.intellij.openapi.editor.ex.EditorEx. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: reasonml-idea-plugin   Source File: PromptConsole.java    License: MIT License 6 votes vote down vote up
private void setupOutputEditor() {
    ((EditorEx) m_outputEditor).getContentComponent().setFocusCycleRoot(false);
    ((EditorEx) m_outputEditor).setHorizontalScrollbarVisible(true);
    ((EditorEx) m_outputEditor).setVerticalScrollbarVisible(true);
    ((EditorEx) m_outputEditor).getScrollPane().setBorder(null);

    EditorSettings editorSettings = ((EditorEx) m_outputEditor).getSettings();
    editorSettings.setLineNumbersShown(false);
    editorSettings.setIndentGuidesShown(false);
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setFoldingOutlineShown(true);
    editorSettings.setRightMarginShown(false);
    editorSettings.setVirtualSpace(false);
    editorSettings.setAdditionalPageAtBottom(false);
    editorSettings.setAdditionalLinesCount(0);
    editorSettings.setAdditionalColumnsCount(0);
    editorSettings.setLineCursorWidth(1);
    editorSettings.setCaretRowShown(false);

    // output only editor
    m_outputEditor.setRendererMode(true);

    // tiny separation between output and prompt
    m_outputEditor.getComponent().setBorder(new SideBorder(JBColor.LIGHT_GRAY, SideBorder.BOTTOM));
}
 
Example 2
Source Project: CodeGen   Source File: TemplateEditorUI.java    License: MIT License 6 votes vote down vote up
public void refresh(@NotNull CodeTemplate codeTemplate) {
    id.setText(codeTemplate.getId());
    displayTextField.setText(codeTemplate.getDisplay());
    extensionTextField.setText(codeTemplate.getExtension());
    filenameTextField.setText(codeTemplate.getFilename());
    subPathTextField.setText(codeTemplate.getSubPath());
    orderTextField.setText(StringUtils.nullOr(codeTemplate.getOrder(), 1) + "");
    resourceCheckBox.setSelected(StringUtils.nullOr(codeTemplate.getResources(), false));
    // create editor
    String template = StringUtils.isEmpty(codeTemplate.getTemplate()) ? "" : codeTemplate.getTemplate();
    String extension = StringUtils.isEmpty(codeTemplate.getExtension()) ? "vm" : codeTemplate.getExtension();
    if (editor == null) {
        editor = createEditor(template, extension);
    } else {
        ((EditorEx) editor).setHighlighter(
                highlighterFactory.createEditorHighlighter(null, FileProviderFactory.getFileType(extension)));
        editor.getDocument().setText(template);
    }
    this.rootPanel.repaint();
}
 
Example 3
Source Project: consulo   Source File: EditorTextField.java    License: Apache License 2.0 6 votes vote down vote up
public void setDocument(Document document) {
  if (myDocument != null) {
    uninstallDocumentListener(true);
  }

  myDocument = document;
  installDocumentListener();
  if (myEditor != null) {
    //MainWatchPanel watches the oldEditor's focus in order to remove debugger combobox when focus is lost
    //we should first transfer focus to new oldEditor and only then remove current oldEditor
    //MainWatchPanel check that oldEditor.getParent == newEditor.getParent and does not remove oldEditor in such cases

    boolean isFocused = isFocusOwner();
    EditorEx newEditor = createEditor();
    releaseEditor(myEditor);
    myEditor = newEditor;
    add(myEditor.getComponent(), BorderLayout.CENTER);

    validate();
    if (isFocused) {
      myEditor.getContentComponent().requestFocus();
    }
  }
}
 
Example 4
/**
 * Gets all of the {@link EditorEx} editors open to Dart files.
 */
public List<EditorEx> getActiveDartEditors() {
  if (project.isDisposed()) {
    return Collections.emptyList();
  }
  final FileEditor[] editors = FileEditorManager.getInstance(project).getSelectedEditors();
  final List<EditorEx> dartEditors = new ArrayList<>();
  for (FileEditor fileEditor : editors) {
    if (!(fileEditor instanceof TextEditor)) continue;
    final TextEditor textEditor = (TextEditor)fileEditor;
    final Editor editor = textEditor.getEditor();
    if (editor instanceof EditorEx && !editor.isDisposed()) {
      dartEditors.add((EditorEx)editor);
    }
  }
  return dartEditors;
}
 
Example 5
Source Project: consulo   Source File: ThreesideTextDiffViewer.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected List<TextEditorHolder> createEditorHolders(@Nonnull EditorHolderFactory<TextEditorHolder> factory) {
  List<TextEditorHolder> holders = super.createEditorHolders(factory);

  boolean[] forceReadOnly = TextDiffViewerUtil.checkForceReadOnly(myContext, myRequest);
  for (int i = 0; i < 3; i++) {
    if (forceReadOnly[i]) holders.get(i).getEditor().setViewer(true);
  }

  ThreeSide.LEFT.select(holders).getEditor().setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT);
  ((EditorMarkupModel)ThreeSide.BASE.select(holders).getEditor().getMarkupModel()).setErrorStripeVisible(false);

  for (TextEditorHolder holder : holders) {
    DiffUtil.disableBlitting(holder.getEditor());
  }

  return holders;
}
 
Example 6
Source Project: consulo   Source File: DiffUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static EditorEx createEditor(@Nonnull Document document, @Nullable Project project, boolean isViewer, boolean enableFolding) {
  EditorFactory factory = EditorFactory.getInstance();
  EditorEx editor = (EditorEx)(isViewer ? factory.createViewer(document, project) : factory.createEditor(document, project));

  editor.putUserData(DiffManagerImpl.EDITOR_IS_DIFF_KEY, Boolean.TRUE);

  editor.getSettings().setShowIntentionBulb(false);
  ((EditorMarkupModel)editor.getMarkupModel()).setErrorStripeVisible(true);
  editor.getGutterComponentEx().setShowDefaultGutterPopup(false);

  if (enableFolding) {
    setFoldingModelSupport(editor);
  } else {
    editor.getSettings().setFoldingOutlineShown(false);
    editor.getFoldingModel().setFoldingEnabled(false);
  }

  UIUtil.removeScrollBorder(editor.getComponent());

  return editor;
}
 
Example 7
Source Project: consulo   Source File: CtrlMouseHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private Runnable doExecute() {
  EditorEx editor = getPossiblyInjectedEditor();
  int offset = getOffset(editor);

  PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
  if (file == null) return createDisposalContinuation();

  final Info info;
  final DocInfo docInfo;
  try {
    info = getInfoAt(editor, file, offset, myBrowseMode);
    if (info == null) return createDisposalContinuation();
    docInfo = info.getInfo();
  }
  catch (IndexNotReadyException e) {
    showDumbModeNotification(myProject);
    return createDisposalContinuation();
  }

  LOG.debug("Obtained info about element under cursor");
  return () -> addHighlighterAndShowHint(info, docInfo, editor);
}
 
Example 8
Source Project: consulo   Source File: FoldingPopupManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void mouseMoved(@Nonnull EditorMouseEvent e) {
  myAlarm.cancelAllRequests();
  Editor editor = e.getEditor();
  if (editor.getUserData(DISABLED) != null) return;
  if (e.getArea() == EditorMouseEventArea.EDITING_AREA) {
    MouseEvent mouseEvent = e.getMouseEvent();
    Point point = mouseEvent.getPoint();
    FoldRegion fold = ((EditorEx)editor).getFoldingModel().getFoldingPlaceholderAt(point);
    TooltipController controller = TooltipController.getInstance();
    if (fold != null && !fold.shouldNeverExpand()) {
      myAlarm.addRequest(() -> {
        if (editor.getUserData(DISABLED) != null || !editor.getComponent().isShowing() || !fold.isValid() || fold.isExpanded()) return;
        DocumentFragment range = createDocumentFragment(fold);
        Point p = SwingUtilities.convertPoint((Component)mouseEvent.getSource(), point, editor.getComponent().getRootPane().getLayeredPane());
        controller.showTooltip(editor, p, new DocumentFragmentTooltipRenderer(range), false, FOLDING_TOOLTIP_GROUP);
      }, TOOLTIP_DELAY_MS);
    }
    else {
      controller.cancelTooltip(FOLDING_TOOLTIP_GROUP, mouseEvent, true);
    }
  }
}
 
Example 9
/**
 * Gets all of the {@link EditorEx} editors open to Dart files.
 */
public List<EditorEx> getActiveDartEditors() {
  if (project.isDisposed()) {
    return Collections.emptyList();
  }
  final FileEditor[] editors = FileEditorManager.getInstance(project).getSelectedEditors();
  final List<EditorEx> dartEditors = new ArrayList<>();
  for (FileEditor fileEditor : editors) {
    if (!(fileEditor instanceof TextEditor)) continue;
    final TextEditor textEditor = (TextEditor)fileEditor;
    final Editor editor = textEditor.getEditor();
    if (editor instanceof EditorEx && !editor.isDisposed()) {
      dartEditors.add((EditorEx)editor);
    }
  }
  return dartEditors;
}
 
Example 10
Source Project: consulo   Source File: SelectionQuotingTypedHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testRuby7852ErrantEditor() {
  myFixture.configureByText(PlainTextFileType.INSTANCE, "\"aaa\"\nbbb\n\n");
  myFixture.getEditor().getCaretModel().moveToOffset(0);
  myFixture.getEditor().getSelectionModel().setSelection(0, 5);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), '\'', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.getEditor().getSelectionModel().removeSelection();
  myFixture.checkResult("'aaa'\nbbb\n\n");

  myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getDocument().getLineStartOffset(3));
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), 'A', ((EditorEx)myFixture.getEditor()).getDataContext());
      typedAction.actionPerformed(myFixture.getEditor(), 'B', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.checkResult("'aaa'\nbbb\n\nAB");
}
 
Example 11
Source Project: consulo   Source File: SwapSelectionBoundariesAction.java    License: Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example 12
Source Project: consulo   Source File: EditorFragmentComponent.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param component Should be provided if editor is not currently displayable.
 *                  Makes for correct rendering on multi-monitor configurations.
 */
private static EditorFragmentComponent createEditorFragmentComponent(Component component,
                                                                     Editor editor,
                                                                     int startLine,
                                                                     int endLine,
                                                                     boolean showFolding,
                                                                     boolean showGutter,
                                                                     boolean useCaretRowBackground) {
  final EditorEx editorEx = (EditorEx)editor;
  final Color old = editorEx.getBackgroundColor();
  Color backColor = getBackgroundColor(editor, useCaretRowBackground);
  editorEx.setBackgroundColor(backColor);
  EditorFragmentComponent fragmentComponent = new EditorFragmentComponent(component, editorEx, startLine, endLine, showFolding, showGutter);
  fragmentComponent.setBackground(backColor);

  editorEx.setBackgroundColor(old);
  return fragmentComponent;
}
 
Example 13
Source Project: consulo   Source File: ExportToFileUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  final Document document = ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(true);
  ((DocumentImpl)document).setAcceptSlashR(true);

  myTextArea = EditorFactory.getInstance().createEditor(document, myProject, PlainTextFileType.INSTANCE, true);
  final EditorSettings settings = myTextArea.getSettings();
  settings.setLineNumbersShown(false);
  settings.setLineMarkerAreaShown(false);
  settings.setFoldingOutlineShown(false);
  settings.setRightMarginShown(false);
  settings.setAdditionalLinesCount(0);
  settings.setAdditionalColumnsCount(0);
  settings.setAdditionalPageAtBottom(false);
  ((EditorEx)myTextArea).setBackgroundColor(UIUtil.getInactiveTextFieldBackgroundColor());
  return myTextArea.getComponent();
}
 
Example 14
Source Project: StringManipulation   Source File: IdeUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static EditorImpl createEditorPreview(String text, boolean editable) {
	EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
	ColorAndFontOptions options = new ColorAndFontOptions();
	options.reset();
	options.selectScheme(scheme.getName());

	EditorFactory editorFactory = EditorFactory.getInstance();
	Document editorDocument = editorFactory.createDocument(text);
	EditorEx editor = (EditorEx) (editable ? editorFactory.createEditor(editorDocument) : editorFactory.createViewer(editorDocument));
	editor.setColorsScheme(scheme);
	EditorSettings settings = editor.getSettings();
	settings.setLineNumbersShown(true);
	settings.setWhitespacesShown(false);
	settings.setLineMarkerAreaShown(false);
	settings.setIndentGuidesShown(false);
	settings.setFoldingOutlineShown(false);
	settings.setAdditionalColumnsCount(0);
	settings.setAdditionalLinesCount(0);
	settings.setRightMarginShown(false);

	return (EditorImpl) editor;
}
 
Example 15
Source Project: MavenHelper   Source File: GoalEditor.java    License: Apache License 2.0 6 votes vote down vote up
@NotNull
private static Editor createEditor() {
	EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
	ColorAndFontOptions options = new ColorAndFontOptions();
	options.reset();
	options.selectScheme(scheme.getName());
	EditorFactory editorFactory = EditorFactory.getInstance();
	Document editorDocument = editorFactory.createDocument("");


	EditorEx editor = (EditorEx) (true ? editorFactory.createEditor(editorDocument) : editorFactory.createViewer(editorDocument));
	editor.setColorsScheme(scheme);
	EditorSettings settings = editor.getSettings();
	settings.setLineNumbersShown(false);
	settings.setUseSoftWraps(true);
	settings.setWhitespacesShown(false);
	settings.setLineMarkerAreaShown(false);
	settings.setIndentGuidesShown(false);
	settings.setFoldingOutlineShown(false);
	settings.setAdditionalColumnsCount(0);
	settings.setAdditionalLinesCount(0);
	settings.setRightMarginShown(false);

	return editor;
}
 
Example 16
Source Project: consulo   Source File: DiffLineSeparatorRenderer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void paint(Editor editor, Graphics g, Rectangle r) {
  if (!myCondition.get()) return;

  int y = r.y;
  int lineHeight = myEditor.getLineHeight();

  EditorGutterComponentEx gutter = ((EditorEx)editor).getGutterComponentEx();
  int annotationsOffset = gutter.getAnnotationsAreaOffset();
  int annotationsWidth = gutter.getAnnotationsAreaWidth();
  if (annotationsWidth != 0) {
    g.setColor(editor.getColorsScheme().getColor(EditorColors.GUTTER_BACKGROUND));
    g.fillRect(annotationsOffset, y, annotationsWidth, lineHeight);
  }

  draw(g, 0, y, lineHeight, myEditor.getColorsScheme());
}
 
Example 17
Source Project: consulo   Source File: TextEditorComponent.java    License: Apache License 2.0 6 votes vote down vote up
public TextEditorComponent(@Nonnull final Project project, @Nonnull final VirtualFile file, @Nonnull final DesktopTextEditorImpl textEditor) {
  super(new BorderLayout(), textEditor);

  myProject = project;
  myFile = file;
  myTextEditor = textEditor;

  myDocument = FileDocumentManager.getInstance().getDocument(myFile);
  LOG.assertTrue(myDocument != null);
  myDocument.addDocumentListener(new MyDocumentListener(), this);

  myEditor = createEditor();
  add(myEditor.getComponent(), BorderLayout.CENTER);
  myModified = isModifiedImpl();
  myValid = isEditorValidImpl();
  LOG.assertTrue(myValid);

  MyVirtualFileListener myVirtualFileListener = new MyVirtualFileListener();
  myFile.getFileSystem().addVirtualFileListener(myVirtualFileListener);
  Disposer.register(this, () -> myFile.getFileSystem().removeVirtualFileListener(myVirtualFileListener));
  MessageBusConnection myConnection = project.getMessageBus().connect(this);
  myConnection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener());

  myEditorHighlighterUpdater = new EditorHighlighterUpdater(myProject, this, (EditorEx)myEditor, myFile);
}
 
Example 18
Source Project: consulo   Source File: EditorTextField.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setEnabled(boolean enabled) {
  if (isEnabled() != enabled) {
    super.setEnabled(enabled);
    setViewerEnabled(enabled);
    EditorEx editor = myEditor;
    if (editor != null) {
      releaseEditor(editor);
      initEditor();
      revalidate();
    }
  }
}
 
Example 19
Source Project: consulo   Source File: ThreesideTextDiffViewerEx.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void consume(Graphics g) {
  EditorEx editor1 = getEditor(ThreeSide.BASE);
  EditorEx editor2 = getEditor(ThreeSide.RIGHT);

  int width = editor1.getScrollPane().getVerticalScrollBar().getWidth();
  DiffDividerDrawUtil.paintPolygonsOnScrollbar((Graphics2D)g, width, editor1, editor2, myPaintable);

  myFoldingModel.paintOnScrollbar((Graphics2D)g, width);
}
 
Example 20
Source Project: consulo   Source File: TargetElementUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public static PsiReference findReference(Editor editor) {
  int offset = editor.getCaretModel().getOffset();
  PsiReference result = findReference(editor, offset);
  if (result == null) {
    int expectedCaretOffset = editor instanceof EditorEx ? ((EditorEx)editor).getExpectedCaretOffset() : offset;
    if (expectedCaretOffset != offset) {
      result = findReference(editor, expectedCaretOffset);
    }
  }
  return result;
}
 
Example 21
Source Project: consulo   Source File: SemanticEditorPosition.java    License: Apache License 2.0 5 votes vote down vote up
private SemanticEditorPosition(@Nonnull EditorEx editor,
                               int offset,
                               @Nonnull BiFunction<EditorEx, Integer, HighlighterIterator> createHighlighterIteratorAtOffset,
                               @Nonnull Function<IElementType, SyntaxElement> typeMapper) {
  myCreateHighlighterIteratorAtOffset = createHighlighterIteratorAtOffset;
  myEditor = editor;
  myChars = myEditor.getDocument().getCharsSequence();
  myIterator = createHighlighterIteratorAtOffset.apply(editor, offset);
  myTypeMapper = typeMapper;
}
 
Example 22
Source Project: weex-language-support   Source File: DocumentIntention.java    License: MIT License 5 votes vote down vote up
private void openSample(Project project, Editor editor) {

        EditorTextField field = new EditorTextField(editor.getDocument(), project, WeexFileType.INSTANCE, true, false) {
            @Override
            protected EditorEx createEditor() {
                EditorEx editor1 = super.createEditor();
                editor1.setVerticalScrollbarVisible(true);
                editor1.setHorizontalScrollbarVisible(true);
                return editor1;

            }
        };

        field.setFont(editor.getContentComponent().getFont());

        JBPopup jbPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(field, null)
                .createPopup();

        jbPopup.setSize(new Dimension(500, 500));
        jbPopup.showInBestPositionFor(editor);
    }
 
Example 23
Source Project: consulo   Source File: LanguageConsoleImpl.java    License: Apache License 2.0 5 votes vote down vote up
public LanguageConsoleImpl(@Nonnull Helper helper) {
  super(helper.project, GlobalSearchScope.allScope(helper.project), true, true);
  myHelper = helper;
  EditorFactory editorFactory = EditorFactory.getInstance();
  myConsoleExecutionEditor = new ConsoleExecutionEditor(helper);
  Disposer.register(this, myConsoleExecutionEditor);
  Document historyDocument = ((EditorFactoryImpl)editorFactory).createDocument(true);
  UndoUtil.disableUndoFor(historyDocument);
  myHistoryViewer = (EditorEx)editorFactory.createViewer(historyDocument, getProject(), EditorKind.CONSOLE);
  myHistoryViewer.getDocument().addDocumentListener(myDocumentAdapter);
  myConsoleExecutionEditor.getDocument().addDocumentListener(myDocumentAdapter);
  myScrollBar.setModel(new MyModel(myScrollBar, myHistoryViewer, myConsoleExecutionEditor.getEditor()));
  myScrollBar.putClientProperty(Alignment.class, Alignment.BOTTOM);
}
 
Example 24
Source Project: consulo   Source File: ConsoleExecuteAction.java    License: Apache License 2.0 5 votes vote down vote up
public void execute(@Nullable TextRange range, @Nonnull String text, @Nullable EditorEx editor) {
  if (range == null) {
    ((LanguageConsoleImpl)myConsoleView).doAddPromptToHistory();
    myConsoleView.print(text, ConsoleViewContentType.USER_INPUT);
    if (!text.endsWith("\n")) {
      myConsoleView.print("\n", ConsoleViewContentType.USER_INPUT);
    }
  }
  else {
    assert editor != null;
    ((LanguageConsoleImpl)myConsoleView).addTextRangeToHistory(range, editor, myExecuteActionHandler.myPreserveMarkup);
  }
  myExecuteActionHandler.addToCommandHistoryAndExecute(myConsoleView, text);
}
 
Example 25
Source Project: consulo   Source File: DiffUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static EditorEx createEditor(Document document, Project project, boolean isViewer, @Nullable FileType fileType) {
  EditorFactory factory = EditorFactory.getInstance();
  EditorEx editor = (EditorEx)(isViewer ? factory.createViewer(document, project) : factory.createEditor(document, project));
  editor.putUserData(DiffManagerImpl.EDITOR_IS_DIFF_KEY, Boolean.TRUE);
  editor.getGutterComponentEx().revalidateMarkup();

  if (fileType != null && project != null && !project.isDisposed()) {
    CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(project);
    editor.getSettings().setTabSize(codeStyleFacade.getTabSize(fileType));
    editor.getSettings().setUseTabCharacter(codeStyleFacade.useTabCharacter(fileType));
  }

  return editor;
}
 
Example 26
Source Project: consulo   Source File: TypedHandler.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isInsideLiteral(@Nonnull Editor editor, @Nonnull QuoteHandler quoteHandler, int offset) {
  if (offset == 0) return false;

  HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset - 1);
  if (iterator.atEnd()) {
    LOG.assertTrue(false);
    return false;
  }

  return quoteHandler.isInsideLiteral(iterator);
}
 
Example 27
Source Project: consulo   Source File: SelectionQuotingTypedHandler.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 28
Source Project: consulo   Source File: SelectionQuotingTypedHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
private void doTest(final char c, @Nonnull String before, @Nonnull String expected) {
  myFixture.configureByText(PlainTextFileType.INSTANCE, before);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), c, ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.getEditor().getSelectionModel().removeSelection();
  myFixture.checkResult(expected);
}
 
Example 29
Source Project: consulo   Source File: CopyProviderRule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CopyProvider getData(@Nonnull DataProvider dataProvider) {
  final Editor editor = dataProvider.getDataUnchecked(PlatformDataKeys.EDITOR);
  if (editor instanceof EditorEx) {
    return ((EditorEx) editor).getCopyProvider();
  }
  return null;
}
 
Example 30
Source Project: consulo   Source File: AbstractPopup.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
private RelativePoint getBestPositionFor(@Nonnull Editor editor) {
  DataContext context = ((EditorEx)editor).getDataContext();
  Rectangle dominantArea = context.getData(PlatformDataKeys.DOMINANT_HINT_AREA_RECTANGLE);
  if (dominantArea != null && !myRequestFocus) {
    final JLayeredPane layeredPane = editor.getContentComponent().getRootPane().getLayeredPane();
    return relativePointWithDominantRectangle(layeredPane, dominantArea);
  }
  else {
    return guessBestPopupLocation(editor);
  }
}