Skip to content

Commit

Permalink
Create only one undo for each save action invocation
Browse files Browse the repository at this point in the history
Each changed region creates its own undo entry in the undo queue. This
means that one has to undo each text change separately after save
actions are invoked instead of only a single undo.

Fortunately it is possible to tell the undo queue that multiple undos
belong together.
  • Loading branch information
kiritsuku committed Oct 9, 2014
1 parent b9e88e3 commit e76eed2
Showing 1 changed file with 9 additions and 2 deletions.
@@ -1,6 +1,7 @@
package org.scalaide.ui.internal.editor

import scala.concurrent._, ExecutionContext.Implicits.global
import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.reflect.internal.util.SourceFile
import scala.tools.refactoring.common.{TextChange => RTextChange}
Expand All @@ -11,6 +12,7 @@ import org.eclipse.jdt.core.ICompilationUnit
import org.eclipse.jdt.internal.ui.javaeditor.saveparticipant.IPostSaveListener
import org.eclipse.jface.text.IDocument
import org.eclipse.jface.text.IRegion
import org.eclipse.text.undo.DocumentUndoManagerRegistry
import org.scalaide.core.IScalaPlugin
import org.scalaide.core.compiler.IScalaPresentationCompiler
import org.scalaide.core.compiler.IScalaPresentationCompiler.Implicits._
Expand All @@ -33,9 +35,9 @@ import org.scalaide.extensions.saveactions.AutoFormattingSetting
import org.scalaide.extensions.saveactions.RemoveDuplicatedEmptyLinesSetting
import org.scalaide.extensions.saveactions.RemoveTrailingWhitespaceSetting
import org.scalaide.logging.HasLogger
import org.scalaide.util.internal.FutureUtils.TimeoutFuture
import org.scalaide.util.eclipse.EclipseUtils
import org.scalaide.util.eclipse.EditorUtils
import org.scalaide.util.internal.FutureUtils.TimeoutFuture
import org.scalaide.util.internal.eclipse.TextEditUtils

object SaveActionExtensions {
Expand Down Expand Up @@ -100,7 +102,12 @@ trait SaveActionExtensions extends HasLogger {
* Applies all save actions to the contents of the given document.
*/
private def applySaveActions(udoc: IDocument): Unit = {
val undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(udoc)
undoManager.beginCompoundChange()

applyDocumentExtensions(udoc)

undoManager.endCompoundChange()
}

/**
Expand Down

0 comments on commit e76eed2

Please sign in to comment.