[Bluej-discuss] Moe Editor: Indentation & Block Actions

Michael Kölling M.Kolling at kent.ac.uk
Sun Dec 30 16:17:52 GMT 2007


On 30 Dec 2007, at 14:54, <mpp8 at kent.ac.uk> wrote:

> Firstly, the doIndent method in MoeActions seems to be created to be  
> used both to find the indentation required when a new line is  
> created, and to change/correct the indentation of the current line.
>
> It is called in three places: NewLineAction, the closingBrace  
> method, and IndentAction. The latter suggests that it is called when  
> the 'Indent More' option on the Edit menu is selected, but that is  
> IndentLineAction. So is IndentAction use at all? If not, then I  
> can't understand why doIndent checks the location of the caret in  
> the current line - as it will always be at the beginning (either  
> there's a new line, or closingBrace has called  
> "textPane.setCaretPosition(lineStart);" beforehand).

IndentAction, if I remember correctly, is not used for the "Indent  
More" block-action, but for "indent", which is bound to the TAB key.

"indent" does two things: If the current caret position is before the  
indent of the line above, it indents to the same level as the line  
above. If the indent is already at that level or beyond, it indents to  
the next TAB stop.


> Secondly, when performing a block action, the code specifically  
> selects the entirety of all the lines included in the action. The  
> default action would be to keep the selection as it is before, which  
> would seem to me to be a more natural way of working - I find it  
> annoying when I change the indentation, then go to type something in  
> where the caret was before, only to find that that replaces the  
> whole line, as it has been entirely selected for no apparent reason.  
> Is there a reason for this?

No, not really. Only that block actions, such as "Indent More" apply  
to complete lines of every line of which at least a part is included  
in the current selection. But I think that could be done without  
actually selecting the whole line.


> (This second point is the feature that I was looking in the code to  
> investigate - I had assumed that it selected all the lines involved  
> because it would be too difficult to keep track of where the  
> selection had been before, but I've now found out that it has been  
> specifically programmed to act like that.) I notice that other IDEs/ 
> editors also work in a similar ways (I last noticed it in either  
> Eclipse or TextWrangler; I can't remember) - is BlueJ made to fit  
> with a convention, or is there some other reason?

It was not done to fit the convention. It was just that I thought that  
the function applies to the complete line, and to make that clear, the  
complete line gets selected. (Block function always apply to multiples  
of lines.) But after what you said, I agree that it might be better to  
leave the selection as it was.

Michael



More information about the bluej-discuss mailing list