Bug 324695 - New highlight yank feature doesn't play nice with block mode selection (CTRL-V)
Summary: New highlight yank feature doesn't play nice with block mode selection (CTRL-V)
Alias: None
Product: kate
Classification: Unclassified
Component: Vi Input Mode (show other bugs)
Version: Git
Platform: Compiled Sources Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Fabian
Depends on:
Reported: 2013-09-09 11:30 UTC by Fabian
Modified: 2013-12-01 18:44 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Note You need to log in before you can comment on or make changes to this bug.
Description Fabian 2013-09-09 11:30:00 UTC
When selecting a block of text and yanking it, not only the block will be highlighted, but also everything after in between the beginning of the selection and the end of it.
ASCII art  example:
- = text; o = marked with CTRL-V; * = highlighted
will lead to
when yanked.

Reproducible: Always

Steps to Reproduce:
1. Open a file with some text.
2. Mark a block of text in block mode
3. Yank it via e.g. y
Actual Results:  
see above

Expected Results:  
only the selected code should be  highlighted

The problem is because when creating the yankRage with
Range yankRange(range.startLine, range.startColumn, range.endLine, range.endColumn);
it doesn't know anymore about being delimited. One could maybe create one Range per line to fix this, but that sounds horribly inefficient. Is there maybe smarter Range class?
Comment 1 Dominik Haumann 2013-09-09 12:18:30 UTC
This looks like
- void KTextEditor::MovingRange::setBlockMode(bool blockMode)
- bool KTextEditor::MovingRange::blockMode() const
are missing in the MovingRange class.

A possible workaround: create N MovingRanges, for each line one.

Fabian, do you plan to send a patch?
Comment 2 Dominik Haumann 2013-09-09 12:32:45 UTC
Git commit fface1586b1e32067292862e63b000cf9f0d436a by Dominik Haumann.
Committed on 09/09/2013 at 12:32.
Pushed by dhaumann into branch 'master'.

todo KDE 5 note

in KDE5, maybe add
- void MoivingRange::setBlockMode(bool enableBlockMode);
- bool MoivingRange::blockMode() const;
This way, arbitrary highlighting would work for colums as well. In fact, if implemented
correctly in the Kate Renderer, drawing block selection mode could use this, too.
The vi in put mode yank highlighting could use it, too: https://bugs.kde.org/show_bug.cgi?id=324695

A correct implementation needs to take care of MovingRangeFeedback, especially
of mouseEnteredRange(), mouseExitedRange(), caretEnteredRange() and caretEnteredRange()

M  +10   -0    ktexteditor/movingrange.h

Comment 3 Fabian 2013-09-09 12:36:01 UTC
Yes, I plan on creating a workaround for this. I'll create a review request once it's done.
Comment 4 Simon St James 2013-09-09 12:36:21 UTC
Sounds like the workaround of using N highlighted ranges would be the best short-term solution; I'll see if I can get this done for KDE 4.12, and leave a note to re-visit in KDE5.

Thanks for the report - I'm embarrassed I didn't think to check this!
Comment 5 Dominik Haumann 2013-09-09 12:42:41 UTC
N highlightings will work. But as soon as you rely on mouse or caret interaction, this will break again, since you get notified for each moving range. This is not a problem currently, though, since the yank highlighting does not use the moving range feedback anyway.

Best would be an implementation in kate part that supports block mode, see comment #2. :-) Since the vi input mode is Kate Part internal, it even could use this implementation directly through Kate::TextRange (which inherits KTextEditor::MovingRange).

Maybe you can give this route a try?
The vi code then would need to cast the MovingRange* to Kate::TextRange* and then access the added setBlockMode() function.
Comment 6 Michal Humpula 2013-12-01 18:44:54 UTC
Git commit c4589f9346633793af9599656a8c06c283307786 by Michal Humpula.
Committed on 30/11/2013 at 09:53.
Pushed by michalhumpula into branch 'master'.

vi-mode: fix yanking in visual block mode

REVIEW: 114220

M  +31   -20   part/vimode/katevinormalmode.cpp
M  +4    -3    part/vimode/katevinormalmode.h
M  +12   -0    tests/vimode_test.cpp