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 30147
Collapse All | Expand All

(-)editor/libsrc/org/netbeans/editor/ActionFactory.java (+111 lines)
Lines 866-871 Link Here
866
        }
866
        }
867
    }
867
    }
868
868
869
870
    /**
871
     * Reindent the current line.
872
     *
873
     * @todo Fix it such that it doesn't modify the selection
874
     */
875
    public static class ReindentLineAction extends BaseAction {
876
877
        static final long serialVersionUID =1L;
878
879
        public ReindentLineAction() {
880
            // TODO: figure out what these flags are all about
881
            super(BaseKit.reindentLineAction,
882
                  ABBREV_RESET | MAGIC_POSITION_RESET | UNDO_MERGE_RESET);
883
            //putValue ("helpID", ReindentLineAction.class.getName ());
884
        }
885
886
        public void actionPerformed(ActionEvent evt, JTextComponent target) {
887
            if (target != null) {
888
                if (!target.isEditable() || !target.isEnabled()) {
889
                    target.getToolkit().beep();
890
                    return;
891
                }
892
893
                // Todo: operate iterately over all the lines in the
894
                // selection
895
896
                // Note: there is a Utilities.reformat(doc, pos)
897
                // method - is that all I need?
898
899
900
                // This code is copied from FormatAction in this
901
                // same file - I just tweaked the code which used
902
                // to look at the selection to compute the line bounds
903
                // instead. Finally, I adjust the caret position to
904
                // the first non-whitespace character instead of
905
                // column 0.
906
                
907
                Caret caret = target.getCaret();
908
                BaseDocument doc = (BaseDocument)target.getDocument();
909
                GuardedDocument gdoc = (doc instanceof GuardedDocument)
910
                                       ? (GuardedDocument)doc : null;
911
912
                doc.atomicLock();
913
                try {
914
915
                    int caretLine = Utilities.getLineOffset(doc, caret.getDot());
916
                    int startPos;
917
                    Position endPosition;
918
919
920
                    /*
921
                    if (caret.isSelectionVisible()) {
922
                        startPos = target.getSelectionStart();
923
                        endPosition = doc.createPosition(target.getSelectionEnd());
924
                    } else {
925
                        startPos = 0;
926
                        endPosition = doc.createPosition(doc.getLength());
927
                    }
928
                    */
929
                    startPos = Utilities.getRowStart(doc, caret.getDot());
930
                    endPosition =
931
                      doc.createPosition(Utilities.getRowEnd(doc, caret.getDot()));
932
933
934
                    
935
                    int pos = startPos;
936
                    if (gdoc != null) {
937
                        pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos);
938
                    }
939
940
                    while (pos < endPosition.getOffset()) {
941
                        int stopPos = endPosition.getOffset();
942
                        if (gdoc != null) { // adjust to start of the next guarded block
943
                            stopPos = gdoc.getGuardedBlockChain().adjustToNextBlockStart(pos);
944
                            if (stopPos == -1) {
945
                                stopPos = endPosition.getOffset();
946
                            }
947
                        }
948
949
                        int reformattedLen = doc.getFormatter().reformat(doc, pos, stopPos);
950
                        pos = pos + reformattedLen;
951
952
                        if (gdoc != null) { // adjust to end of current block
953
                            pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos);
954
                        }
955
                    }
956
957
                    // Restore the line
958
                    pos = Utilities.getRowStartFromLineOffset(doc, caretLine);
959
                    if (pos >= 0) {
960
                        
961
                        pos = Utilities.getRowFirstNonWhite(doc, pos);
962
                        
963
                        caret.setDot(pos);
964
                    }
965
                } catch (GuardedException e) {
966
                    target.getToolkit().beep();
967
                } catch (BadLocationException e) {
968
                    if (System.getProperty("netbeans.debug.exceptions") != null) { // NOI18N
969
                        e.printStackTrace();
970
                    }
971
                } finally {
972
                    doc.atomicUnlock();
973
                }
974
                
975
            }
