Bug 368580 - Auto Brackets forgets about multiple levels of brackets when overtyping closing bracket
Summary: Auto Brackets forgets about multiple levels of brackets when overtyping closi...
Status: RESOLVED FIXED
Alias: None
Product: frameworks-ktexteditor
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-11 07:56 UTC by Matt Whitlock
Modified: 2019-06-02 07:00 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.58


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Whitlock 2016-09-11 07:56:57 UTC
This is with ktexteditor 5.26.0.

The Auto Brackets feature appears to remember only one level of bracketing for purposes of auto-overtyping closing brackets. Only the innermost closing bracket is automatically overwritten.

Reproducible: Always

Steps to Reproduce:
In a new document in KWrite (or Kate, KDevelop, etc.) with Auto Brackets enabled, type more than one opening bracket (of any kind). Then type the corresponding closing brackets (in reverse order).

Actual Results:  
Only the first closing bracket gets automatically overwritten. The remaining closing brackets are inserted instead, leading to excessive closing brackets.

Expected Results:  
All closing brackets should be automatically overwritten if they were automatically inserted and have not yet been automatically overwritten.

This worked in KDE 4, presumably because *all* closing brackets were *always* automatically overtyped by matching characters. This was an okay solution, though it confounded the later insertion of additional closing brackets into a run of closing brackets.

A better solution would be to remember which closing brackets on the current editing line were automatically inserted and automatically overtype them if and only if the character being typed matches the existing closing bracket and the existing closing bracket has not already been automatically overtyped. (The set of remembered auto-inserted closing brackets can be forgotten when the cursor moves to another line.)

Some examples (pipe character indicates cursor position)…

Type these five characters: ((a))
Expected result: ((a))|
Actual result: ((a))|)

Type these seven characters: ({[a]})
Expected result: ({[a]})|
Actual result: ({[a]})|})
Comment 1 Lothar 2019-04-12 22:33:55 UTC
Git commit 8f0813f6c7ed6da15cdc10030b42c34f7ce98fb0 by loh tar.
Committed on 12/04/2019 at 22:29.
Pushed by lohtar into branch 'master'.

DocumentPrivate: Make bracket handling smart

This patch checks if the entered closing bracket is already balanced and
skip the input in this case. Targets the "nested autbracket" problem
without to base on this enabled config setting.
FIXED-IN: 5.58

Differential Revision: https://phabricator.kde.org/D19608

M  +12   -0    src/document/katedocument.cpp

https://commits.kde.org/ktexteditor/8f0813f6c7ed6da15cdc10030b42c34f7ce98fb0
Comment 2 Daniel Scharrer 2019-05-30 10:03:27 UTC
The new behavior should only be enabled with auto bracketing on - it's super annoying to start out with f(|), type arg() and then end up with f(arg()| instead of f(arg()|).
Comment 3 Dominik Haumann 2019-06-02 07:00:05 UTC
@Daniel: this was accidentally always on, and it's fixed for 5.59, see: https://bugs.kde.org/show_bug.cgi?id=407852