From: SourceForge.net <no...@so...> - 2013-04-03 07:01:43
|
Patches item #3607873, was opened at 2013-03-13 03:36 Message generated for change (Comment added) made by marchaefner You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=300588&aid=3607873&group_id=588 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: texteditor Group: None >Status: Open Resolution: None Priority: 5 Private: No Submitted By: Marc Häfner (marchaefner) Assigned to: Shlomy Reinstein (shlomy) Summary: Fix cursor misplacement with auto-indent. Initial Comment: This fixes a subtle bug introduced in rev. 14899, where `insertEnterAndIndent` sometimes places the cursor at the wrong column. Example ------- (python, underscores for spaces, vbar for cursor) Given the following situation, with auto-indent and an indentation level of 2 spaces. (Note that the amount of spaces after the cursor matches the indentation level for the next line): if_False:|__pass Executing `insertEnterAndIndent` (default action for ENTER key) results in: if_False: |__pass Expected outcome would be (and is for different amount of spaces): if_False: __|pass Cause ----- This behaviour is caused by an early return in `JEditBuffer.indentLine` if `idealIndent == currentIndent`. While this is necessary for `insertTabAndIndent`, it prevents re-indentation which would produce a correct cursor position. Fix --- `indentLine` already has a parameter `canDecreaseIndent` which is only used by `insertTabAndIndent`. This fix simply reuses that flag and prevent re-indentation to the same level only for the Tab key. Side Effects ------------ The fix reverts to the behaviour before rev. 14899 (2009-04-09), except for the Tab key. I.e. `indentLine` no longer always returns `false` if a line is already correctly indented. Within the jEdit project only `insertTabAndIndent` uses the return value. ---------------------------------------------------------------------- >Comment By: Marc Häfner (marchaefner) Date: 2013-04-03 00:01 Message: The new fix is in `insertEnterAndIndent`: If no indentation took place (i.e. `JEditBuffer.indentLine` returned false) invoke `smartHome` to explicitly move the cursor to the correct position. I also took the liberty to add a comment to the method. ---------------------------------------------------------------------- Comment By: Shlomy Reinstein (shlomy) Date: 2013-03-31 03:03 Message: This patch has a side-effect of not preserving the leading whitespace in case the ideal indentation level is the same as the current (existing) indentation level. I recall that there was an explicit request (don't remember why) to preserve the existing whitespace if the level of indentation is okay. Personally, I'd prefer jEdit to replace the leading whitespace with the default (e.g. if my leading whitespace is mixed spaces and tabs, I'd prefer auto-indent to replace the spaces with tabs) - which is what this patch does. I don't remember why we didn't do it this way, but there was a good reason for the current behavior (without the patch). It would be okay to move the cursor to the right place, but without having any side effects like the above. ---------------------------------------------------------------------- Comment By: Alan Ezust (ezust) Date: 2013-03-16 16:59 Message: I am testing it now and trying to observe some change in behavior and am unable to see any yet. Shlomy is on vacation but I thought he should take a look at it too when he gets back since 14899 is his revision. it's just a 2-liner patch and looks fine to me so far though. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=300588&aid=3607873&group_id=588 |