Alexey-T / CudaText

Cross-platform text editor, written in Free Pascal
Mozilla Public License 2.0
2.54k stars 174 forks source link

Must exclude last line from fold-block if it ends with more 'tokens' #5747

Closed pintassilgo closed 1 month ago

pintassilgo commented 1 month ago
if (true) {
  a = 1;
} else {
  a = 0;
}

Collapse first line.

Expected (it works in any other editor):

if (true) {
} else {
  a = 0;
}

Cuda (the else line is unexpectedly collapsed): image

Alexey-T commented 1 month ago

Yes, I agree it must be improved.

pintassilgo commented 1 month ago

Not that it matters, but this is a bug, not enhancement... Code folding is expected to collapse the clicked block, not to include a line that initiates another block. As it is with any other app supporting code folding.

Alexey-T commented 1 month ago

Suggestion is the improvement. Logic of it is - if after block ending we have more lexer tokens on the same line, lets decrement ending's y coord.

Alexey-T commented 1 month ago

I improved it. before it was fixed for JSON lexer only. via property in .cuda-lexmap file. now we don't need that property. it's auto detected. now it works for ALL lexers (not only {} based).

Alexey-T commented 1 month ago

beta cudatext.zip

pintassilgo commented 1 month ago

Thanks, fixed.

A couple of minor visual details:

  1. Look: image The visual mark for folded block is { ... }, but in this case it looks weird because closing brackets is in the line below, while opening brackets is correctly hidden by the folding. Can you understand? The closing brackets in second line looks wrong because there's already a closing brackets in first line.

So maybe you should think of a different default visual indicator for collapsed block. Just for reference:


  1. Think about an if with many conditionals. It's a good practice to list them in multiple lines, turning the group of conditions as an own foldable block. So, for instance:
if (name === 'Alex' ||
    name === 'AlexT' ||
    name === 'Alex T') {
  a = 1;
  b = 2;
} else {
  a = 0;
}

If you click to fold the first block (if conditionals), then you can't fold the child block inside the if. Also, in this case Cuda doesn't display the opening brackets following the if (), which is a bit strange.

image

Alexey-T commented 1 month ago
  1. Fixed
  2. I suggest to disable folding for round brackets. Ok?
pintassilgo commented 1 month ago
  1. Thanks.

  2. I disagree, I like being able to fold them, for me it's better keeping current than doing this change you suggested. If doable, I suggest a little improvement of how Sublime handles this. When you fold the if (), the opening brackets is exposed at the first line: image In my opinion, this is the best visual. easy to understand, easy to see, beautiful... But it's not perfect because then you can't fold the { } block. Actually you can, but only if you do it before you fold the ( ) block.

Sublime way is already an improvement to current Cuda, but to fix the issue of not being able to fold { } when ( ) is fold, maybe user could be able to click the code folding column to fold it. By the way, this would be a good feature to have. Current, in order to fold a block with mouse you need to find and click the line that opens the block. It would be good if user can fold the block by clicking the folding column in any line (could be set by option). So, if user clicks inside the red circle in image below, it would fold the block.

image

Alexey-T commented 1 month ago

will think about your last suggestion. now i see it is not good when 2+ ranges overlap and we click on overlapped line. also it don't work in Sublime. normal way to fold - is to click [+].

new beta. 1 and 2 fixed? i excluded the ')' and '}' char from fold-tooltip ( ... ) / { ... }. cudatext.zip

pintassilgo commented 1 month ago

Thanks, it's better now.

Regarding the click-on-fold-column-to-fold, I use that feature in Reddit and find it useful.

https://github.com/user-attachments/assets/d266f5aa-921f-4b4d-8d8e-bcf61e4e329d

Sometimes current code block is very long and you want to collapse it, you need to scroll till you find the line that opens the brackets. There's probably a hotkey to fold current block, but it would be good to have a good way to do it with the mouse too.

Alexey-T commented 1 month ago

reddit ui is diffetent, each range has new column. we must not adapt to reddit.

seems i made all fixes. lets find more issues if any.