This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 225293
Collapse All | Expand All

(-)a/editor.lib/src/org/netbeans/editor/BaseKit.java (-1 / +7 lines)
Lines 1164-1171 Link Here
1164
1164
1165
                    try {
1165
                    try {
1166
                    final Position insertionOffset = doc.createPosition(computeInsertionOffset(target.getCaret()), Position.Bias.Backward);
1166
                    final Position insertionOffset = doc.createPosition(computeInsertionOffset(target.getCaret()), Position.Bias.Backward);
1167
                    String replacedText = "";
1168
                    if (Utilities.isSelectionShowing(target.getCaret())) {
1169
                        int p0 = Math.min(target.getCaret().getDot(), target.getCaret().getMark());
1170
                        int p1 = Math.max(target.getCaret().getDot(), target.getCaret().getMark());
1171
                        replacedText = doc.getText(p0, p1 - p0);
1172
                    }
1167
                    final TypedTextInterceptorsManager.Transaction transaction = TypedTextInterceptorsManager.getInstance().openTransaction(
1173
                    final TypedTextInterceptorsManager.Transaction transaction = TypedTextInterceptorsManager.getInstance().openTransaction(
1168
                            target, insertionOffset, cmd);
1174
                            target, insertionOffset, cmd, replacedText);
1169
                    
1175
                    
1170
                    try {
1176
                    try {
1171
                        if (!transaction.beforeInsertion()) {
1177
                        if (!transaction.beforeInsertion()) {
(-)a/editor.lib2/apichanges.xml (+15 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
        <change id="TypedTextInterceptor.getReplacedText">
111
            <summary>OnSaveTask interface added</summary>
112
            <version major="1" minor="66"/>
113
            <date day="5" month="9" year="2012"/>
114
            <author login="mmetelka"/>
115
            <compatibility binary="compatible" source="compatible" semantic="compatible" addition="yes"/>
116
            <description>
117
                <p>
118
                    Added OnSaveTask interface which allows modules to register
119
                    tasks into MimeLookup that will be performed right before document saving.
120
                </p>
121
            </description>
122
            <issue number="217904"/>
123
        </change>
124
110
        <change id="OnSaveTask">
125
        <change id="OnSaveTask">
111
            <summary>OnSaveTask interface added</summary>
126
            <summary>OnSaveTask interface added</summary>
112
            <version major="1" minor="66"/>
127
            <version major="1" minor="66"/>
(-)a/editor.lib2/nbproject/project.properties (-1 / +1 lines)
Lines 43-49 Link Here
43
is.autoload=true
43
is.autoload=true
44
javac.source=1.6
44
javac.source=1.6
45
javac.compilerargs=-Xlint:unchecked
45
javac.compilerargs=-Xlint:unchecked
46
spec.version.base=1.72.0
46
spec.version.base=1.73.0
47
47
48
javadoc.arch=${basedir}/arch.xml
48
javadoc.arch=${basedir}/arch.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypedTextInterceptorsManager.java (-4 / +4 lines)
Lines 71-80 Link Here
71
        return instance;
71
        return instance;
72
    }
72
    }
73
73
74
    public Transaction openTransaction(JTextComponent c, Position offset, String typedText) {
74
    public Transaction openTransaction(JTextComponent c, Position offset, String typedText, String replacedText) {
75
        synchronized (this) {
75
        synchronized (this) {
76
            if (transaction == null) {
76
            if (transaction == null) {
77
                transaction = new Transaction(c, offset, typedText);
77
                transaction = new Transaction(c, offset, typedText, replacedText);
78
                return transaction;
78
                return transaction;
79
            } else {
79
            } else {
80
                throw new IllegalStateException("Too many transactions; only one at a time is allowed!"); //NOI18N
80
                throw new IllegalStateException("Too many transactions; only one at a time is allowed!"); //NOI18N
Lines 161-168 Link Here
161
        private final Collection<? extends TypedTextInterceptor> interceptors;
161
        private final Collection<? extends TypedTextInterceptor> interceptors;
162
        private int phase = 0;
162
        private int phase = 0;
163
163
164
        private Transaction(JTextComponent c, Position offset, String typedText) {
164
        private Transaction(JTextComponent c, Position offset, String typedText, String replacedText) {
165
            this.context = TypingHooksSpiAccessor.get().createTtiContext(c, offset, typedText);
165
            this.context = TypingHooksSpiAccessor.get().createTtiContext(c, offset, typedText, replacedText);
166
            this.interceptors = getInterceptors(c.getDocument(), offset);
166
            this.interceptors = getInterceptors(c.getDocument(), offset);
167
        }
167
        }
168
    } // End of Transaction class
168
    } // End of Transaction class
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypingHooksSpiAccessor.java (-1 / +1 lines)
Lines 74-80 Link Here
74
    protected TypingHooksSpiAccessor() {
74
    protected TypingHooksSpiAccessor() {
75
    }
75
    }
76
76
77
    public abstract TypedTextInterceptor.MutableContext createTtiContext(JTextComponent c, Position offset, String typedText);
77
    public abstract TypedTextInterceptor.MutableContext createTtiContext(JTextComponent c, Position offset, String typedText, String replacedText);
78
    public abstract Object [] getTtiContextData(TypedTextInterceptor.MutableContext context);
78
    public abstract Object [] getTtiContextData(TypedTextInterceptor.MutableContext context);
79
    public abstract void resetTtiContextData(TypedTextInterceptor.MutableContext context);
79
    public abstract void resetTtiContextData(TypedTextInterceptor.MutableContext context);
80
    
80
    
(-)a/editor.lib2/src/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.java (-3 / +17 lines)
Lines 303-324 Link Here
303
            this.caretPosition = caretPosition;
303
            this.caretPosition = caretPosition;
304
        }
304
        }
305
305
306
        /**
307
         * Gets the replaced text. This is the text that was selected
308
         * by the user and it is replaced by inserted text.
309
         *
310
         * <p>The selected text is removed from document before <code>insert</code> method.
311
         *
312
         * @return The replaced text.
313
         */
314
        public String getReplacedText() {
315
            return replacedText;
316
        }
317
306
        // -------------------------------------------------------------------
318
        // -------------------------------------------------------------------
307
        // Private implementation
319
        // Private implementation
308
        // -------------------------------------------------------------------
320
        // -------------------------------------------------------------------
309
321
310
        private String insertionText = null;
322
        private String insertionText = null;
323
        private String replacedText = null;
311
        private int caretPosition = -1;
324
        private int caretPosition = -1;
312
        
325
        
313
        private MutableContext(JTextComponent c, Position offset, String typedText) {
326
        private MutableContext(JTextComponent c, Position offset, String typedText, String replacedText) {
314
            super(c, offset, typedText);
327
            super(c, offset, typedText);
328
            this.replacedText = replacedText;
315
        }
329
        }
316
330
317
        private static final class Accessor extends TypingHooksSpiAccessor {
331
        private static final class Accessor extends TypingHooksSpiAccessor {
318
332
319
            @Override
333
            @Override
320
            public MutableContext createTtiContext(JTextComponent c, Position offset, String typedText) {
334
            public MutableContext createTtiContext(JTextComponent c, Position offset, String typedText, String replacedText) {
321
                return new MutableContext(c, offset, typedText);
335
                return new MutableContext(c, offset, typedText, replacedText);
322
            }
336
            }
323
337
324
            @Override
338
            @Override

Return to bug 225293