Match pairs setting

This will match {, (, and [. But not angle brackets!
This commit is contained in:
Felix Angell 2016-11-27 16:00:32 +00:00
parent 556e027011
commit 02da76691e
2 changed files with 19 additions and 0 deletions

View File

@ -13,6 +13,7 @@ type EditorConfig struct {
Flash_Cursor bool `toml:"flash_cursor"`
Cursor_Flash_Rate uint32 `toml:"cursor_flash_rate"`
Cursor_Reset_Delay uint32 `toml:"cursor_reset_delay"`
Match_Braces bool `toml:"match_braces"`
}
func NewDefaultConfig() *TomlConfig {

View File

@ -71,8 +71,26 @@ func (b *Buffer) processTextInput(t *sdl.TextInputEvent) {
b.contents[b.curs.y] = b.contents[b.curs.y].Insert(b.curs.x, string(rawVal))
b.curs.move(1, 0)
matchingPair := int(rawVal)
// the offset in the ASCII Table is +2 for { and for [
// but its +1 for parenthesis (
offset := 2
switch rawVal {
case '(':
offset = 1
fallthrough
case '{':
fallthrough
case '[':
matchingPair += offset
b.contents[b.curs.y] = b.contents[b.curs.y].Insert(b.curs.x, string(rune(matchingPair)))
}
}
// TODO(Felix): refactor me!)
func (b *Buffer) processActionKey(t *sdl.KeyDownEvent) {
switch t.Keysym.Scancode {
case sdl.SCANCODE_RETURN: