diff --git a/editor.lib/src/org/netbeans/editor/BaseKit.java b/editor.lib/src/org/netbeans/editor/BaseKit.java --- a/editor.lib/src/org/netbeans/editor/BaseKit.java +++ b/editor.lib/src/org/netbeans/editor/BaseKit.java @@ -1164,8 +1164,14 @@ try { final Position insertionOffset = doc.createPosition(computeInsertionOffset(target.getCaret()), Position.Bias.Backward); + String replacedText = ""; + if (Utilities.isSelectionShowing(target.getCaret())) { + int p0 = Math.min(target.getCaret().getDot(), target.getCaret().getMark()); + int p1 = Math.max(target.getCaret().getDot(), target.getCaret().getMark()); + replacedText = doc.getText(p0, p1 - p0); + } final TypedTextInterceptorsManager.Transaction transaction = TypedTextInterceptorsManager.getInstance().openTransaction( - target, insertionOffset, cmd); + target, insertionOffset, cmd, replacedText); try { if (!transaction.beforeInsertion()) { diff --git a/editor.lib2/apichanges.xml b/editor.lib2/apichanges.xml --- a/editor.lib2/apichanges.xml +++ b/editor.lib2/apichanges.xml @@ -107,6 +107,21 @@ + + OnSaveTask interface added + + + + + +

+ Added OnSaveTask interface which allows modules to register + tasks into MimeLookup that will be performed right before document saving. +

+
+ +
+ OnSaveTask interface added diff --git a/editor.lib2/nbproject/project.properties b/editor.lib2/nbproject/project.properties --- a/editor.lib2/nbproject/project.properties +++ b/editor.lib2/nbproject/project.properties @@ -43,7 +43,7 @@ is.autoload=true javac.source=1.6 javac.compilerargs=-Xlint:unchecked -spec.version.base=1.72.0 +spec.version.base=1.73.0 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypedTextInterceptorsManager.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypedTextInterceptorsManager.java --- a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypedTextInterceptorsManager.java +++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypedTextInterceptorsManager.java @@ -71,10 +71,10 @@ return instance; } - public Transaction openTransaction(JTextComponent c, Position offset, String typedText) { + public Transaction openTransaction(JTextComponent c, Position offset, String typedText, String replacedText) { synchronized (this) { if (transaction == null) { - transaction = new Transaction(c, offset, typedText); + transaction = new Transaction(c, offset, typedText, replacedText); return transaction; } else { throw new IllegalStateException("Too many transactions; only one at a time is allowed!"); //NOI18N @@ -161,8 +161,8 @@ private final Collection interceptors; private int phase = 0; - private Transaction(JTextComponent c, Position offset, String typedText) { - this.context = TypingHooksSpiAccessor.get().createTtiContext(c, offset, typedText); + private Transaction(JTextComponent c, Position offset, String typedText, String replacedText) { + this.context = TypingHooksSpiAccessor.get().createTtiContext(c, offset, typedText, replacedText); this.interceptors = getInterceptors(c.getDocument(), offset); } } // End of Transaction class diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypingHooksSpiAccessor.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypingHooksSpiAccessor.java --- a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypingHooksSpiAccessor.java +++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypingHooksSpiAccessor.java @@ -74,7 +74,7 @@ protected TypingHooksSpiAccessor() { } - public abstract TypedTextInterceptor.MutableContext createTtiContext(JTextComponent c, Position offset, String typedText); + public abstract TypedTextInterceptor.MutableContext createTtiContext(JTextComponent c, Position offset, String typedText, String replacedText); public abstract Object [] getTtiContextData(TypedTextInterceptor.MutableContext context); public abstract void resetTtiContextData(TypedTextInterceptor.MutableContext context); diff --git a/editor.lib2/src/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.java b/editor.lib2/src/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.java --- a/editor.lib2/src/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.java +++ b/editor.lib2/src/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.java @@ -303,22 +303,36 @@ this.caretPosition = caretPosition; } + /** + * Gets the replaced text. This is the text that was selected + * by the user and it is replaced by inserted text. + * + *

The selected text is removed from document before insert method. + * + * @return The replaced text. + */ + public String getReplacedText() { + return replacedText; + } + // ------------------------------------------------------------------- // Private implementation // ------------------------------------------------------------------- private String insertionText = null; + private String replacedText = null; private int caretPosition = -1; - private MutableContext(JTextComponent c, Position offset, String typedText) { + private MutableContext(JTextComponent c, Position offset, String typedText, String replacedText) { super(c, offset, typedText); + this.replacedText = replacedText; } private static final class Accessor extends TypingHooksSpiAccessor { @Override - public MutableContext createTtiContext(JTextComponent c, Position offset, String typedText) { - return new MutableContext(c, offset, typedText); + public MutableContext createTtiContext(JTextComponent c, Position offset, String typedText, String replacedText) { + return new MutableContext(c, offset, typedText, replacedText); } @Override