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

feat: add '%' key for vi (goto_matching_brace) #544

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bundles/vi/base_map.moon
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ map = {

'}': (editor) -> apply editor, (editor) ->
editor.cursor\para_down!

'%': (editor) -> apply editor, (editor) ->
editor.cursor\goto_matching_brace!
}

on_unhandled: (event, source, translations) ->
Expand Down
4 changes: 1 addition & 3 deletions lib/howl/commands/edit_commands.moon
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ command.register
name: 'cursor-goto-brace'
description: 'Go to the brace matching the current brace, if any'
handler: ->
cursor = app.editor.cursor
pos = app.editor\get_matching_brace cursor.pos
cursor\move_to(:pos) if pos
app.editor.cursor\goto_matching_brace!

command.register
name: 'editor-replace-exec'
Expand Down
4 changes: 4 additions & 0 deletions lib/howl/ui/cursor.moon
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ class Cursor extends PropertyObject
else
@cursor\end_of_file :extend

goto_matching_brace: () =>
pos = @container\get_matching_brace @pos
@move_to(:pos) if pos

-- private

@property _line: get: =>
Expand Down
4 changes: 4 additions & 0 deletions site/source/doc/api/ui/cursor.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,9 @@ selection, or extends the selection if already present.
Moves the cursor one paragraph up. If `extend` is true, creates a new selection,
or extends the selection if already present.

### goto_matching_brace ()

Moves the cursor to brace matching the current brace if any.

[Editor]: editor.html
[Selection]: selection.html
8 changes: 8 additions & 0 deletions spec/ui/cursor_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,11 @@ And hƏre's line twʘ
assert.equal 'L', sel.text
cursor.line = 2
assert.equals 'Liñe 1 ʘf tƏxt\nA', sel.text

describe 'goto_matching_brace', ->
it 'moves to the matching brace', ->
editor.buffer.mode.auto_pairs = {'[': ']'}
editor.buffer.text = '[foo]'
cursor.pos = 1
cursor\goto_matching_brace!
assert.equal 5, cursor.pos