Fixes #2260. Refactor `cb_func_select_action()` a bit. You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/2264
-- Commit Summary --
* Add 'Select to enclosing brackets' keybinding
-- File Changes --
M doc/geany.txt (9) M src/keybindings.c (78) M src/keybindings.h (5)
-- Patch Links --
https://github.com/geany/geany/pull/2264.patch https://github.com/geany/geany/pull/2264.diff
Looks ok by inspection, not tested.
A couple of suggestions for improvement:
1. include `<>` if the `brace_match_ltgt` is set
2. the search for `]})` will find those characters in comments and strings so the selection is probably not what the user intended. Not sure how to cure that though 3. will mitigate it somewhat.
3. check if the cursor is in a position where a pair of brackets are already highlighted and use that pair instead of searching
If you don't want to do these in this PR thats fine, please copy them into a future improvements issue.
@ntrel pushed 2 commits.
b64c0f453d22374900ded4547b83f8ecd798ba18 Support <> if pref set d4ce14124643bd565419b18cf3a8d609ac6486e8 If no matching bracket, continue searching for another outer bracket
include <> if the brace_match_ltgt is set
Now done.
the search for ]}) will find those characters in comments and strings so the selection is probably not what the user intended.
In that case no selection would be made as scintilla wouldn't find a match (of the same style), but this wouldn't be what the user intended. If there is no match, I've now made it continue searching for an outer bracket pair.
check if the cursor is in a position where a pair of brackets are already highlighted and use that pair instead of searching
With today's changes at least, I don't see how that would be useful. Bracket highlighting highlights an opening bracket to the right of the cursor, whereas for this feature we want an outside bracket to be matched (see last commit message for clearer explanation).
I've now made it continue searching for an outer bracket pair.
Good idea.
Bracket highlighting can highlight an opening bracket just to the right of the cursor
I just felt it would be natural that if when my cursor was beside a `{` or `(` that was highlighted that the binding selected that, basically "goto matching brace" with selection. Thats also what I understand #2260 is asking for.
I just felt it would be natural that if when my cursor was beside a { or ( that was highlighted that the binding selected that,
I don't mind really if people prefer that, but this command is called select *enclosing* brackets, and the cursor is actually outside the brackets in this case.
Thats also what I understand #2260 is asking for.
I had a look but I'm not sure that this nuance is mentioned in that issue.
but this command is called select enclosing brackets
But the first thing it says is `fixes #2260` so I expected it to do that. Thats not to say that it isn't a useful command in and of itself, but it isn't the answer to #2260.
Where #2260 says:
CTRL-b is a great shortcut, but i cannot select text to matching brace
That is the existing command `goto matching brace`, that is bound to `ctrl_b` by default. Therefore the OP is asking for a version of that to select between the braces. Note that `goto matching brace` does nothing unless a bracket is highlighted, it isn't `goto enclosing brackets`.
So whilst your `select enclosing brackets` command is also a useful one because it works when the cursor is not beside the bracket, its not what was actually asked for in #2260.
As an example, if the cursor is beside a `{` of a C block, which is on a line by itself in the Geany code style, the brace is highlighted irrespective of which side the cursor is on and it seems unexpected to me as a user that the keybinding will select some outer block in the case that the cursor is before the `{` when its highlighted while the goto (ctrl-b) will goto the matching inner brace.
In the best case we should have both functions keybindable as required since they are both useful in different cases.
github-comments@lists.geany.org