Faculty of Information Technology
Software Engineering Group

#130 closed todo (fixed)

A tab keypress should indent the whole block

Reported by: Patrik Svestka Owned by:
Priority: major Milestone: 8.0.0
Component: default Keywords:
Cc: Also affects CVS HEAD (eXept version): no


If you have a source code like:

contents := String new: 4 * 1024.
contents replaceAll: Character space with: $X.

top := StandardSystemView new.
top extent:300@200.

textView := EditTextView new.
textView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
top addSubView:textView.

textView contents: contents.

top open. 

and you want to indent part of it it behaves unexpectedly. Indents only the first line where the cursor is.

Steps to reproduce:

Select a block of code
Press TAB
It should indent all the code selected

Attachments (1)

Change History (7)

comment:1 Changed 21 months ago by Jan Vrany

Milestone: 8.0.0

Actually, indenting / undenting is no longer implemented as macro, it used to be like that by apparently in 2011 Claus changed that. Makes perfect sense.

Even indenting by seems to be implemented, but due to a little bug (?) it does not work.
See EditTextView >> #doKeyPress:x:y:m around line 363:

    ((key == #BackTab) or:[(key == #Tab)]) ifTrue:[
        self tabMeansNextField ifTrue:[^ super keyPress:key x:x y:y].

        self hasSelection ifTrue:[
            selectStyle == #line ifTrue:[
                ((key == #Tab) and:[shiftPressed not]) ifTrue:[
                    macroName := #IndentBy4.
                ] ifFalse:[
                    macroName := #UndentBy4.
                macroName notNil ifTrue:[
                    self executekeyboardMacroNamed:macroName.

If you replace selectStyle == #line ifTrue:[... with true ifTrue:[... then it start working.

We first need some tests, though.
Meanwhile, you may dirty-hack it this way and test, if it behaves as you'd expect (if not, collect examples and add them to this comment!)

comment:2 Changed 14 months ago by Jan Vrany

Status: newtesting

Please test attached patch aa6d81fa1892. It implements same behavior as Sublime Text.

Note that this is marked as 8.0.0 so it's kind of high-prio :-)

comment:3 Changed 14 months ago by Patrik Svestka

I have tested the patch but it appears it does not yet work correctly (works same for mouse and keyboard):

I would separate two issues:

1) When you select block of code at the direction down-to-up:

After selection when you press a tab it indents only first line of the block
and deselects the whole block. (in Sublime Text the block remains selected)

2) When you When you select block of code at the direction up-to-down:

The code is not indented at all. The tab is then created after the block and
the block is deselected afterwards too.

comment:4 Changed 14 months ago by Jan Vrany

Argh, I have not tested bottom-to-top direction of selection. Will do soonish.

As for 'top-to-bottom' direction, this is interesting. The patch contains
couple tests (see test_issue_130*). Do they pass? If so, could you be
more specific about the testcase that does not work?

comment:5 Changed 14 months ago by Jan Vrany

Please test improved patch libwidg_fix_1_of_1_rev_c6976b98f3c3_Issue__130__Fixed_support_for_indenting_by_tab.patch​​:

  • It ensures default values in UserPreferences and ensure tab width is set to 4 by default (when running tests).
  • It added test to make sure it works with tab width set to 8.
  • It added test to check bottom-to-top selection

All tests pass on my system.

Last edited 14 months ago by Jan Vrany (previous) (diff)

comment:6 Changed 14 months ago by Patrik Svestka

Resolution: fixed
Status: testingclosed

Now it is perfect.

My testing showed that it behaves exactly as it should. Both ways of selecting the block work correctly. All tests do pass correctly now. I'm closing the ticket.

Note: See TracTickets for help on using tickets.