976
        }
977
    }
978
979
    
869
    public static class AdjustWindowAction extends BaseAction {
980
    public static class AdjustWindowAction extends BaseAction {
870
981
871
        int percentFromWindowTop;
982
        int percentFromWindowTop;
(-)editor/libsrc/org/netbeans/editor/BaseKit.java (+4 lines)
Lines 144-149 Link Here
144
    /** Shift line right action */
144
    /** Shift line right action */
145
    public static final String shiftLineRightAction = "shift-line-right"; // NOI18N
145
    public static final String shiftLineRightAction = "shift-line-right"; // NOI18N
146
146
147
    /** Reindent Line action */
148
    public static final String reindentLineAction = "reindent-line"; // NOI18N
149
147
    /** Shift line left action */
150
    /** Shift line left action */
148
    public static final String shiftLineLeftAction = "shift-line-left"; // NOI18N
151
    public static final String shiftLineLeftAction = "shift-line-left"; // NOI18N
149
152
Lines 639-644 Link Here
639
                   new ActionFactory.RedoAction(),
642
                   new ActionFactory.RedoAction(),
640
                   new ActionFactory.WordMatchAction(wordMatchNextAction, true),
643
                   new ActionFactory.WordMatchAction(wordMatchNextAction, true),
641
                   new ActionFactory.WordMatchAction(wordMatchPrevAction, false),
644
                   new ActionFactory.WordMatchAction(wordMatchPrevAction, false),
645
                   new ActionFactory.ReindentLineAction(),
642
                   new ActionFactory.ShiftLineAction(shiftLineLeftAction, false),
646
                   new ActionFactory.ShiftLineAction(shiftLineLeftAction, false),
643
                   new ActionFactory.ShiftLineAction(shiftLineRightAction, true),
647
                   new ActionFactory.ShiftLineAction(shiftLineRightAction, true),
644
                   new ActionFactory.AdjustWindowAction(adjustWindowTopAction, 0),
648
                   new ActionFactory.AdjustWindowAction(adjustWindowTopAction, 0),
(-)editor/libsrc/org/netbeans/editor/Bundle.properties (+1 lines)
Lines 96-101 Link Here
96
paste-from-clipboard=Paste
96
paste-from-clipboard=Paste
97
popup-remove-selection=Delete
97
popup-remove-selection=Delete
98
redo=Redo
98
redo=Redo
99
reindent-line=Re-indent Line
99
remove-line=Delete Line
100
remove-line=Delete Line
100
remove-line-begin=Delete Preceding Characters in Line
101
remove-line-begin=Delete Preceding Characters in Line
101
remove-selection=Delete Selection
102
remove-selection=Delete Selection
(-)ide/defaults/src/org/netbeans/modules/defaults/Emacs-keybindings.xml (-1 / +2 lines)
Lines 49-55 Link Here
49
    <bind actionName="goto-declaration" key="A-PERIOD"/>
49
    <bind actionName="goto-declaration" key="A-PERIOD"/>
50
    <bind actionName="goto-declaration" key="CA-G"/>
50
    <bind actionName="goto-declaration" key="CA-G"/>
51
    <bind actionName="insert-break" key="ENTER"/>
51
    <bind actionName="insert-break" key="ENTER"/>
52
    <bind actionName="insert-tab" key="TAB"/>
52
    <bind actionName="insert-tab" key="C-Q$TAB"/>
53
    <bind actionName="reindent-line" key="TAB"/>
53
    <bind actionName="page-down" key="C-V"/>
54
    <bind actionName="page-down" key="C-V"/>
54
    <bind actionName="page-down" key="PAGE_DOWN"/>
55
    <bind actionName="page-down" key="PAGE_DOWN"/>
55
    <bind actionName="page-up" key="A-V"/>
56
    <bind actionName="page-up" key="A-V"/>

Return to bug 30147