Search in sources :

Example 6 with UndoableEditor

use of org.eclipse.che.ide.api.editor.texteditor.UndoableEditor in project che by eclipse.

the class LanguageServerFormatter method applyEdits.

private void applyEdits(List<TextEditDTO> edits, Document document) {
    HandlesUndoRedo undoRedo = null;
    if (editor instanceof UndoableEditor) {
        undoRedo = ((UndoableEditor) editor).getUndoRedo();
    }
    try {
        if (undoRedo != null) {
            undoRedo.beginCompoundChange();
        }
        // #2437: apply the text edits from last to first to avoid messing up the document
        Collections.reverse(edits);
        for (TextEditDTO change : edits) {
            RangeDTO range = change.getRange();
            document.replace(range.getStart().getLine(), range.getStart().getCharacter(), range.getEnd().getLine(), range.getEnd().getCharacter(), change.getNewText());
        }
    } catch (final Exception e) {
        Log.error(getClass(), e);
    } finally {
        if (undoRedo != null) {
            undoRedo.endCompoundChange();
        }
    }
}
Also used : HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) TextEditDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextEditDTO) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 7 with UndoableEditor

use of org.eclipse.che.ide.api.editor.texteditor.UndoableEditor in project che by eclipse.

the class RecipeEditorPanel method onCancelButtonClicked.

/** {@inheritDoc} */
@Override
public void onCancelButtonClicked() {
    setEnableSaveAndCancelButtons(false);
    view.setTags(recipeDescriptor.getTags());
    view.setName(recipeDescriptor.getName());
    if (editor instanceof UndoableEditor) {
        HandlesUndoRedo undoRedo = ((UndoableEditor) editor).getUndoRedo();
        while (editor.isDirty() && undoRedo.undoable()) {
            undoOperations++;
            undoRedo.undo();
        }
    }
}
Also used : UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo)

Aggregations

HandlesUndoRedo (org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo)7 UndoableEditor (org.eclipse.che.ide.api.editor.texteditor.UndoableEditor)7 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)3 OperationException (org.eclipse.che.api.promises.client.OperationException)2 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)2 Element (elemental.dom.Element)1 Node (elemental.dom.Node)1 CustomEvent (elemental.events.CustomEvent)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 SpanElement (elemental.html.SpanElement)1 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)1 TextEditDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextEditDTO)1 Completion (org.eclipse.che.ide.api.editor.codeassist.Completion)1 CompletionProposal (org.eclipse.che.ide.api.editor.codeassist.CompletionProposal)1 Change (org.eclipse.che.ide.ext.java.shared.dto.Change)1