mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 15:55:25 +03:00
Matching braces setting plus a shoddy caret width setting
This commit is contained in:
parent
cca2b1f017
commit
af967a37fb
@ -1,5 +1,7 @@
|
||||
package cfg
|
||||
|
||||
import "strconv"
|
||||
|
||||
type TomlConfig struct {
|
||||
Editor EditorConfig
|
||||
Cursor CursorConfig
|
||||
@ -12,6 +14,7 @@ tab_size = 2
|
||||
hungry_backspace = true
|
||||
tabs_are_spaces = true
|
||||
match_braces = false
|
||||
maintain_indentation = true
|
||||
|
||||
[render]
|
||||
aliased = true
|
||||
@ -34,6 +37,18 @@ type CursorConfig struct {
|
||||
Reset_Delay uint32
|
||||
Draw bool
|
||||
Flash bool
|
||||
Block_Width string
|
||||
}
|
||||
|
||||
func (c CursorConfig) GetCaretWidth() int {
|
||||
if c.Block_Width == "block" {
|
||||
return -1
|
||||
}
|
||||
value, err := strconv.ParseInt(c.Block_Width, 10, 32)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return int(value)
|
||||
}
|
||||
|
||||
type RenderConfig struct {
|
||||
@ -53,10 +68,11 @@ type ThemeConfig struct {
|
||||
}
|
||||
|
||||
type EditorConfig struct {
|
||||
Tab_Size int32
|
||||
Hungry_Backspace bool
|
||||
Tabs_Are_Spaces bool
|
||||
Match_Braces bool
|
||||
Tab_Size int32
|
||||
Hungry_Backspace bool
|
||||
Tabs_Are_Spaces bool
|
||||
Match_Braces bool
|
||||
Maintain_Indentation bool
|
||||
}
|
||||
|
||||
func NewDefaultConfig() *TomlConfig {
|
||||
|
@ -72,6 +72,12 @@ func (b *Buffer) processTextInput(t *sdl.TextInputEvent) {
|
||||
b.contents[b.curs.y] = b.contents[b.curs.y].Insert(b.curs.x, string(r))
|
||||
b.curs.move(1, 0)
|
||||
|
||||
// we don't need to match braces
|
||||
// let's not continue any further
|
||||
if !b.cfg.Editor.Match_Braces {
|
||||
return
|
||||
}
|
||||
|
||||
matchingPair := int(r)
|
||||
|
||||
// the offset in the ASCII Table is +2 for { and for [
|
||||
@ -114,6 +120,7 @@ func (b *Buffer) processActionKey(t *sdl.KeyDownEvent) {
|
||||
b.curs.move(0, 1)
|
||||
return
|
||||
} else {
|
||||
// we're at the end of a line
|
||||
newRope = new(rope.Rope)
|
||||
}
|
||||
|
||||
@ -281,11 +288,16 @@ func (b *Buffer) OnRender(ctx *sdl.Renderer) {
|
||||
|
||||
// render the ol' cursor
|
||||
if should_draw && b.cfg.Cursor.Draw {
|
||||
cursorWidth := int32(b.cfg.Cursor.GetCaretWidth())
|
||||
if cursorWidth == -1 {
|
||||
cursorWidth = last_w
|
||||
}
|
||||
|
||||
gfx.SetDrawColorHexString(ctx, b.cfg.Theme.Cursor)
|
||||
ctx.FillRect(&sdl.Rect{
|
||||
b.x + (int32(b.curs.rx)+1)*last_w,
|
||||
b.y + int32(b.curs.ry)*last_h,
|
||||
last_w,
|
||||
cursorWidth,
|
||||
last_h,
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user