Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indent of selected range and copy doesn't include indent of first line #1693

Open
drankinatty opened this issue Nov 21, 2017 · 6 comments
Open

Comments

@drankinatty
Copy link

drankinatty commented Nov 21, 2017

This is more a feature request than a bug, so no immediate attention is required. The problem is selecting lines to indent and copy for pasting. If you fully-select lines 1-10, and then choose indent, the existing selection does not include the new indent of the 1st line (meaning after indent, the selection bounds are never updated on line 1 to include the new spaces inserted before line one for the indent -- at least it behaves that way on windows) I have run into similar issues before and would propose a fix something like the following within the indent loop. Just a simple check if we are indenting the first line, and if so, move the start mark back to the beginning of the first line:

        /* reset start iter and start mark to beginning of line
         * so that selection continues to encompass entire first line.
         */
        if (start_line != end_line && i == start_line &&
            !gtk_text_iter_starts_line (&iter)) {
            gtk_text_iter_set_line_offset (&iter, 0);
            gtk_text_buffer_move_mark (buf, start_mark, &iter);
        }

then before return from the indent function just set the select range to encompass all indented lines:

    /* adjust selection to cover entire first line */
    gtk_text_buffer_select_range (buf, end, start);

I haven't checked whether geany is using indent features from scintilla or just a loop and custom indent function, so this may have to be wrapped around scintilla's indention.

A noted, this is just a feature request for tweaking the select range following indent so the whole newly indented range remains selected. Keep up the great work. Geany is by far the hands down favorite non-desktop integrated editor.

@elextr
Copy link
Member

elextr commented Nov 21, 2017

The trick is to select the lines from the line number margin so whole lines are selected, not just a piece of text,, then you can indent/undent to your hearts content and the new indents are part of the selection.

@drankinatty
Copy link
Author

I like that solution, but what about the times when there is partial first like selected (or the whole like, including the first character, just not from the numbers margin?) I usually have numbers off anyway, but if it works similar to the what word processors do and doesn't require numbers being shown, that in its own right is a cool feature.

@elextr
Copy link
Member

elextr commented Nov 21, 2017

Using the number margin is just an easy way to select whole lines, so long as the selection is whole lines the new indent is part of the selection, but if only part of the line is selected Geany respects the users selection and does not modify its end points.

What you havn't described in your OP is in what use-case its actually a problem?

@drankinatty
Copy link
Author

I apologize. The use case is this. StackOverflow (and any of the coding sites that use markdown) generally use a 4-space indention to format text as code. Selecting code to paste into an answer, and then indent to create the 4-space indention results in just this case -- all lines indented and selected except the first 4-spaces of the first line. That was the specific reason for implementing the selection extension to cover all code indented. It was actually a behavior of kate/kwrite that I duplicated in an editor. I thought I would pass it along to Geany as a feature request it is quite useful to not have to block indent and re-select the lines again to cover the indented range of lines. Keep up the great work. You have a great editor.

@elextr
Copy link
Member

elextr commented Nov 22, 2017

Ahh, have found it only happens when the first line has no indent, then even if you select whole lines the new indent on the first line is not selected. But if the first line of the selection has an existing indent (even one space) the new indent is included in the selection.

Its caused by the >= in this line maybe it should just be > but it needs to be determined if its deliberate or accidental before its declared a bug. Anybody know the back storey?

@val461
Copy link

val461 commented Jun 18, 2018

when the first line has no indent, then even if you select whole lines the new indent on the first line is not selected.

I do not have that issue with Geany 1.33. Do you still have that issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants