zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.96k stars 1.17k forks source link

Fix indent selection #3102

Open vicencb opened 9 months ago

vicencb commented 9 months ago

When indenting a selection and the selection starts at the first column, it is expected that the updated selection start stays at the first column. This patch fixes this.

N.B.: this patch is displayed better ignoring white space.

dustdfg commented 9 months ago

Honestly, I don't understand what it change and what desired behavior even with a help of your comment (Is it even related?).

What should I do to see the change?

I tried to select with mouse/keyboard from two different directions and didn't notice change, maybe I overlooked it...

vicencb commented 9 months ago

These are the steps to reproduce the issue:

  1. Select some lines of text, the selection must start at the first column.
  2. Execute IndentSelection (bound to Tab by default).

The selection after doing the indent doesn't start at the first column. The expected behavior is that the selection still starts at the first column.

The selection direction has no effect on this issue.


That same issue from another point of view:

  1. Select whole lines of text.
  2. Execute IndentSelection.

The selection after doing the indent doesn't include whole lines. The first selected line has a gap at the beginning.

vicencb commented 9 months ago

This fix is unrelated to issue #3055.

dustdfg commented 9 months ago

OK. I see now. I tried to find the intersection with the issue you commented because I just expected it after the comment, sorry...


It is seems to me that this behavior is a matter of taste. Just want to understand where and why do you need this behavior? The only place when it seems profitable is when you decided to indent some part of text and then after indenting you suddenly change your mind and decide to delete the part you just indented but after pressing delete you end up with one "annoying" invisible tab...

vicencb commented 9 months ago

The use case that is mostly affected by this is a few lines of code need to be moved somewhere else, but the destination has a different indent level. I would like to select the code, indent, cut and paste it. With the current behavior this is not possible.

Regarding the matter of taste: the current code already has a special case for when the selection starts at the first column, it looks like it pretends to do the behavior i expect, but it fails to.